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

Inference failure in <T>(f: (get: () => T) => T) => T #60929

Open
devanshj opened this issue Jan 7, 2025 · 1 comment
Open

Inference failure in <T>(f: (get: () => T) => T) => T #60929

devanshj opened this issue Jan 7, 2025 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@devanshj
Copy link

devanshj commented Jan 7, 2025

πŸ”Ž Search Terms

Similar/duplicate of #49618, #47599 & #30134. Sorry couldn't come up with a better title.

πŸ•— Version & Regression Information

Tested with TypeScript 5.7.2

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEYD2A7AzgF0XKGQC54AeAFQD4AKAM0IoHMQNaBKeAXjPhNY6585IAoQREbwMABnbYQuEBQr94AImXNBAeg3x4APQD8w0VgwBGaWBx4KAfXadV6rToNA

πŸ’» Code

declare const create: <T>(f: (get: () => T) => T) => T

let t0 = create(() => "")
//  ^? string

let t1 = create(_ => "")
//  ^? unknown

πŸ™ Actual behavior

t1 is inferred as unknown

πŸ™‚ Expected behavior

t1 should be inferred as string

Additional information about the issue

This is a minimal reproduction of zustand's create...

import { create } from "zustand"

let t0 = create(() => "")
//  ^? UseBoundStore<StoreApi<string>>

let t1 = create(_ => "")
//  ^? UseBoundStore<StoreApi<unknown>>

I'm certain this is a duplicate of one of the above mentioned issue I just want to know it's duplicate of which issue exactly

@Andarist
Copy link
Contributor

Andarist commented Jan 7, 2025

It looks to me like a duplicate of #49618 . There were also 2 other issues, similar to this one, reported recently: #60922 , #60544 . Despite those 2 mentioning NoInfer, the root cause of the issue is quite the same as here: resolving contextual parameter type that references a type parameter "fixes" its inference, it can't be changed afterward and the return type is not known at all before this point because it can only be computed after analyzing the function's body and that requires resolving the parameter's type

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants