Skip to content

Constraints are not considered for Conditional Types #31096

Closed
@hediet

Description

@hediet

TypeScript Version: 3.5.0-dev.20190424

Code

function f<
	TType extends { p: string },
>(
	bla: TType
): void {
	const x: TType['p'] = 'test'; // typechecks
	const y: TType["p"] extends string ? string : number = "test"; // does not
}

Expected behavior:
It typechecks.

Actual behavior:
It does not:

Type '"test"' is not assignable to type 'TType["p"] extends string ? string : number'.
const y: TType["p"] extends string ? string : number

The assignment to x however typechecks.

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions