-1

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!

Thibaud
  • 1,059
  • 4
  • 14
  • 27

1 Answers1

0

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

Charlo Poitras
  • 198
  • 1
  • 14