Skip to content

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

@devanshj

Description

@devanshj

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions