Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dtslint changes output type based on $ExpectType values #632

Closed
marekdedic opened this issue Mar 8, 2023 · 3 comments
Closed

dtslint changes output type based on $ExpectType values #632

marekdedic opened this issue Mar 8, 2023 · 3 comments

Comments

@marekdedic
Copy link
Contributor

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.

@marekdedic marekdedic changed the title dtslint changes outputtype based on $ExpectType values dtslint changes output type based on $ExpectType values Mar 8, 2023
@marekdedic
Copy link
Contributor Author

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?

@marekdedic
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant