Skip to content

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

@AnyhowStep

Description

@AnyhowStep

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

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions