Skip to content

Property assignment to static method of class breaks declaration emit #38553

Closed
@TimvdLippe

Description

@TimvdLippe

TypeScript Version: 4.0.0-dev.20200512

Search Terms: jsdoc, declaration, static method

Code

clazz.js:

export class Clazz {
  static method() {}
}

Clazz.method.prop = 5;

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "lib",
    "declaration": true,
    "allowJs": true,
    "checkJs": true
  },
  "files": [
    "clazz.js"
  ]
}

Expected behavior:
The emitted declaration file is:

export class Clazz {
    static method(): void;
}
export namespace Clazz {
    export namespace method {
        export const prop: number;
    }
}

Actual behavior:

export class Clazz {
}

Note that if the method is not static, it properly generates the declaration file.

Also, please don't ask me why this is in the DevTools codebase. I only found out that we did when TypeScript started complaining about missing methods even though they were defined. I then spend a long time trying to figure out what the issue was, until I discovered the property assignment. When I changed the property assignment to a normal variable declaration, TS was properly emitting the method again.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions