import { Type , TypeChecker } from "typescript" ; import { isSimpleType , SimpleType , SimpleTypeKind } from "../simple-type" ; import { toSimpleType } from "../transform/to-simple-type" ; import { or } from "../utils/list-util" ; import { isTypeChecker } from "../utils/ts-util" ; import { validateType } from "../utils/validate-type" ; import { SimpleTypeKindComparisonOptions } from "./simple-type-comparison-options" ; param type param kind param kind param checker param options export function isAssignableToSimpleTypeKind ( type , kind , options ? ) ; export function isAssignableToSimpleTypeKind ( type , kind , checker , options ? ) ; export function isAssignableToSimpleTypeKind ( type , kind , optionsOrChecker ? , options = { } ) { const checker = isTypeChecker ( optionsOrChecker ) ? optionsOrChecker : undefined ; options = ( isTypeChecker ( optionsOrChecker ) || optionsOrChecker == null ? options : optionsOrChecker ) || { } ; if ( ! isSimpleType ( type ) ) { return isAssignableToSimpleTypeKind ( toSimpleType ( type , checker ! ) , kind , options ) ; } return validateType ( type , simpleType => { if ( Array . isArray ( kind ) && or ( kind , itemKind => simpleType . kind === itemKind ) ) { return true ; } if ( simpleType . kind === kind ) { return true ; } switch ( simpleType . kind ) { case "OBJECT" : { if ( simpleType . members == null || simpleType . members . length === 0 ) { return isAssignableToSimpleTypeKind ( { kind : "ANY" } , kind , options ) ; } break ; } case "ANY" : { return options . matchAny || false ; } case "ENUM_MEMBER" : { return isAssignableToSimpleTypeKind ( simpleType . type , kind , options ) ; } } } ) ; }