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

Typehole not picking up nulls #14

Closed
andrew-ironforge opened this issue May 22, 2021 · 4 comments
Closed

Typehole not picking up nulls #14

andrew-ironforge opened this issue May 22, 2021 · 4 comments

Comments

@andrew-ironforge
Copy link

I've got a typehole as follows:

Screen Shot 2021-05-21 at 7 51 50 PM

row is the following in the debugger:
Screen Shot 2021-05-21 at 7 52 21 PM

Notice how totalCompensation is null even though the typehole only picks up the string. I would expect the generated type to be totalCompensation: string | null;

I did run this typehole a number of times and it should have picked up the null value before I put a breakpoint here for a screenshot.

@rikukissa
Copy link
Owner

rikukissa commented May 22, 2021

It definitely seems like a bug. I wasn't able to reproduce it with

const list = ["hello", null];

type AutoDiscovered = any;

list.forEach((val) => {
  console.log(typehole.t3<AutoDiscovered>(val));
});

and keep getting null | string as the output type. Can you verify you have the latest typehole runtime installed (1.6.0)?
I made some fixes earlier, and it's possible that this would now be fixed.

There is a test case that checks that generating the right type from the samples, which leads me to believe that the issue might between the sample storage and the runtime.

@rikukissa
Copy link
Owner

rikukissa commented May 22, 2021

There also seems to be something off with how json-to-ts generates the types in case of null

With this input

{ __typeholeRootWrapper__: [ { a: 2 }, { a: null } ] }

We get this output

interface RootObject {
  __typeholeRootWrapper__: TypeholeRootWrapper[];
}
interface TypeholeRootWrapper {
  a?: number;
}

I'd expect it to be

interface RootObject {
  __typeholeRootWrapper__: TypeholeRootWrapper[];
}
interface TypeholeRootWrapper {
  a: number | null;
}

There's actually an issue about the exact problem MariusAlch/json-to-ts#17

@andrew-ironforge
Copy link
Author

Yeah I wonder if these are related. Perhaps json-to-ts just doesn't handle nulls well

@rikukissa
Copy link
Owner

I've now forked json-to-ts and fixed the null handling. The fix is available in release https://github.com/rikukissa/typehole/releases/tag/1.6.2 . See if upgrading the extension and the runtime package would fix this. I'll close this issue for now, but please reopen if it still happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants