TypeScript

Corset supports TypeScript out of the fox when you install the Corset package on npm.

When using the mount API and you should see intellisense as you type. However, TypeScript doesn't give great hints with bare classes like those used in Corset, so it can be helpful to pull in some types.

The MountedBehavior interface is used with mount to give full type completion. This example shows what you get after the types have been expanded. You only need to import and implement MountedBehavior.

import type { MountedBehavior, BehaviorContext, SheetWithValues } from 'corset';
import sheet, { mount } from 'corset';

mount(document, class implements MountedBehavior {
  bind(props: Map<string, any>, ctx: BehaviorContext): SheetWithValues {
    return sheet`
      #app {
        /** ... */
      }
    `;
  }
});

Custom functions

Similarly, when using custom functions via registerCustomFunction, you can get better type support by implementing the ICorsetFunction interface.

import type { ICorsetFunction, FunctionContext } from 'corset';
import { registerCustomFunction } from 'corset';

registerCustomFunction('--my-fn',  class implements ICorsetFunction {
  call([a, b]: [string, string], props: Map<string, any>, context: FunctionContext) {
      
  }
});