A third-party library exports a variable containing an enum instead of the enum itself:
enum Size { S, M, L }
export const sizeType: typeof Size = Size;
In my own code, how can I declare that something has type Size
?
import { sizeType } from '...';
interface Props {
size: /* What goes here that's equivalent to 'Size'? */
}
const props: Props = { size: sizeType.S };
props.size = sizeType.L;
Here are some declarations I tried that don't work:
size: typeof sizeType;
// error: Type 'Size' is not assignable to type 'typeof Size'.
size: typeof sizeType['S'];
// error: Type 'Size.L' is not assignable to type 'Size.S'.
size: InstanceType<typeof sizeType>;
// error: Type `typeof Size' does not satisfy the constraint 'abstract new (...args: any) => any`.