Open
Description
From https://github.com/squidfunk/typescript-issue-38339-repro (courtesy of @squidfunk)
TypeScript Version: 3.9.1-rc
Search Terms:
Subtype reduction, ternary
Code
import { JSX } from "preact"
type IntrinsicElements = JSX.IntrinsicElements[keyof JSX.IntrinsicElements]
export type IntrinsicElements2<
T = IntrinsicElements
> = {
[K in keyof T]: K extends "accept"
? T[K] | [string]
: T[K]
}
export type IntrinsicElements3<
T = IntrinsicElements2
> = {
[K in keyof T]: K extends "class"
? T[K] | [boolean]
: T[K]
}
export type IntrinsicElements4<
T = IntrinsicElements3
> = {
[K in keyof T]: K extends "id"
? T[K] | [number]
: T[K]
}
export function foo(): IntrinsicElements4 | undefined {
let t: IntrinsicElements4 | undefined
// this takes 2 seconds to check
return t
// this takes 10 seconds to check
// return true ? t : t
}
Expected behavior: return t
and return true ? t : t
check in a comparable amount of time
Actual behavior: the ternary is much slower
Related Issues: #38339