evanbb/fml

React: ease extension of FmlComponentProps<Value>

Opened this issue · 0 comments

Types aren't defined to easily reflect how FmlComponent implementation configs can be extended.

As it stands right now, the extra props are mixed into props.config, like this:

declare module '@fml/core' {
  export interface FmlFieldControlRegistry<TValue>
    extends Record<string, FmlFieldControlRegistration<unknown>> {
    customImpl: [string | undefined, { stuff: boolean }];
  }
}

function CustomImpl(props) {
  console.log(props) // { config: { stuff: false, ...rest } }
}

but the interface makes it seem like it should add extra props to... well, y'know, the PROPS, like this:

interface CustomProps extends FmlComponentProps<string | undefined> {
  stuff: boolean;
}

function CustomImpl(props: CustomProps) {
  const {
    config,
    stuff // this doesn't actually exist, but the types make it seem like it ought to 😭 
  } = props
}

Let's add another generic argument for extra props to FmlComponentProps:

interface FmlComponentProps<Value, ExtraConfig extends never = never> {
  config: FmlConfiguration<TValue> & ExtraConfig;
}