Search code examples
typescriptgenericsantd

Type alias for generic with known parameter


I'm writing an AntD form. Is there a way to shorten the form component name with type, like this:

const CustomForm = Form<LongTypeName>
const CustomFormItem = CustomForm.Item

const Bar = () => (
  <>
    <CustomForm />
    ...
    <CustomFormItem />
  </>
)

I'm using AntD 4.24.7, TS 4.1.2.


Solution

  • With the hint of @slava-knyazev I find that the code only works in TS 4.7+. It is a feature called Instantiation expression.