However, if you use the non-null assertion operator, you can convey to the TypeScript compiler that the stringWord variable is never null or undefined. In this case, the following error will appear: Error: Object is possibly ‘null’.ts(2531) Refer to the following code: let stringWord: string | null ![]() In that case, the TypeScript compiler will reject our variable value since there is a possibility that it will have a null value. But suppose we define a function that accepts only a string type as a parameter. If we define a string-type variable as string | null, it means that the variable holds a string or null value. Let’s see some simple examples of how the exclamation mark is used in TypeScript. How does the exclamation mark behave in TypeScript? In this article, I will discuss several uses of the exclamation mark in TypeScript. ![]() This non-null assertion will remove null and undefined values. But when working with TypeScript, the exclamation mark acts as a non-null assertion operator. In many scripting languages, developers use the exclamation mark as a not operator. BoldSign – Electronic Signature Software.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |