JmJ
JmJ

Reputation: 2098

TypeScript `extend` produces ESLint error when extending a generic

I have a load of models that have some meta data appended, so I created a generic type to append them to the models when they're present:

type WithMeta<T> = T extends Meta;

Although this produces the following error: Parsing error: '?' expected.

ESLint isn't telling me which rule is triggering this, so hoping someone here knows the answer? Thanks

Upvotes: 4

Views: 4235

Answers (1)

JmJ
JmJ

Reputation: 2098

I was able to fix my issue with &:

interface Meta {
  createdAt: string;
  updatedAt: string;
}

type WithMeta<T> = T & Meta;

Upvotes: 7

Related Questions