November 2019
Beginner
804 pages
20h 1m
English
If you take a close look at the code for the previous UserSettings example component, you may notice a weird exclamation mark:
@Inject("username")
username!: string; // definite assignment assertion
Now, what is it and why did we need it?
As the official TypeScript documentation (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#definite-assignment-assertions) states, definite assignment assertions can be used to tell the compiler that variables will indeed be assigned, even if TypeScript can't determine this on its own.
The definite assignment assertion is used through the ! character, and is defined after a property or variable declaration.
If we consider ...
Read now
Unlock full access