Dev Helpers
← Back

Derive an instance type

Derive an instance type using TypeScript.

Open this example in the interactive library

Source code

interface Named {
  name: string;
}
console.log(
  (() => {
    class Item {
      count = 2;
    }
    const item: InstanceType<typeof Item> = new Item();
    return item.count;
  })(),
);

Sample output

2