microsoft/DefinitelyTyped-tools

dtslint changes output type based on $ExpectType values

marekdedic opened this issue · 3 comments

Hi,
I'm looking at commit 886607f and trying to get the tests to pass by modifying Line 379.

Currently I get the error:

ERROR: 380:1  expect  TypeScript@4.9 expected type to be:
  Page | Post
got:
  Page<"edit"> | Post<"edit">

however, if I change the expected value to be the returned value, I get

ERROR: 380:1  expect  TypeScript@4.9 expected type to be:
  Page<"edit"> | Post<"edit">
got:
  Page | Post

so it seems like dtslint can't decide whether it wants the type parameter ("edit" is actually the default value) or not.

I managed to track the issue down to

const actual = type
? checker.typeToString(type, /*enclosingDeclaration*/ undefined, ts.TypeFormatFlags.NoTruncation)
: "";
if (!expected.split(/\s*\|\|\s*/).some((s) => actual === s || matchReadonlyArray(actual, s))) {
unmetExpectations.push({ node, expected, actual });
}

So... it seems TypeScript itself is changing the type output based on the surroundings?

Ok, I'm dumb, the 2 errors were on different TS versions.