creditkarma / thrift-typescript

Generate TypeScript from Thrift IDL files
Apache License 2.0
155 stars 32 forks source link

3.7.2-0 has type errors for optional fields #166

Closed hayes closed 5 years ago

hayes commented 5 years ago

@kevin-greene-ck I did not test my change well enough. Just did a little more testing and realized I made a bad assumption.

The underlying issue is that the args interface has optional fields, but does not accept undefined as a value:

{ foo: undefined } is not assignable to { foo?: string }.

kevin-greene-ck commented 5 years ago

No worries, that's why I did a prerelease so I could run it through all our testing. Will you be able to fix or do I need to make time to look at it?

hayes commented 5 years ago

Still trying to fully understand the issue. I'll update in a few minutes when I have a better idea of how to fix it.

hayes commented 5 years ago

it looks like it may actually be related to strict unions

hayes commented 5 years ago

@kevin-greene-ck I think the solution is that for unions I need to change the generated code from:

const obj: TypeName = {...}; to const obj = {...} as TypeName;

does that sound reasonable?

hayes commented 5 years ago

the issue was actually that the compiler can't know that only one of the props is set for the unions type when it's reconstructing it from the args object.

hayes commented 5 years ago

It would be simpler to do the same thing for both structs and unions