Z
Z
zlodiak2019-07-16 15:20:33
typescript
zlodiak, 2019-07-16 15:20:33

Is it necessary to specify the type?

Please tell me in this code:

ColorScheme = 'primary'|'accent'|'warn';
.....
@Input() public color: ColorScheme|null = null;

is it necessary to specify the type with: The fact is that if I remove |null , then there are no error messages in the console
|null

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-07-16
@zlodiak

When how :

By default nulland undefinedare subtypes of all other types.
<...>
However, when using the --strictNullChecksflag, nulland undefinedare only assignable to any and their respective types

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question