'what is the use of ! in object Typescript [duplicate]
I found something that I think is really strange. A ! inside an object
interface MyObj {
a?: string,
b: number
}
const toto: string = "test";
const obj: MyObj = {
a: toto!,
b: 0
}
I can't figure out what is the toto!
Solution 1:[1]
A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Specifically, the operation x! produces a value of the type of x with null and undefined excluded. See here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Charlo Poitras |
