import { expectTypeOf } from 'expect-type'; import { ArrayDeclarationOption as ArrDec, FlagsDeclarationOption as FlagsDec, MapDeclarationOption as MapDec, NumberDeclarationOption as NumDec, ParameterType as PType, ParameterType, StringDeclarationOption as StrDec, } from 'typedoc'; import { InferDeclarationType, MapperPart, Option } from './option'; describe( 'Typings', () => { const maybe = true as boolean; it( 'should infer declaration', () => { if( maybe ) return; expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); } ); it( 'should have correct options values', () => { if( maybe ) return; const opt1 = Option.factory( {} as any )( { name: 'Hello', type: ParameterType.Number, help: 'Test', } ); expectTypeOf( opt1.getValue() ).toEqualTypeOf(); expectTypeOf( opt1.setValue ).parameter( 0 ).toEqualTypeOf(); expectTypeOf( opt1.getValue() ).not.toEqualTypeOf(); expectTypeOf( opt1.setValue ).parameter( 0 ).not.toEqualTypeOf(); const opt2 = Option.factory( {} as any )( { name: 'Hello', type: ParameterType.String, help: 'Test', }, v => parseInt( v, 10 ) ); expectTypeOf( opt2.getValue() ).toEqualTypeOf(); expectTypeOf( opt2.setValue ).parameter( 0 ).toEqualTypeOf(); expectTypeOf( opt2.getValue() ).not.toEqualTypeOf(); expectTypeOf( opt2.setValue ).parameter( 0 ).not.toEqualTypeOf(); } ); it( 'should infer mapper', () => { if( maybe ) return; expectTypeOf>().toEqualTypeOf<[mapper?: ( value: number ) => number]>(); expectTypeOf>().not.toEqualTypeOf<[mapper: ( value: number ) => number]>(); expectTypeOf>().toEqualTypeOf<[mapper: ( value: string ) => number]>(); expectTypeOf>>().toEqualTypeOf<[mapper?: ( value: {foo: true} ) => {foo: true}]>(); expectTypeOf>>().not.toEqualTypeOf<[mapper: ( value: {foo: true} ) => {foo: true}]>(); expectTypeOf>>().toEqualTypeOf<[mapper?: ( value: {foo: boolean} ) => {foo: boolean}]>(); expectTypeOf>>().not.toEqualTypeOf<[mapper: ( value: {foo: boolean} ) => {foo: boolean}]>(); } ); } );