首页 > 其他分享 >[Typescript] Variable assignment - extends infer X

[Typescript] Variable assignment - extends infer X

时间:2022-11-17 15:24:23浏览次数:44  
标签:use Typescript assignment extends Result Variable infer

You can use `extends infer X` to assign the result of an expression to a variable

type SomeFunction<U> = 
    SuperHeavyComputation<U> extends infer Result
    ? [Result, Result, Result]
    : never

 

The trick is to use `infer X` right after the `extends` keyword

标签:use,Typescript,assignment,extends,Result,Variable,infer
From: https://www.cnblogs.com/Answer1215/p/16899579.html

相关文章

  • 自学 TypeScript 第二天 编译选项
    前言:昨天我们学习了TS的数据类型,不知道大家回去以后练习没练习,如果你练习了一定会发现一个问题,我们的TS好像和JS不太一样JS写完之后直接就可以放到页面上,就可以用......
  • NOTE_vanilla+typescript
    E:\song\threejs_learn\vite-project\index.html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><linkrel="icon"type="image/svg+xml"......
  • [Typescript]106. Medium - OnPropChnagedMethods
    typeOnPropChnagedMethods<T>={[KeyinkeyofT&stringas`${Key}Changed`]:(cb:(newValue:T[Key])=>void)=>void}declarefunctionmakeWatchedObject<......
  • [Typescript] 105. Medium - Placeholder
    typePlaceholder<Textendsstring>=Textends`${string}{${inferP}}${inferREST}`?P|Placeholder<REST>:never;declarefunctionformat<Sextendsstr......
  • [Typescript] 103. Hard - Tuple Filter
    Implementatype FilterOut<T,F> thatfiltersoutitemsofthegiventype F fromthetuple T.Forexample,typeFiltered=FilterOut<[1,2,null,3],null......
  • 【转】Typescript: how to convert number to an int8, int16, int32, uint8, uint16,
    转载:Typescript:howtoconvertnumbertoanint8,int16,int32,uint8,uint16,oruint32exportclassCONVERT{staticNumberToUint32(x:number):number......
  • 取消TypeScript的强类型校验
    作用取消TypeScript的强类型校验例在TypeScript导入echarts时,无法识别;报文件“*/utils/lib/ec-canvas/echarts.js”不是模块使用//@ts-ignore解决思路如下//@......
  • TypeScript 使用 echart 小结
    可使用封装好的echarts-for-weixin下载说明引入组件说明导入组件{"usingComponents":{"ec-canvas":"../../ec-canvas/ec-canvas"}}ts/js引入echa......
  • 文件导入 - TypeScript
    require与importrequire:是运行时调用,所以require理论上可以运用在代码的任何地方import:是编译时调用,所以必须放在文件开头-使用require导入index.ts//----------......
  • [Typescript] 102. Hard - String to Number
    Convertastringliteraltoanumber,whichbehaveslike Number.parseInt. /*_____________YourCodeHere_____________*/typeToNumber<Sextendsstring,......