Skip to content

Adding a JSDoc @typedef declaration breaks emitting static getter to ".d.ts" files. #37289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kbkk opened this issue Mar 9, 2020 · 2 comments · Fixed by #37780
Closed

Adding a JSDoc @typedef declaration breaks emitting static getter to ".d.ts" files. #37289

kbkk opened this issue Mar 9, 2020 · 2 comments · Fixed by #37780
Assignees
Labels
Bug A bug in TypeScript

Comments

@kbkk
Copy link

kbkk commented Mar 9, 2020

TypeScript Version: 3.9.0-dev.20200309

Search Terms: static get, static get cannot find name

Code

'use strict';

class Handler {
	static get OPTIONS() {
		return 1;
	}

	process() {
	}
}

module.exports = Handler;

/**
 * @typedef {Object} HandlerOptions
 * @property {String} name
 */

Expected behavior:

export = Handler;
declare class Handler {
    static get OPTIONS(): number;
    process(): void;
}
declare namespace Handler {
    export { OPTIONS, HandlerOptions };
}
type HandlerOptions = {
    name: string;
};

Actual behavior:

// Missing `static get OPTIONS` declaration
// And an error is emitted: `TS2304: Cannot find name 'OPTIONS'.`
export = Handler;
declare class Handler {
    process(): void;
}
declare namespace Handler {
    export { OPTIONS, HandlerOptions };
}
type HandlerOptions = {
    name: string;
};

Playground Link: Provided

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 12, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Mar 12, 2020
@kbkk
Copy link
Author

kbkk commented Mar 23, 2020

Same problem with @callback JSdocs:

.js:

/**
 * @callback TransactionCallback
 * @param {Transaction}
 */

generated .d.ts:

// TS2693: 'any' only refers to a type, but is being used as a value here.
type TransactionCallback = (: any) => any;

@sandersn
Copy link
Member

sandersn commented Apr 3, 2020

The predicate the symbol serialiser uses to distinguish static properties from expando namespace properties is not precise enough. The fix is to make sure that properties defined inside a class are serialised there instead of in the merged namespace.

sandersn added a commit that referenced this issue Apr 3, 2020
Previously static class members would be treated the same way as expando
namespace assignments to a class:

```ts
class C {
  static get x() { return 1 }
}
C.y = 12
```

This PR adds a syntactic check to the static/namespace filter that
treats symbols whose valueDeclaration.parent is a class as statics.

Fixes #37289
sandersn added a commit that referenced this issue Apr 4, 2020
* Fix serialisation of static class members in JS

Previously static class members would be treated the same way as expando
namespace assignments to a class:

```ts
class C {
  static get x() { return 1 }
}
C.y = 12
```

This PR adds a syntactic check to the static/namespace filter that
treats symbols whose valueDeclaration.parent is a class as statics.

Fixes #37289

* fix messed-up indent

* Extract function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants