The Wayback Machine - https://web.archive.org/web/20210101141500/https://github.com/microsoft/TypeScript/issues/37314
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

Open
AnyhowStep opened this issue Mar 10, 2020 · 4 comments

Comments

@AnyhowStep
Copy link
Contributor

@AnyhowStep 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

@AnyhowStep AnyhowStep commented Mar 10, 2020

Type from here, #27024 (comment)

So, #27024 is related

@AnyhowStep
Copy link
Contributor Author

@AnyhowStep AnyhowStep commented Mar 10, 2020

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

@weswigham weswigham commented Mar 12, 2020

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

@AnyhowStep AnyhowStep commented Mar 13, 2020

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

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.