nitro-codegen
Version:
The code-generator for react-native-nitro-modules.
16 lines (14 loc) • 459 B
text/typescript
import { NamedWrappingType } from './NamedWrappingType.js'
import type { Type } from './Type.js'
export function getTypeAs<T>(
type: Type,
classReference: new (...args: any[]) => T
): T {
if (type instanceof classReference) {
return type as unknown as T
} else if (type instanceof NamedWrappingType) {
return getTypeAs(type.type, classReference)
} else {
throw new Error(`Type of kind "${type.kind}" is not a ${classReference}!`)
}
}