You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeFunc=(...args: [...strs: string[],num1: number,num2: number])=>void// OKconstfunc: Func=()=>{}// Error:// Type '(arg1: string | number) => void' is not assignable to type 'Func'.// Types of parameters 'arg1' and 'strs' are incompatible.// Type '[...strs: string[], num1: number, num2: number]' is not assignable to type '[arg1: string | number]'.// Source has 2 element(s) but target allows only 1.constfunc1: Func=(arg1)=>{}// Error:// Type '(arg2: string | number, arg3: string | number) => void' is not assignable to type 'Func'.// Types of parameters 'arg2' and 'strs' are incompatible.// Type '[...strs: string[], num1: number, num2: number]' is not assignable to type '[arg2: string | number, arg3: string | number]'.// Target allows only 2 element(s) but source may have more.constfunc2: Func=(arg2,arg3)=>{};// Error:// Type '(arg4: string | number, arg5: string | number, arg6: string | number) => void' is not assignable to type 'Func'.// Types of parameters 'arg4' and 'strs' are incompatible.// Type '[...strs: string[], num1: number, num2: number]' is not assignable to type '[arg4: string | number, arg5: string | number, arg6: string | number]'.// Target requires 3 element(s) but source may have fewer.constfunc3: Func=(arg4,arg5,arg6)=>{};
🙁 Actual behavior
Functions that have one or more arguments (func1, func2, func3) cannot be assigned to variables of type Func.
🙂 Expected behavior
No compiler errors and the types of arguments are inferred as:
Bug Report
🔎 Search Terms
function rest arguments parameter tuple type leading middle rest elements
🕗 Version & Regression Information
4.2.3, 4.3.5, 4.4.2
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Functions that have one or more arguments (
func1,func2,func3) cannot be assigned to variables of typeFunc.🙂 Expected behavior
No compiler errors and the types of arguments are inferred as:
arg1,arg2,arg3,arg4,arg5:string | numberarg6:string | number | undefined