L
L
lexstile2020-10-23 21:01:41
typescript
lexstile, 2020-10-23 21:01:41

What is the correct way to type number|null?

I'm trying to write:

export interface ApplicationInit {
  initialPayment: number|null;
}
const initialState: ApplicationInit = {
  initialPayment: null,
};

Gives an error:
5f931a6c3a90c227200575.png
How can I fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-10-24
@lexstile

An interface in TypeScript can have multiple declarations in code, and TypeScript will combine them all into one generic type. Judging by the error with your ApplicationInit, this is exactly what happened, in addition to the initialPayment field, other fields are declared in another declaration, which is why it requires them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question