diff --git a/src/__tests__/types/newable.ts b/src/__tests__/types/newable.ts new file mode 100644 index 0000000..2507cf7 --- /dev/null +++ b/src/__tests__/types/newable.ts @@ -0,0 +1,24 @@ +import {Newable} from '../../types'; + +interface TestInterface { + doSomething(): void; +} + +class Test implements TestInterface { + public doSomething(): void { + // Do something + } +} + +const correct1: Newable = Test; +const correct2: Newable = Test; +const correct3: Newable[] = [Test]; + +// @ts-expect-error +const incorrect1: Newable = new Test(); +// @ts-expect-error +const incorrect2: Newable = new Test(); +// @ts-expect-error +const incorrect3: Newable = 'Test'; +// @ts-expect-error +const incorrect4: Newable = () => Test; diff --git a/src/types/index.ts b/src/types/index.ts index 64fd6db..cd3fc9d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,6 +2,8 @@ export * from './arrayWithOneOrMore'; export * from './extractRecord'; export * from './extractRecordKeys'; export * from './makeOptional'; +export * from './maybe'; +export * from './newable'; export * from './oneOrMore'; export * from './promiseOr'; export * from './readonlyOr'; @@ -10,5 +12,4 @@ export * from './recursiveRequired'; export * from './replace'; export * from './requireOnly'; export * from './resolvePromise'; -export * from './maybe'; export * from './reverseMap'; diff --git a/src/types/newable.ts b/src/types/newable.ts new file mode 100644 index 0000000..049fd65 --- /dev/null +++ b/src/types/newable.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** + * A type for an instantiable class. + */ +export type Newable = new (...args: any[]) => T;