`design:type`/`design:paramtypes`/`design:returntype` is wrong for Enums in a different module
sapphi-red opened this issue · comments
Describe the bug
When using a type from a different module in a property or method that has a decorator and emitDecoratorMetadata
is enabled, SWC uses typeof Namespace === "undefined" || typeof Namespace.TypeName === "undefined" ? Object : Namespace.TypeName
as the value to pass to _ts_metadata
.
This is wrong because Namespace.TypeName
could be a enum
. If it's an enum
, the value should be Number
or String
depending on the definition of that enum
. But the code emit by SWC returns Object
.
TypeScript emits typeof (_b = typeof Enums !== "undefined" && Enums.Options) === "function" ? _b : Object
, which does not have this problem.
Input code
import * as Enums from './enums'
function decorate() {}
class Foo {
@decorate()
foo(options: Enums.Options): Enums.Options {}
@decorate()
bar: Enums.Options
}
Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true
},
"target": "es2024",
"loose": false,
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
The output uses typeof (_b = typeof Enums !== "undefined" && Enums.Options) === "function" ? _b : Object
, which avoids this problem.
Actual behavior
The output uses typeof Enums === "undefined" || typeof Enums.Options === "undefined" ? Object : Enums.Options
, which has this problem.
Version
1.13.5
Additional context
No response