0

I create a template VueJS using typescript, I found the example code has a line

export default class HelloWorld extends Vue {
  @Prop() private msg!: string;
}

If I remove !, vscode said

Property 'msg' has no initializer and is not definitely assigned in the constructor.Vetur(2564)

I searched ! in Google but found nothing, what does it do exactly?

Steve Lam
  • 979
  • 1
  • 17
  • 40
  • 1
    These two answers might help you: https://stackoverflow.com/questions/57816914/exclamation-mark-in-type-definition/57816974#57816974 and https://stackoverflow.com/a/42274019/2404452 – blaz Feb 05 '20 at 04:04
  • @sayalok: It's not, my question relates to `!` – Steve Lam Feb 05 '20 at 04:04
  • Thank @blaz, I got it now – Steve Lam Feb 05 '20 at 04:05
  • 1
    This feature was added in TS2.7. Relevant documentation: [definite assignment assertions with `!`](http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#definite-assignment-assertions) – jcalz Feb 05 '20 at 17:33

0 Answers0