How to tell TypeScript that optional property in object exists and is set?

old question, but there’s a very clean solution in newer versions of typescript

fn(myVar!);

In Typescript, what is the ! (exclamation mark / bang) operator when dereferencing a member?

EDIT:
This doesn’t answer the original question in which the OP wanted to tell Typescript that propertyA is defined inside myVar. This solution was biased by the misleading title, and it only shows how to instruct Typescript that a given var (myVar!) or property (myVar.propertyA!) is defined.

It seems many people come here by looking at the title and find this answer helpful.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)