microsoft/typescript-go

Different error message when asserting between unrelated types

Closed this issue · 4 comments

Steps to reproduce

type State = { __content: string, name: string };
let o = { uuid: "" };

let v = o as State;

Playground Link

Behavior with typescript@5.8

We get this errro:

src/index.ts:4:9 - error TS2352: Conversion of type '{ uuid: string; }' to type 'State' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type '{ uuid: string; }' is missing the following properties from type 'State': __content, name

Behavior with tsgo

We don't get the part about type sufficiently overlapping:

src/index.ts:4:9 - error TS2739: Type '{ uuid: string; }' is missing the following properties from type 'State': __content, name

I might be wrong, but I think this might have been intentional? @ahejlsberg

I might be wrong, but I this might have been intentional? @ahejlsberg

Is the strategy to also make changes on the ts-go version that are not ported to the js version? Because that will make validating that there is parity between the two versions more difficult.

Yes, there are some differences; a couple in printback like this one, along with other differences like not arbitrarily cutting off "did you mean" after a hardcoded number (impossible to achieve concurrently).

I do not suspect you will hit many. I think it's only one or two like this. I remember this one pretty early on. I don't remember exactly the rationale, but the elaboration stack is one of the things with super complicated logic (elaboration skipping, mutable chains) and I believe the code was simplified.

This one wasn't intentional, but rather an effect of simplifying the old obtuse error elaboration/suppression logic. I think there is value in preserving the insufficient overlap elaboration, so I'll put up a fix.