-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScript
Milestone
Description
TypeScript Version: 3.7.0-dev.20190905
Search Terms: ParameterDecorator propertyKey
Code
The type ParameterDecorator is defined as follows in src/lib/es5.d.ts:
Line 1362 in 72bb4c2
| declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void; |
However, at runtime, constructor parameter decorators are invoked with propertyKey set to undefined.
Consider the following code:
function inject() {
return function i(target: Object,
propertyKey: string | symbol,
parameterIndex: number
): void {
console.log('propertyKey', typeof propertyKey);
}
}
class FooBar {
constructor(
@inject()
public name: string
) {}
}Compile it with experimentalDecorators enabled in tsconfig.json.
Expected behavior:
Either:
- The code does not compile, because the decorator function must accept
string | symbol | undefinedin thepropertyKeyargument - Or the program prints
propertyKey stringorpropertyKey symbolat runtime
Actual behavior:
- The code compiles
- The programs prints
undefinedat runtime
Playground Link:
Related Issues:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScript