Sometimes we may want to explicitly assert whether the type of a expression is compatible with a certain type, but type assertion does not satisfy the type safety we want:
interface SomeEventData {
foo: number;
bar: string;
}
this.emit('some-event', {foo: 123} as SomeEventData);
The behavior is desired but it would be nice if we have an elegant way for more secure type checking instead of:
let data: SomeEventData = {foo: 123};
E.g.:
this.emit('some-event', {foo: 123}: SomeEventData);
Sometimes we may want to explicitly assert whether the type of a expression is compatible with a certain type, but type assertion does not satisfy the type safety we want:
The behavior is desired but it would be nice if we have an elegant way for more secure type checking instead of:
E.g.: