allow missing properties for 'undefined' type
Derya opened this issue · 2 comments
If I have an interface like this:
interface Data {
id: number;
name: string;
colors: ThemingColor[] | undefined;
}
A value without a colors
field all will fail the check. Is there any way I can configure it to allow missing fields for the undefined
type? Or some other type, perhaps?
Semi-related: I'm also not really sure if this is in scope for this project, or if you're interested in curating more stuff for this project in general, but it'd also be nice if this library could mutate the data to fit my interface to some extent. Specifically I want to be able to have an interface that specifies an array or object and if that key is missing, it should be instantiated as an empty array/object. Is an option like that interesting to you guys at all? I can maybe build it and make a PR if so.
If you specifiy
interface Data {
id: number;
name: string;
colors?: ThemingColor[];
}
then missing colors
would be allowed. This matches TypeScript's behavior in this respect.
As for other stuff, I think there is indeed sometimes a need for what you mention, but it could be created as a standalone library that depends on ts-interface-checker
(since it can benefit from all the structures in it), but doesn't seem like it requires to be built into it, so I think it's better not to.
Okay excellent, thanks for the help!