score:0

after a large amount of experimentation, this what i ended up with. it appears to work correctly:

class basecomponent<props:object, state, defaultprops: $shape<props>> extends react.component<defaultprops, props, state> {
  static defaultprops: $abstract<defaultprops>;
  props: props;
  state: $abstract<state>;
}

the key was to define props/state/and defaultprops on basecomponent in addition to passing the type params through to react.components. i'm not sure why this is necessary, but it does solve the issue.

score:0

in order to have my code work with a variable number of generic arguments, this is how i ended up typing the component:

export default class newcomponent<p, s = {}> extends component<p, s> {
  props: p
  state: s
  ...
}

score:2

this works for me:

class basecomponent<d, p, s> extends react.component<d, p, s> {
    static defaultprops: d
    props: p
    state: s
    yourcustomfunction(): void
}

class you extends basecomponent<any, any, any> {
  --- component body ---
}

Related Query

More Query from same tag