I want to define a type in TypeScript, which among other keys has the key "description". The key should not be optional, the associated value should be allowed to be a string or null.
I tried to define my type like this:
type Form = {
id: string
name: string
description: string | null
}
Unfortunately, ESLint returns me this message:
Usage of "null" is deprecated except when describing legacy APIs; use "undefined" instead
If I declare description as undefined, but also the key becomes optional or not?
How to define the type so that this object is OK
const questions: Form = {
id: 'q1',
name: 'Test',
description: null
}
but not this one:
const questions: Form = {
id: 'q1',
name: 'Test'
}
and also not this one:
const questions: Form = {
id: 'q1'
}