You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type returned by validation with Dictionary differs from the type accepted by the type validator. This can lead to problems in runtime, even when we pass the type validation. I noticed it's occurring when the key in the dictionary is Union.
It looks like the validation performed by Dictionary is different than the type it says it returns. Indeed, if we try to create this object and during the declaration, we mark it's of this type, we fail at compilation.
typeDict=Static<typeofDict>;// Compile: Property 'b' is missing in type '{ a: number; }' but required in type '{ a: number; b: number; }'consttypedExample: Dict={a: 42};
The object which goes through the validation should be the same as the type. It'll reduce the number of possible problems.
In my opinion, the behaviour should be that the validation checks all the required keys for existence, so in the example Dict.check(example) should fail.
The text was updated successfully, but these errors were encountered:
Tested on:
@tsconfig/node18
: 2.0.1node
: 18.15.0runtypes
: 6.7.0typescript
: 5.1.3The type returned by validation with
Dictionary
differs from the type accepted by the type validator. This can lead to problems in runtime, even when we pass the type validation. I noticed it's occurring when the key in the dictionary isUnion
.Here's a simple example:
It looks like the validation performed by
Dictionary
is different than the type it says it returns. Indeed, if we try to create this object and during the declaration, we mark it's of this type, we fail at compilation.The object which goes through the validation should be the same as the type. It'll reduce the number of possible problems.
In my opinion, the behaviour should be that the validation checks all the required keys for existence, so in the example
Dict.check(example)
should fail.The text was updated successfully, but these errors were encountered: