You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the call to outerA(), the type of the func parameter is inferred as FuncA<(arg: 'a' | 'b') => void>, as determined by the type of the arg parameter.
In the call to outerB(), the type of the func parameter is inferred instead as FuncB<(arg: 'a' | 'b' | 'c') => void>, using the base constraint of inner's T parameter rather than the subtype of that constraint used by the arg parameter.
🙂 Expected behavior
I do not expect the addition of an optional property on FuncB<T> to break the type parameter inference. It seems that inner's T parameter should be inferred as 'a' | 'b' in both cases.
The text was updated successfully, but these errors were encountered:
TS2322: Type '(arg: 'a' | 'b') => void' is not assignable to type '(arg: "a" | "b" | "c") => void'.
Types of parameters 'arg' and 'arg' are incompatible.
Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'.
Type '"c"' is not assignable to type '"a" | "b"'.
The error goes away if you change FunctionComponent<P> to (props: PropsWithChildren<P>, context?: any) => ReactElement<any, any> | null (just the call signature without the optional properties).
Bug Report
🔎 Search Terms
function interface optional properties generics type parameters inference
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
In the call to
outerA()
, the type of thefunc
parameter is inferred asFuncA<(arg: 'a' | 'b') => void>
, as determined by the type of thearg
parameter.In the call to
outerB()
, the type of thefunc
parameter is inferred instead asFuncB<(arg: 'a' | 'b' | 'c') => void>
, using the base constraint ofinner
'sT
parameter rather than the subtype of that constraint used by thearg
parameter.🙂 Expected behavior
I do not expect the addition of an optional property on
FuncB<T>
to break the type parameter inference. It seems thatinner
'sT
parameter should be inferred as'a' | 'b'
in both cases.The text was updated successfully, but these errors were encountered: