0
export interface A {
  a?: string
  aa?: number
}

export interface B extends A {
  b?: string
  bb?: boolean
}

export interface C {
  <D extends B>(d: D): void
}

let c: C = <D extends B>(d: D) => {
  let h: D = { // Type '{ a: string; aa: number; b: string; bb: false; }' is not assignable to type 'D'.'{ a: string; aa: number; b: string; bb: false; }' is assignable to the constraint of type 'D', but 'D' could be instantiated with a different subtype of constraint 'B'.
    a: '',
    aa: 1,
    b: '',
    bb: false
  }
}

the line declared h has Error: Type '{ a: string; aa: number; b: string; bb: false; }' is not assignable to type 'D'. '{ a: string; aa: number; b: string; bb: false; }' is assignable to the constraint of type 'D', but 'D' could be instantiated with a different subtype of constraint 'B'.

Ma Tianqi
  • 198
  • 1
  • 8
  • 1
    https://github.com/microsoft/TypeScript/issues/29397 + https://github.com/Microsoft/TypeScript/issues/29049 – zerkms Sep 23 '19 at 03:15
  • 2
    As it is, you can call `c` like `c<{a: 'x'}>({a: 'x'});` which perfectly satisfies the type constraints, but... `h` wouldn't meet `{a: 'x'}` which is why you get the warning. – acdcjunior Sep 23 '19 at 03:23
  • 1
    Possible duplicate of [could be instantiated with a different subtype of constraint 'object'](https://stackoverflow.com/questions/56505560/could-be-instantiated-with-a-different-subtype-of-constraint-object) – ford04 Sep 23 '19 at 05:14

0 Answers0