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

NoInfer isn't erased and breaks type narrowing #58266

Closed
patroza opened this issue Apr 20, 2024 · 3 comments Β· Fixed by #58292
Closed

NoInfer isn't erased and breaks type narrowing #58266

patroza opened this issue Apr 20, 2024 · 3 comments Β· Fixed by #58292
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@patroza
Copy link

patroza commented Apr 20, 2024

πŸ”Ž Search Terms

NoInfer

πŸ•— Version & Regression Information

  • This changed between versions 5.3 and 5.4 (introduced)

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240419#code/C4TwDgpgBAglC8UDeB9YBDA5gLigInTwF8AoUSKAIQWTS1zwCNiSzxoBVGuAHytYD0AqOWgA5APYBJAHYAzCACcATAB4YAPm6sAxhJkBnYFAC2uJIogGArgBtguSbIWLVHDUQDaAXRo-WctYyOsAAlvqm6GDqADRUGgAUocAQJga4lugAJvq2ILA+cXK4CeiO0vJK6hoAlAhalHVIUJbA1ooyUFDJqQYAdCZRCXJ1pEJQEDJZBlDWYFDoM1AJzZY29uXOVe4A3FBEUHwydrY1Pt2GKdlQEnLLq1Z2DrB7B0cnZ94kepdQBhImCDAAAWoRkmBogzACRMcQSKDq8C0KD6ayefToEPg2PwhCgAH5kFA+iSUHE0RsoCiKcYDrhjrZTiQgA

πŸ’» 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

@saram-aman
Copy link

saram-aman commented Apr 20, 2024

@patroza can i work on the issue? if so then please assign!

@patroza
Copy link
Author

patroza commented Apr 20, 2024

@patroza can i work on the issue? if so then please assign!

please feel free. I know @Andarist wants to look into it next days, but no time like the present :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants