-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
π Search Terms
generics, optional parameter, default generic type, generic constraint
π Version & Regression Information
- This changed between versions 4.1.5 and 4.2.3
β― Playground Link
Playground link with relevant code
π» Code
interface SomeInterface<T> {
value: T
}
declare function factory<T extends string = string>(optionalParameter?: T): SomeInterface<T>;
declare function echo<K extends {[key: string]: SomeInterface<any>}>(opt: K ): K;
const fallbackToConstraintInsteadOfDefault = echo({ foo: factory() } as const);π Actual behavior
the return type of echo is not fully of type K, but falls back to the constraint of K.
π Expected behavior
The return type is from the default type of T.
Notes
This behaviour does not occur in 4.1.5
This behaviour does not occur when no constraint for K is given.
This behaviour does not occur when factory gets called with a parameter.
This behaviour does not occur when the return value of factory is first stored in a variable.
Reloaded2
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug