Skip to content
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

"emitDecoratorMetadata" emits "Object" for "design:type" when type is inferred #18995

Closed
teq opened this issue Oct 6, 2017 · 4 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@teq
Copy link

teq commented Oct 6, 2017

TypeScript Version: 2.5.3

Code

import 'reflect-metadata'; // v0.1.10

class Foo {
    @LogType public str1: string;
    @LogType public str2 = 'hello';
    @LogType public num1: number;
    @LogType public num2 = 10;
    @LogType public bool1: boolean;
    @LogType public bool2 = true;
}

function LogType(target: any, propertyKey: string) {
    const type = Reflect.getMetadata("design:type", target, propertyKey);
    console.log(type.name);
}

tsconfig.json

{
    "compilerOptions": {
        ...
        "target": "es6",
        "module": "commonjs",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        ...
    }
}

Expected behavior:

String
String
Number
Number
Boolean
Boolean

Actual behavior:

String
Object
Number
Object
Boolean
Object
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Decorators The issue relates to the decorator syntax labels Oct 6, 2017
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.6.1 milestone Oct 6, 2017
@mhegazy mhegazy assigned weswigham and unassigned rbuckton Oct 6, 2017
@weswigham
Copy link
Member

I'm just going to point out that fixing this is, by definition, type directed emit.

@weswigham
Copy link
Member

@rbuckton was of the opinion that we could add extra check specifically looking to serialize the type from the literal kind of an initializer; but that we won't actually go and lookup type information for the initializer, as that's foo far down the type-directed path (and leads to needing to include the type system in file dependency analysis).

@mhegazy
Copy link
Contributor

mhegazy commented Oct 6, 2017

looking at this again. this is behaving as intended. we only serialize explicit types. implicit types are not serialized. this is the only way to make scenarios like single-file transpile works.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 6, 2017
@mhegazy mhegazy removed this from the TypeScript 2.6.1 milestone Oct 6, 2017
@mhegazy mhegazy removed Bug A bug in TypeScript Domain: Decorators The issue relates to the decorator syntax labels Oct 6, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 20, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants