Open
Description
🔎 Search Terms
I'm writing a generic function:
export function useKeyValueStore<T extends string | number | boolean>(
key: string,
initialValue: T,
): [T, (value: T) => void] {
if I call it with useKeyValueStore("someKey", 100)
, T gets inferred as 100
if I remove the extends string | number | boolean
type constraint, it gets inferred as number
this seems like unintended behavior - I'd like to keep the constraint and infer T as number
🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
No response
💻 Code
// Your code here
🙁 Actual behavior
see above
🙂 Expected behavior
see above
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels