AnoopN
AnoopN

Reputation: 39

Typescript Generic type error

I have a utility function which does the type level check on injecting store to react component.

import { Omit } from 'typelevel-ts';
import * as React from 'react';

declare module 'mobx-react' {
  export function inject<D>(
   mapStoreToProps: (store) => D
  ): <A extends D>(component: React.ComponentType<A>) => 
   React.SFC<Omit<A, keyof D> & Partial<D>>;
}

With latest typescript version 2.9.2 I get an error "Type 'A' does not satisfy the constraint 'object'.Type 'D' is not assignable to type 'object'."

Can you please help to understand this error and possibly how to fix this.

thanks

Upvotes: 1

Views: 282

Answers (1)

kingdaro
kingdaro

Reputation: 12018

It looks like Omit requires the first generic to be an object, so it should work if you add that constraint for D:

export function inject<D extends object>(

Upvotes: 3

Related Questions