首页 > 其他分享 >[Typescript] 76. Easy - Parameters

[Typescript] 76. Easy - Parameters

时间:2022-10-29 03:22:14浏览次数:63  
标签:Typescript const _____________ Parameters arg1 arg2 number 76 type

Implement the built-in Parameters generic without using it.

For example:

const foo = (arg1: string, arg2: number): void => {}

type FunctionParamsType = MyParameters<typeof foo> // [arg1: string, arg2: number]
/* _____________ Your Code Here _____________ */

type MyParameters<T extends (...args: any[]) => any> = T extends (...args: infer Args) => any ? Args: [];


/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

const foo = (arg1: string, arg2: number): void => {}
const bar = (arg1: boolean, arg2: { a: 'A' }): void => {}
const baz = (): void => {}

type cases = [
  Expect<Equal<MyParameters<typeof foo>, [string, number]>>,
  Expect<Equal<MyParameters<typeof bar>, [boolean, { a: 'A' }]>>,
  Expect<Equal<MyParameters<typeof baz>, []>>,
]

 

标签:Typescript,const,_____________,Parameters,arg1,arg2,number,76,type
From: https://www.cnblogs.com/Answer1215/p/16837966.html

相关文章

  • P7676 COCI2013-2014#5 TROKUTI
    P7676COCI2013-2014#5TROKUTI-洛谷|计算机科学教育新生态(luogu.com.cn)首先考虑三角形的形成条件(注意到题面保证了无三线共点):三条边;任意两条边不平行。考虑......
  • [Typescript] 74. Medium - LastIndexOf
    Implementthetypeversionof Array.lastIndexOf, LastIndexOf<T,U> takesanArray T,any U andreturnstheindexofthelast U inArray TForexample:......
  • 【761】机器学习特征重要性分析以及特征相关系数热力图
    参考:数据科学|避坑!Python特征重要性分析中存在的问题参考:python特征相关性热力图怎么画_如何在python中绘制热地图(实例)python特征相关性热力图怎么画_如何在python中绘......
  • [Typescript] 72. Medium - IndexOf
    ImplementthetypeversionofArray.indexOf,indexOf<T,U>takesanArrayT,anyUandreturnstheindexofthefirstUinArrayT.typeRes=IndexOf<[1,2,3......
  • [Typescript] 71. Medium - Trunc
    Implementthetypeversionof Math.trunc,whichtakesstringornumberandreturnstheintegerpartofanumberbyremovinganyfractionaldigits.Forexample......
  • TypeScript 复习与进阶三部曲 (2) – 把 TypeScript 当编程语言使用
    前言上一篇,我们提到,TypeScript进阶有3个阶段. 第一阶段是"把TypeScript当强类型语言使用",我们已经介绍完了. 第二阶段是"把TypeScript当编程语言使用"......
  • [Typescript] 70. Medium - Without
    ImplementthetypeversionofLodash.without,Without<T,U>takesanArrayT,numberorarrayUandreturnsanArraywithouttheelementsofU.typeRes=With......
  • leetcode-476-easy
    NumberComplementThecomplementofanintegeristheintegeryougetwhenyouflipallthe0'sto1'sandallthe1'sto0'sinitsbinaryrepresentation.Fo......
  • [Typescript] 69. Medium - Trim Right
    Implement TrimRight<T> whichtakesanexactstringtypeandreturnsanewstringwiththewhitespaceendingremoved.Forexample:typeTrimed=TrimRight<'......
  • [Typescript] 68. Medium - Fill
    Fill,acommonJavaScriptfunction,nowletusimplementitwithtypes. Fill<T,N,Start?,End?>,asyoucansee,Fill acceptsfourtypesofparameters,ofwh......