0

What are the meanings of ! signs in type definitions in *.tsx files?

Is it sugar coat of a feature while creating an a instance property?

For example: provider!: Web3Provider;

Cem Kaan
  • 2,086
  • 1
  • 24
  • 55
  • https://stackoverflow.com/questions/38874928/operator-in-typescript-after-object-method – Chellappan வ Mar 24 '22 at 07:06
  • Does this answer your question? [In Typescript, what is the ! (exclamation mark / bang) operator when dereferencing a member?](https://stackoverflow.com/questions/42273853/in-typescript-what-is-the-exclamation-mark-bang-operator-when-dereferenci) – luk2302 Mar 24 '22 at 07:07
  • I think question should stay. It is not duplicate of any other non-null assertion operator info. I already knew what is it but I just discovered it is available in `instance properties ` – Cem Kaan Mar 24 '22 at 07:15
  • This is not just a simple `non-null assertion operator` It's special for assignments – Cem Kaan Mar 24 '22 at 07:22

1 Answers1

0

Thanks for your comments.

I found answer by ...

  1. removed ! sign from code.
  2. TSlint said: Property 'provider' has no initializer and is not definitely assigned in the constructor.ts(2564)
  3. The Quick fix tool recommended me to add Definite Assignment Assertions
  4. Googled Definite Assignment Assertions and found out they are That's the non-null assertion operator.

It is a way to tell the compiler "don't complain about the possibility of it being null or undefined."

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#definite-assignment-assertions

Cem Kaan
  • 2,086
  • 1
  • 24
  • 55