-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
TypeScript Version: 3.9.2
Search Terms: subtypes, extends
Expected behavior: {name: "age"} extends {name: string} so A extends B
Code
export type IsFlatObject<T extends object> = Extract<
Exclude<T[keyof T], Date | FileList>,
any[] | object
> extends never
? true
: false;
export type FieldValues = Record<string, any>;
export type FieldName<TFieldValues extends FieldValues> = IsFlatObject<
TFieldValues
> extends true
? Extract<keyof TFieldValues, string>
: string;
export type CustomElement<TFieldValues> = {
name: FieldName<TFieldValues>;
};
type ISChild<A, B> = A extends B ? true : false
type A = CustomElement<{age: string}> // i.e {name: "age"}
type B = CustomElement<FieldValues> // i.e {name: string}
type ShouldBeTrue = ISChild<{name: "age"}, {name: string}> // type true
type ShouldBeTrueAsWell = ISChild<A, B> // type false
Output
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}Playground Link: Provided
jamiehaywood
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone