// Test ArgN types statically import * as a from './index'; import { ArgsN, ArgsNum } from './pick-rangen'; import { ReplaceReturn } from './replace-return'; import { ArgI } from './pick'; import { CtorArgs } from './ctor-args'; function staticAssert1Args() { function foo(a: string, b: number) { /** */ } const assertion: a.Arg2 = 123; function boo(a: a.Arg1, b: a.Arg2) { /**/ } boo('hello', assertion); } function staticAssert2ArgN() { function f( a: string, b: number, c: boolean, d: undefined, e: object, f: Function, g: string, h: number, i: boolean, j: null, ) { /** */ } const arg1: a.Arg1 = 'hello'; const arg2: a.Arg2 = 123; const arg3: a.Arg3 = true; const arg4: a.Arg4 = undefined; const arg5: a.Arg5 = {}; const arg6: a.Arg6 = () => {}; const arg7: a.Arg7 = 'hello'; const arg8: a.Arg8 = 321; const arg9: a.Arg9 = false; const arg10: a.Arg10 = null; } function staticAssert3Pre() { function foo(a: string, b: number) {} let boo: (x: boolean, a: string, b: number) => void; boo = foo as any as a.Pre1Arg2; let goo: (x: boolean, y: number, a: string, b: number) => void; goo = foo as any as a.Pre2Arg2; } function staticAssert4PreN() { function foo(a: string, b: number) {} let boo: (x: boolean, a: string, b: number) => void; boo = foo as any as a.Pre1ArgN; let goo: (x: boolean, y: number, a: string, b: number) => void; goo = foo as any as a.Pre2ArgN; } function staticAssert5PickRange() { function foo(a: string, b: number, c: boolean) {} const args: a.Args2off1 = [ 123, true ]; } function staticAssert6Post() { function foo(a: string, b: number) {} let boo: (a: string, b: number, x: boolean) => void; boo = foo as any as a.Post1Arg2; let goo: (a: string, b: number, x: boolean, y: number) => void; goo = foo as any as a.Post2Arg2; } function staticAssert7PickRangeN() { function foo(a: string, b: number, c: boolean) {} const args: ArgsN = [ 'hello', 123, true ]; function boo() {} const args2: ArgsN = []; } function staticAssert8PostN() { function foo(a: string, b: number) {} let boo: (a: string, b: number, x: boolean) => void; boo = foo as any as a.Post1ArgN; let goo: (a: string, b: number, x: boolean, y: number) => void; goo = foo as any as a.Post2ArgN; } function staticAssert9ReplaceReturn() { function foo(a: string, b: number) { return 'hello world'; } let boo: (a: string, b: number, x: boolean) => number; boo = foo as any as ReplaceReturn>; } function staticAssert10ReplaceReturn() { function foo(a: number, b: string): number { return 0; } function boo(a: number, b: string): string { return '0'; } const booFromFoo: ReplaceReturn = boo; } function staticAssertRestArgsN() { const myCallbacks = { foo: (a: number, b: number) => a + b, boo: (a: number) => a + 10, }; function call< CallbackName extends keyof Callbacks, Callbacks extends { [k: string]: (...args: any[]) => any } = typeof myCallbacks, Callback extends (...args: any[]) => any = Callbacks[CallbackName], >(callbackName: CallbackName, ...args: ArgsN): ReturnType { return (myCallbacks as { [k: string]: Function })[callbackName as any](...args); } call('foo', 1, 2); } function staticAssertArgsNum() { function foo(a: number, b: string): number { return 0; } function boo(a: number, b: string, c: boolean): string { return '0'; } const fooI: ArgsNum = 2; const booI: ArgsNum = 3; } function staticAssertArgI() { function boo(a: number, b: string, c: boolean): string { return '0'; } const a: ArgI = 123; const b: ArgI = '123'; const c: ArgI = false; } function ctorArgs() { class A { constructor( public x: number, public y: string, public z: boolean, ) {} } const _: CtorArgs = [ 0, '0', false ]; }