import { CallExpression , TypeChecker } from '@tsd/typescript' ; import { Diagnostic } from '../interfaces' ; import { Handler , isIdentical , isNotIdentical , isNotAssignable , expectDeprecated , expectNotDeprecated , prinTypeWarning , } from './handlers' ; export enum Assertion { EXPECT_TYPE = 'expectType' , EXPECT_NOT_TYPE = 'expectNotType' , EXPECT_ERROR = 'expectError' , EXPECT_ASSIGNABLE = 'expectAssignable' , EXPECT_NOT_ASSIGNABLE = 'expectNotAssignable' , EXPECT_DEPRECATED = 'expectDeprecated' , EXPECT_NOT_DEPRECATED = 'expectNotDeprecated' , PRINT_TYPE = 'printType' } const assertionHandlers = new Map < Assertion , Handler > ( [ [ Assertion . EXPECT_TYPE , isIdentical ] , [ Assertion . EXPECT_NOT_TYPE , isNotIdentical ] , [ Assertion . EXPECT_NOT_ASSIGNABLE , isNotAssignable ] , [ Assertion . EXPECT_DEPRECATED , expectDeprecated ] , [ Assertion . EXPECT_NOT_DEPRECATED , expectNotDeprecated ] , [ Assertion . PRINT_TYPE , prinTypeWarning ] ] ) ; param typeChecker param assertions returns export const handle = ( typeChecker , assertions ) : Diagnostic [ ] => { const diagnostics = [ ] ; for ( const [ assertion , nodes ] of assertions ) { const handler = assertionHandlers . get ( assertion ) ; if ( ! handler ) { continue ; } diagnostics . push ( ... handler ( typeChecker , nodes ) ) ; } return diagnostics ; } ;