Open
Description
π Search Terms
generic function optional undefined ? modifier return infer inferrence
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
// Since 4.7, TS doesn't innately add `|undefined` to optional params the way it does for props with EOPT off
type Expected = (arg?: number) => void
// ^? (arg?: number) => void
// But it adds it when instantiating a type from a generic param
type OptionalUnary<t> = (arg?: t) => void
type Fail = OptionalUnary<number>
// ^? (arg?: number | undefined) => void
declare const foo: <t>(arg?: t) => void
const instantiated = foo<number>
// ^? (arg?: number | undefined) => void
declare const bar: <t>(arg: t) => (arg?: t) => void;
const returned = bar(42);
// ^? (arg?: number | undefined) => void
π Actual behavior
(see example)
π Expected behavior
(see example)
Additional information about the issue
I don't think this is likely to cause type-safety issues. It's primarily just visual clutter and inconsistency with the standard behavior.