If you know from external means that an expression is not null
or undefined
, you can use the non-null assertion operator !
to coerce away those types:
// Error, some.expr may be null or undefined
let x = some.expr.thing;
// OK
let y = some.expr!.thing;
More Related Contents:
- ‘unknown’ vs. ‘any’
- *ngFor running an infinite loop in angular2
- About “*.d.ts” in TypeScript
- Exclude property from type
- Why am I getting an error “Object literal may only specify known properties”?
- How to get query params from url in Angular 2?
- Understanding esModuleInterop in tsconfig file
- How to inject Document in service?
- In TypeScript, how to get the keys of an object type whose values are of a given type?
- Implementing a generic function with a conditional return type
- Angular2: How to load data before rendering the component?
- How to define static property in TypeScript interface
- Is there a way to define type for array with unique items in typescript?
- What is the difference between type and class in Typescript?
- TypeScript Import Path Alias
- Declaring the type of ‘this’ in a typescript function?
- Using eslint with typescript – Unable to resolve path to module
- Typescript error: TS7053 Element implicitly has an ‘any’ type
- In Typescript what does mean?
- What does the tsconfig option “lib” do?
- Accessing a property in a parent Component
- TypeScript error in Angular2 code: Cannot find name ‘module’
- Is this behavior of “𝚊𝚗𝚢” a TypeScript Type System Bug?
- Class type check in TypeScript
- Typescript: Type of a property dependent on another property within the same object
- Naming of TypeScript’s union and intersection types
- Eliminate nevers to make union possible
- Union and Intersection of types
- What is the “as syntax” pointed out by tslint?
- Jest won’t transform the module – SyntaxError: Cannot use import statement outside a module