Closed
Description
π Search Terms
NoInfer
π Version & Regression Information
- This changed between versions 5.3 and 5.4 (introduced)
β― Playground Link
π» Code
type A = {_tag: "a"}
type B = {_tag: "b"}
type U = A | B
// type NoInfer2<A> = A
const m: { result: NoInfer<U> }[] = []
function map<A, B>(items: readonly A[], f: (a: NoInfer<A>) => B) { return items.map(f) }
// ends up as ({ result: NoInfer<U>; } | null)[] instead of ({ result: A; } | null)[]
const something = map(m, (_) => _.result._tag === "a" ? { ..._, result: _.result } : null)
π Actual behavior
ends up as ({ result: NoInfer<U>; } | null)[]
π Expected behavior
({ result: A; } | null)[]
Additional information about the issue
use the custom NoInfer2
type instead, and it works as expected.
Here's the actual source that lead me to the problem https://www.typescriptlang.org/play#code/JYWwDg9gTgLgBAbzgQSlAhgTwDRwKIBmBApgMYy4DyYMwEAdnAL5wFQQhwBExRZMXAFCDSDAM7woxMQFcANjDFwAvHADahEuQB0s0qWLEAJgAoAjAEptYYGGInN-bcQAewCvj4709IwBUAC2J6E1d3FQA+OBMkMPgmCwtcRx0oGXoAZUx6UgsAXWFReglWdGA5YxUUNCxtAnKYYigAWXQwEylZBTFcEwB9C0jBOBG+5zcYbT6YdABzFWVVLgAxMrkZKS44AH44aloGXQ57JG0zvtw4gC44MbjmQZv9unptegZ7C0EvoA