# Typescript - Tips & Tricks - Non-null assertion operator > In some cases, you have a field that you initialize in a method, and if you follow the flow of the... - **Author**: Luca Del Puppo (@puppo92) — AI Native Engineer at Nearform - **Published**: Mar 15, 2021 - **Canonical URL**: https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-non-null-assertion-operator/ - **Series**: TypeScript - Tips & Tricks (Part 13 of 21) — https://delpuppo.net/blog/series/ts-tips-and-tricks/ - **Series LLMs.txt**: https://delpuppo.net/blog/series/ts-tips-and-tricks/llms.txt - **Category**: TypeScript - **Tags**: typescript, webdev - **Hashnode Mirror**: https://blog.delpuppo.net/typescript-tips-tricks-non-null-assertion-operator - **Dev.to Mirror**: https://dev.to/playfulprogramming/typescript-tips-tricks-non-null-assertion-operator-21eb - **Blog Index LLMs.txt**: https://delpuppo.net/blog/llms.txt ## Series Context: TypeScript - Tips & Tricks - Part 1: [Typescript - Tips & Tricks - typeof](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-typeof/) - Part 2: [Typescript - Tips & Tricks - Literal Types](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-literal-types/) - Part 3: [Typescript - Tips & Tricks - keyof](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-keyof/) - Part 4: [Typescript - Tips & Tricks - Union and Intersection](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-union-and-intersection/) - Part 5: [Typescript - Tips & Tricks - Overloaded Functions](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-overloaded-functions/) - Part 6: [Typescript - Tips & Tricks - this parameter](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-this-parameter/) - Part 7: [Typescript - Tips & Tricks - any vs. unknown](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-any-vs-unknown/) - Part 8: [Typescript - Tips & Tricks - Optional modifier](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-optional-modifier/) - Part 9: [Typescript - Tips & Tricks - Index Signature](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-index-signature/) - Part 10: [Typescript - Tips & Tricks - readonly modifier](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-readonly-modifier/) - Part 11: [Typescript - Tips & Tricks - Readonly Array](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-readonly-array/) - Part 12: [Typescript - Tips & Tricks - Tuple](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-tuple/) - Part 13: [Typescript - Tips & Tricks - Non-null assertion operator](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-non-null-assertion-operator/) **(Current Article)** - Part 14: [Typescript - Tips & Tricks - Never type](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-never-type/) - Part 15: [Typescript - Tips & Tricks - Assert Function](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-assert-function/) - Part 16: [Typescript - Tips & Tricks - Type Guard](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-type-guard/) - Part 17: [Typescript - Tips & Tricks - Conditional Type](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-conditional-type/) - Part 18: [Typescript - Tips & Tricks - infer keyword](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-infer-keyword/) - Part 19: [Typescript - Tips & Tricks - Mapped Types](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-mapped-types/) - Part 20: [Typescript - Tips & Tricks - Advanced Types](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-advanced-types/) - Part 21: [Typescript - Tips & Tricks - Rest Parameters & Rest Arguments](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-rest-parameters-rest-arguments/) --- In some cases, you have a field that you initialize in a method, and if you follow the flow of the code you are sure that this field is initialized but typescript doesn't understand it. An example ```ts type Person = { name: string; }; let person: Person; function initialize() { person = { name: "name" }; } initialize(); console.log("Hello", person.name); // Variable 'person' is used before being assigned. ``` In this case, you can see how the typescript compiler doesn't understand that the "person" field isn't null but it's initialized. To resolve this problem, the typescript language exposes us the _"Non-null assertion operation"_(!). This operator says to the compiler that the field isn't null or undefined but it's defined. The previous example can be reviewed in this way ```ts type Person = { name: string; }; let person: Person; function initialize() { person = { name: "name" }; } initialize(); console.log("Hello", person!.name); ``` As you can see, in this case, the code doesn't have errors and the compilation ends with success. That's all for today! Bye-bye guys!