We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目链接:AppendArgument
实现 AppendArgument,满足下面需求,将第二个参数放到函数参数的最后一位
AppendArgument
import type { Equal, Expect } from "@type-challenges/utils"; type Case1 = AppendArgument<(a: number, b: string) => number, boolean>; type Result1 = (a: number, b: string, x: boolean) => number; type Case2 = AppendArgument<() => void, undefined>; type Result2 = (x: undefined) => void; type cases = [Expect<Equal<Case1, Result1>>, Expect<Equal<Case2, Result2>>];
type AppendArgument<Fn, A> = Fn extends (...args: infer Args) => infer R ? (...args: [...Args, A]) => R : never;
infer Args
args_0
args_1
type AppendArgument<Fn, A> = Fn extends (...args: infer Args) => infer R ? (...args: [...rest: Args, x: A]) => R : never;
解决方法二中,形参不是传入的形参问题。
type AppendArgument<Fn extends (...args: any) => any, A> = ( ...args: [...Parameters<Fn>, A] ) => ReturnType<Fn>;
Parameters
ReturnType
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
题目链接:AppendArgument
实现
AppendArgument
,满足下面需求,将第二个参数放到函数参数的最后一位答案
方法一
知识点
infer Args
获取到参数类型args_0
、args_1
...方法二
知识点
解决方法二中,形参不是传入的形参问题。
方法三
知识点
Parameters
可以获取到函数的参数ReturnType
可以获取到函数的返回值The text was updated successfully, but these errors were encountered: