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

Nested conditional types and generics, testing type equality evaluating to incorrect branch #37314

Closed
AnyhowStep opened this issue Mar 10, 2020 · 4 comments · Fixed by #42525
Closed
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@AnyhowStep
Copy link
Contributor

AnyhowStep commented Mar 10, 2020

TypeScript Version: 3.5.1, 3.8.3

Search Terms:
conditional types, generics, equality

Code

strictNullChecks and strictFunctionTypes enabled

export type Equals<A1 extends any, A2 extends any> =
    (<A>() => A extends A1 ? 1 : 0) extends (<A>() => A extends A2 ? 1 : 0)
    ? 1
    : 0

interface Foo<T> {
    x : () => T
}

declare const a: Foo<Date>;
declare const b: Foo<Date | null>;

//Expected 0, Actual 1
type ShouldBe0 = Equals<typeof a, typeof b>;

Expected behavior:

Evaluates to 0

Actual behavior:

Evaluates to 1

Playground Link: http://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=16&pc=1#code/FAUwHgDg9gTgLgAjgTwiBBRAjgVwIYA2AzgDwCCAjAuHCAHYAmRCedyANAmQEzVi2NmrZAD4EAXmAJpCABTkRsgJQSxZPgKZcqAfgRUAXAgAMKmvS3yyileLUaLzHgj2GTSqTNefpR48GAASzpaGAAzPABjdAAxKCgSABUxAG8fBDAEI2VVBETgAF8AhhBIgjwYdEioOiJEPCM4hIARPFoRAG5gErKKqpq6hAAjRviSVtoEAB8EOhwCAk6AgHpljEhS2gYTTjJIuHwCfWAUNAQAZQALKHmGACEQYwlMXEJSU5AoMJZOD6-hpZAA

Related Issues: Not that I know of

I filed this issue over here as well, millsp/ts-toolbelt#97


Looking at the type, it should work. But it doesn't. I think it might indicate something is broken with TS

@AnyhowStep
Copy link
Contributor Author

Type from here, #27024 (comment)

So, #27024 is related

@AnyhowStep
Copy link
Contributor Author

The comment was made on September 2018.

Around that time, TS 3.0 and TS 3.1 were out.

It also breaks for TS 3.0 and TS 3.1

TS 3.0 Playground

TS 3.1 Playground

@weswigham
Copy link
Member

Hm, so this is fixed in master, or at least it no longer reproduces. @RyanCavanaugh do we want to track down and backport the fix to 3.8?

@AnyhowStep
Copy link
Contributor Author

I'm wondering if this should be added to the test suite, just to be safe =x

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 31, 2020
weswigham added a commit to weswigham/TypeScript that referenced this issue Jan 27, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jan 27, 2021
weswigham added a commit that referenced this issue Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants