Repository navigation
A behavior of conditional types is changed (regression) #30047
Copy link
Copy link
Open
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Description
Ryan Cavanaugh (@RyanCavanaugh) Wesley Wigham (@weswigham) Anders Hejlsberg (@ahejlsberg) Caused by #27697
TypeScript Version: 3.4.0-dev.20190222
Search Terms:
Code
type Attrs = Record<string, string | EventListener | null | undefined>;
type Children =
| Children.Void
| Children.Text
| Children.Collection
| Children.Record;
namespace Children {
export type Void = undefined;
export type Text = string;
export interface Collection extends ReadonlyArray<El> { }
export type Record = { [field: string]: El; };
}
interface El<
T extends string = string,
E extends Element = Element,
C extends Children = Children,
> {
readonly tag?: T;
readonly element: E;
children: Relax<C>;
}
type Relax<C extends Children> = C extends Children.Text ? Children.Text : C;
declare function f<C extends Children>( children: C): C;
declare function f (attrs: Attrs, ): void;
declare function f<C extends Children>(attrs: Attrs, children: C): C;
f({ a: 0 as any as El<'a', HTMLAnchorElement> }); // ok
f({ a: 0 as any as El<'a', HTMLAnchorElement, Children> }); // ok
f({ a: 0 as any as El<'a', HTMLAnchorElement, Children.Void> }); // error since 3.4.0-dev.20190222
f({ a: 0 as any as El<'a', HTMLAnchorElement, Children.Text> }); // error since 3.4.0-dev.20190222Expected behavior:
pass
Actual behavior:
error
Related Issues:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Activity
falsandtru commentedon Feb 22, 2019
#30010 may fix this.
jack-williams commentedon Feb 27, 2019
Another smaller repro:
A smaller repro.
I think the issue here is that variance markers are marking
CinRelaxas invariant. This is probably caused by #27697 and the extension to variance computation.Even though TypeScript never ends up relating two conditional types in a way the requires invariance of the check types, the effect of variance computation makes the assignment illegal.