How to write a type guard function which behaves like the strict equal operator
I want to write a type guard function which compares the first given value with the second expected value and infers the type of the first value to be the same as the type of the second value. So regarding to type narrowing I want the type guard to do the same as the strict equal operator in this code:
TypeScript type guards. How to get type narrowing AND suggestions?
I have assertIsDefined
type guard with expected value.
I need to type narrowing to expected value with type suggestions.
Why write the returrn type of a type guard as `this is (…) & this` in TypeScript?
I’m reading the Classes section of the handbook, but there is a difference that makes me confused.