tc39 / proposal-type-annotations

ECMAScript proposal for type syntax that is erased - Stage 1
https://tc39.es/proposal-type-annotations/
4.27k stars 47 forks source link

Occasional type erasure #215

Open hydroper opened 8 months ago

hydroper commented 8 months ago

I read that some people find the type erasure proposal not trustworthy as tools such as TypeScript and Flow have different type checking behavior and may also vary due to version upgrades.

If the proposal was taking the runtime types approach, possibly there could be a special treatment of complex types such as union and complement types, similiar to polymorphism:

For example, consider the following program:

type U = "n1" | "n2";

const v: U = "nN";

The above program generates a compile time verify error. If it were valid, it'd translate to:

const v: any = "nN";

Complex types include: