#Extending from Record<string, string>

3 messages · Page 1 of 1 (latest)

mortal oriole
#

Could someone explain that why is the code below shows error in case if I provide the interface instead of type?

type Obj = Record<string, string>;

class A<T extends Obj> {}

type AsType = {
    a: string;
}

// No error
class B extends A<AsType> {}

interface AsInterface {
  a: string;
}

// Error
/**
 * Type 'AsInterface' does not satisfy the constraint 'Obj'.
 * Index signature for type 'string' is missing in type 'AsInterface'.
 */
class C extends A<AsInterface> {}
naive charm
#

interfaces don't have an implicit index signature because they can be merged into

mortal oriole
#

got it, thanks for the fast answer!