Open Irelynx opened 2 years ago
TY @Irelynx for the issue. I'll look into it.
Yes, testDate
is ttly wrong.
This is caused by the strictNullChecks
tsconfig option. It is disabled by default and when it is disabled, you can assign null into many types.
Such as:
class Foo {
testString1: string = null;
testNumber: number = null;
testBoolean: boolean = null;
}
const x = new Foo();
x.testString1 = null;
x.testNumber = null;
x.testBoolean = null;
That is valid TS code with default tsconfig (with strictNullChecks disabled).
So when you have
class Foo {
testString1: string | null = null;
testNumber: number | null = null;
testBoolean: boolean | null = null;
}
it is the same type, cuz those null
s are stripped off. Compiler throws it away with disabled strictNullChecks
.
Solution is to enable the strictNullChecks
option.
There is a way how to get that information anyway (that there is union with null), but it is quite complicated and not reliable.
This must be handled so the reflection keeps standard behavior, no matter what the strictNullChecks
option is.
So with strictNullChecks: false
(default) every type will be union with null
.
So not just fooProp: string | null;
will be string | null
but fooProp: string;
will be string | null
too.
But this has big impact and it is quite complicated to implement this into currect version so it will be in the next
version.
Thanks a lot for your investigation!
I will try change the tsconfig and test my code as soon as I have time for it.
Hello.
I have tried to make some fields of class nullable, but can't get any information about allowed "nullable" behavior (same works with types, functions and interfaces too).
After a little investigation of the behavior, it turned out that the null type is added to field types in some cases. Here is an example code (ts) and "compiled" code (js):
As you can see, only types for
testNull
,testDate
,testNullLiteral
are shown as they should.Also, is the behavior of
testDate
correct?In
testDate
recursive reference specified to typetestDate
(_ßr.Type.store.getLazy(99)
)tst-reflect: 0.7.5 tst-reflect-transformer: 0.9.10