-
Notifications
You must be signed in to change notification settings - Fork 458
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
Different behaviour than tsc+node when using class-transformer #257
Comments
I'm not familiar with class-transformer but the following looks odd somehow: @Type(() => Weapon)
public weapons: Map<string, Weapon>; Assuming @Type(() => Map)
public weapons: Map<string, Weapon>; ? That said, I'm actually a bit baffled because the start script seems to identify |
I looked into this a bit and I don't think this is a ts-jest issue. I've created a repository that illustrates this issue without using ts-jest. Here's the output of running
In the first case, the code is transpiled using the command line (and it works as you expect it to) In the second case, the code is transpiled using the Comparing line 30 in the two transpiled files (using command line and using typescript package) might give a hint to what's going wrong. The version of typescript in both cases was the same - Unless there's something I'm doing incorrectly when transpiling the code, this seems like an issue with Typescript. |
Thank you for the quick response!! |
For the record the issue was that That is an issue because:
|
@thevtm interesting - can you suggest an alternate approach? I haven't considering using anything else and going through the typescript source I'm not sure what the options would even be. I left a similar comment in the TypeScript repo on your issue. It looks like we may need to reopen this @kulshekhar |
@bcruddy I'm not sure about that. Unless there's a way to to replicate the behavior of the command line I don't know the reasons behind the behavioral difference but there shouldn't be any. |
I've managed to make it work using I don't know if it would satisfy the requirements. |
@thevtm this option would create the transpiled files on disk, right? |
Yes, but I think its possible to change that through
|
I gave it a quick look but couldn't figure out how to extract the transpiled code from this. Any idea? |
Using the
|
This might still be a problem. I think jest expects a transformer to return code synchronously |
It does. Transformers must be synchronous. |
Note that although it seems different, |
The way files get transpiled makes all libraries that use I'd like to state my disagreement with the classification of this problem as a TS bug. TS puts the tools at your disposal (see @thevtm's work, or the language services API), but you're not using them. There is a possibility to make this work, but it's not yet done, for reasons I can understand. I also understand that you don't owe the community anything, but I'd like to make a suggestion. Maybe it'd be interesting to put a note in the README to let your users know that libraries like |
Would definitely like a PR with this. I think this has most to do with the fact that jest allows you to preprocess one file at a time, and my impression is that stuff like this needs to have access to the complete type information. |
Closing this in favour of #439 - reasonably sure the solution will be the same. |
First of all great project, I have really been enjoying using it. 😄
I found a weird issue when doing some exploration testing on class-transformer.
I'm using class-transformer to convert a plain object to a classed instance. Like this:
Issue
class-transformer should transform the nested object
plainUser.weapons
fromobject
toMap<string, Weapon>
.The issue is that when I execute that test it fails, instead of transforming to
Map<string, Weapon
I getWeapon
.But when I run it regularly (
tsc
thennode
) it works.In test:
Expected behavior
In node:
Repo
npm start
runstsc
+node
(expected behaviour)npm test
runsjest
(issue)The text was updated successfully, but these errors were encountered: