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

ts-node breaks Date reflection mechanism #511

Closed
MichalLytek opened this issue Jan 14, 2018 · 13 comments
Closed

ts-node breaks Date reflection mechanism #511

MichalLytek opened this issue Jan 14, 2018 · 13 comments
Labels
question Support requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.

Comments

@MichalLytek
Copy link

MichalLytek commented Jan 14, 2018

import "reflect-metadata";

const CollectMetadata: PropertyDecorator = (target, propertyKey) => {
    const ReflectType = Reflect.getMetadata("design:type", target, propertyKey);
    console.log(ReflectType);
    console.log(ReflectType === Date);
}

class Test {
    @CollectMetadata
    property: Date;
}

ts-node output:

PS E:\#Programowanie\#GitHub\type-graphql> npx ts-node src/date.ts
E:\#Programowanie\#GitHub\type-graphql\node_modules\ts-node\dist\bin.js
[Function: Object]
false

tsc and node output:

PS E:\#Programowanie\#GitHub\type-graphql> npx tsc; node build/date.js
E:\#Programowanie\#GitHub\type-graphql\node_modules\typescript\bin\tsc
[Function: Date]
true

I have no idea what's going on, how can we check the emitted js files?
I'm using ts-node 4.1.0 😉

@MichalLytek
Copy link
Author

ping @blakeembrey after a week 😜

@EvanDarwin
Copy link

👍 I've also encountered this issue

@blakeembrey
Copy link
Member

Try using --type-check if you want type information.

@blakeembrey blakeembrey added the question Support requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead. label Jan 29, 2018
@MichalLytek
Copy link
Author

MichalLytek commented Jan 29, 2018

Ok, it works but why only Date reflection is broke without this mode? What does --type-check do? 😕 Why no "Use TypeScript with type checking" affect on this case?

@4F2E4A2E
Copy link

4F2E4A2E commented Feb 7, 2018

@blakeembrey why did you close this issue? Does it mean it's not a bug? Will this be covered somehow or is the param workaround the final solution?

@GeeWee
Copy link

GeeWee commented Feb 13, 2018

What does the --type-check flag do? We're having the same issue in ts-jest.

@blakeembrey
Copy link
Member

blakeembrey commented Feb 20, 2018

It does mostly what it sounds like. It uses the TypeScript compiler to compile using the language services and type system information. Without it is only a single file transpile. If you don't have type information, you won't be able to get features that are required by having type information (such as reflecting type information as metadata).

It is not a bug, if you want type information the solution is to enable type information.

Edit: I would imagine every type information reflection would not work with type information, but perhaps it's only type information from external files? I have not verified this.

@MichalLytek
Copy link
Author

I would imagine every type information reflection would not work with type information, but perhaps it's only type information from external files? I have not verified this.

I've tested it and every single reflection works (classes from external files, String, Number, Boolean, etc.), only the Date is reflected as Object in this mode. That's why it's weird, should we bump the question to the TS team?

@blakeembrey
Copy link
Member

@19majkel94 Without using --type-check? That's really interesting interesting, I expected an all or nothing case since the transpiler mode is a really quick x -> y operation without validation of types. Feel free to ping someone on the TS team, I'm not sure I'll have enough time to investigate the behaviour myself.

@dpaquette
Copy link

dpaquette commented Mar 23, 2018

I am running in to this problem too. I am using the --type-check flag to work around the issue but that is causing performance issues as sometimes ts-node --type-check .\app.ts takes several minutes to run. For comparison, ts-node .\app.ts takes ~5 seconds to run. I can consistently reproduce the slow compile time by using the --no-cache flag: ts-node --type-check --no-cache .\app.ts.

As @19majkel94 noted, the only type that doesn't get reflected properly when skipping type checking is Date properties. All other types are reflected properly.

I'm not sure how to bring this up with the TS team since tsc always produces the expected output.

@An1mus
Copy link

An1mus commented Apr 16, 2018

Can you please clarify this Issue, since I'm new.

If I'll use ts-node --type-check, terminal will wait for TS input.
But If I need to run unit tests, I need to specify this flag for constant usage.
How is that possible to do?

@blakeembrey
Copy link
Member

blakeembrey commented Apr 17, 2018

@An1mus Please check the documentation, it's in the README (you can use environment variables or if you're using by file you can use ts-node/register/type-check). If you need something else, please provide enough information for someone to assist you.

@kalani96746
Copy link

Iʻm not able to get decorator metadata data when using ts-node and I am in fact using --type-check and its still being this way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Support requests. We tend not to answer these on Github. Nowadays I convert to Discussion instead.
Projects
None yet
Development

No branches or pull requests

8 participants