import { Node , Program , Type , TypeChecker } from "typescript" ; import { isSimpleType , SimpleType } from "../simple-type" ; import { toSimpleType } from "../transform/to-simple-type" ; import { isNode , isProgram , isTypeChecker } from "../utils/ts-util" ; import { isAssignableToSimpleType } from "./is-assignable-to-simple-type" ; import { SimpleTypeComparisonOptions } from "./simple-type-comparison-options" ; interface TypeCheckerWithInternals extends TypeChecker { isTypeAssignableTo ( source , target ) : boolean ; } param typeA param typeB param checkerOrOptions param options export function isAssignableToType ( typeA , typeB , options ? ) ; export function isAssignableToType ( typeA , typeB , checker , options ? ) ; export function isAssignableToType ( typeA , typeB , checker , options ? ) ; export function isAssignableToType ( typeA , typeB , checker , options ? ) ; export function isAssignableToType ( typeA , typeB , checkerOrOptions ? , options ? ) { if ( typeA === typeB ) return true ; const checker = isTypeChecker ( checkerOrOptions ) ? checkerOrOptions : isProgram ( checkerOrOptions ) ? checkerOrOptions . getTypeChecker ( ) : undefined ; options = { ... ( checkerOrOptions == null ? { } : isProgram ( checkerOrOptions ) ? checkerOrOptions . getCompilerOptions ( ) : isTypeChecker ( checkerOrOptions ) ? { } : checkerOrOptions ) , ... ( options || { } ) } ; typeA = isNode ( typeA ) ? checker ! . getTypeAtLocation ( typeA ) : typeA ; typeB = isNode ( typeB ) ? checker ! . getTypeAtLocation ( typeB ) : typeB ; if ( ! isSimpleType ( typeA ) && ! isSimpleType ( typeB ) && checker != null && ( checker as TypeCheckerWithInternals ) . isTypeAssignableTo != null ) { return ( checker as TypeCheckerWithInternals ) . isTypeAssignableTo ( typeB , typeA ) ; } const simpleTypeA = isSimpleType ( typeA ) ? typeA : toSimpleType ( typeA , checker ! ) ; const simpleTypeB = isSimpleType ( typeB ) ? typeB : toSimpleType ( typeB , checker ! ) ; return isAssignableToSimpleType ( simpleTypeA , simpleTypeB , options ) ; }