Skip to content

A extends B relation break after wrapping by extra interface #39549

Closed
@nzhl

Description

@nzhl

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions