1:HL["/_next/static/css/275839517c59c532.css",{"as":"style"}] 2:HL["/_next/static/css/bdb880d990e879b6.css",{"as":"style"}] 0:[[["",{"children":["post",{"children":[["slug","get-constructor-type-from-class-in-typescript","d"],{"children":["__PAGE__?{\"slug\":\"get-constructor-type-from-class-in-typescript\"}",{}]}]}]},"$undefined","$undefined",true],"$L3",[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/275839517c59c532.css","precedence":"next"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/bdb880d990e879b6.css","precedence":"next"}]],["$L4",null]]]] 5:HL["/_next/static/css/95c7fb627fba8423.css",{"as":"style"}] 6:HL["/_next/static/css/477df780fc5cb593.css",{"as":"style"}] 7:HL["/_next/static/css/c40a92e7f996f910.css",{"as":"style"}] 3:["$L8",null] 4:[["$","meta","0",{"charSet":"utf-8"}],["$","title","1",{"children":"在 TypeScript 中获取 constructor 类型"}],["$","meta","2",{"name":"description","content":"在 TypeScript 中获取 constructor 类型"}],["$","link","3",{"rel":"manifest","href":"/manifest.json"}],["$","meta","4",{"name":"generator","content":"Hexo.js & Next.js"}],["$","meta","5",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","6",{"property":"og:title","content":"在 TypeScript 中获取 constructor 类型"}],["$","meta","7",{"property":"og:description","content":"在 TypeScript 中获取 constructor 类型"}],["$","meta","8",{"name":"twitter:card","content":"summary"}],["$","meta","9",{"name":"twitter:title","content":"在 TypeScript 中获取 constructor 类型"}],["$","meta","10",{"name":"twitter:description","content":"在 TypeScript 中获取 constructor 类型"}]] 9:I{"id":"7477","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","859:static/chunks/859-ea023633456a13f8.js","355:static/chunks/app/tags/[slug]/page-257dc97429efd72a.js"],"name":"","async":false} a:I{"id":"92","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"","async":false} b:I{"id":"2449","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"","async":false} c:I{"id":"3211","chunks":["272:static/chunks/webpack-7471fa70de6bdb29.js","253:static/chunks/bce60fc1-2413e66000a5dd8f.js","769:static/chunks/769-2bf088c0a421e73d.js"],"name":"","async":false} d:I{"id":"5767","chunks":["272:static/chunks/webpack-7471fa70de6bdb29.js","253:static/chunks/bce60fc1-2413e66000a5dd8f.js","769:static/chunks/769-2bf088c0a421e73d.js"],"name":"","async":false} f:I{"id":"6424","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"GaLite","async":false} 10:I{"id":"9869","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"SpeedInsights","async":false} 11:I{"id":"7148","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"Analytics","async":false} 8:["$","html",null,{"lang":"zh-CN","children":[["$","link",null,{"rel":"icon","href":"/images/icons/icon-72x72.png","type":"image/x-icon"}],["$","link",null,{"rel":"preconnect","href":"https://vip2.loli.io"}],["$","link",null,{"rel":"dns-prefetch","href":"https://vip2.loli.io"}],["$","link",null,{"rel":"alternate","type":"application/atom+xml","href":"/atom.xml"}],["$","body",null,{"children":["$","div",null,{"className":"kbCXHY jdraHW eqrBPF kEFtPS bNzOWQ juexza kXMrYr ","children":[["$","header",null,{"className":"doNOqr WhAZY cRUUAa cwMEsi dpJmjl bsTuZj iRietU JCsMI fONtwf eEsPgn gWUoqV kazZiE fsKTUV dkPCxO gdGTeM ","children":[["$","div",null,{"className":"doNOqr WhAZY hrtgtE iYRJzs iJGxaV jlwzhw ","children":[["$","$L9",null,{"className":"icyDkI gSBWlu foGVKH IVbXa kooHYa JxWnH cVJMrm hyoqRt jlijat kUpitc gdtkYW iDPWLw kayxZK hCkclF cneMsd gYPNzh ","href":"/","children":[["$","div",null,{"className":"eSltVp cpOcAb caItCN cyerGB dSxtaa lbEyiT kUPESX Pmecg ldtSOY ","children":["$","$La",null,{"src":"https://vip2.loli.io/2023/03/09/2tAMcy694lE3IZX.jpg","blurDataURL":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAW0lEQVR4nAFQAK//AAAAAA0MCD08JoiyXkqWNQBPSDHtwYf/86ehuWNAeS4Aep9O+bt9/9aWxbtzETMSAClqHld9MqambcuqdgMOAwBCaS1Mdzd/hFE4PCMEEAS4ex049PWXOAAAAABJRU5ErkJggg==","alt":"avatar","width":200,"height":200,"layout":"responsive","className":"jWjrEQ eKtERL BRobm iovjFN ","placeholder":"blur","priority":true}]}],["$","h1",null,{"className":"evYdWj cpOcAb XEVlt huiurs ","children":"fengkx's Blog"}]]}],["$","h2",null,{"id":"name","className":"hrtgtE fcXWHl ","children":"fengkx"}],["$","h3",null,{"id":"title","className":"hrtgtE fcXWHl ","children":"Student & Coder"}],["$","div",null,{"className":"fONtwf fcXWHl foGVKH IVbXa dPVLzs fkrGAA cvCecb jJGIjV ","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"d":"M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z","children":"$undefined"}],["$","circle","1",{"cx":"12","cy":"10","r":"3","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"gUpJEt ","children":"Guangzhou, China"}]]}],["$","nav",null,{"className":"hrtgtE jlwzhw gSBWlu IVbXa kKRHCo jzaqKj ehqwGF ","children":[["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z","children":"$undefined"}],["$","polyline","1",{"points":"9 22 9 12 15 12 15 22","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"首页"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/archives","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","polyline","0",{"points":"21 8 21 21 3 21 3 8","children":"$undefined"}],["$","rect","1",{"x":"1","y":"3","width":"22","height":"5","children":"$undefined"}],["$","line","2",{"x1":"10","y1":"12","x2":"14","y2":"12","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"归档"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/tags","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z","children":"$undefined"}],["$","line","1",{"x1":"7","y1":"7","x2":"7.01","y2":"7","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"标签"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/links","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2","children":"$undefined"}],["$","circle","1",{"cx":"9","cy":"7","r":"4","children":"$undefined"}],["$","path","2",{"d":"M23 21v-2a4 4 0 0 0-3-3.87","children":"$undefined"}],["$","path","3",{"d":"M16 3.13a4 4 0 0 1 0 7.75","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"友链"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/about","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M18 8h1a4 4 0 0 1 0 8h-1","children":"$undefined"}],["$","path","1",{"d":"M2 8h16v9a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V8z","children":"$undefined"}],["$","line","2",{"x1":"6","y1":"1","x2":"6","y2":"4","children":"$undefined"}],["$","line","3",{"x1":"10","y1":"1","x2":"10","y2":"4","children":"$undefined"}],["$","line","4",{"x1":"14","y1":"1","x2":"14","y2":"4","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"关于"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/search","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"cpOcAb gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","circle","0",{"cx":"11","cy":"11","r":"8","children":"$undefined"}],["$","line","1",{"x1":"21","y1":"21","x2":"16.65","y2":"16.65","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"jJhMtm fcXWHl ","children":"搜索"}]]}]}],["$","div",null,{"className":"kooHYa evYdWj ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/atom.xml","prefetch":false,"children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"cpOcAb gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M4 11a9 9 0 0 1 9 9","children":"$undefined"}],["$","path","1",{"d":"M4 4a16 16 0 0 1 16 16","children":"$undefined"}],["$","circle","2",{"cx":"5","cy":"19","r":"1","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"jJhMtm fcXWHl ","children":"RSS"}]]}]}]]}]]}],["$","div",null,{"className":"doNOqr hrtgtE fcXWHl iigETV bMSzLf XEVlt jmezSN izetJs kdrTtD bLIxaN ","children":[["$","div",null,{"className":"iLYBKc gSBWlu zEGrF evYWGf hDdCaA ","children":[["$","$L9",null,{"title":"fengkx's GitHub","href":"https://github.com/fengkx","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"d":"M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}],["$","$L9",null,{"title":"fengkx's Telegram","href":"https://t.me/fengkx","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","line","0",{"x1":"22","y1":"2","x2":"11","y2":"13","children":"$undefined"}],["$","polygon","1",{"points":"22 2 15 22 11 13 2 9 22 2","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}],["$","$L9",null,{"href":"https://mstdn.social/@fengkx","rel":"me","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"stroke":"none","d":"M0 0h24v24H0z","fill":"none","children":"$undefined"}],["$","path","1",{"d":"M18.648 15.254c-1.816 1.763 -6.648 1.626 -6.648 1.626a18.262 18.262 0 0 1 -3.288 -.256c1.127 1.985 4.12 2.81 8.982 2.475c-1.945 2.013 -13.598 5.257 -13.668 -7.636l-.026 -1.154c0 -3.036 .023 -4.115 1.352 -5.633c1.671 -1.91 6.648 -1.666 6.648 -1.666s4.977 -.243 6.648 1.667c1.329 1.518 1.352 2.597 1.352 5.633s-.456 4.074 -1.352 4.944z","children":"$undefined"}],["$","path","2",{"d":"M12 11.204v-2.926c0 -1.258 -.895 -2.278 -2 -2.278s-2 1.02 -2 2.278v4.722m4 -4.722c0 -1.258 .895 -2.278 2 -2.278s2 1.02 2 2.278v4.722","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}],["$","$L9",null,{"title":"RSS feed","href":"/atom.xml","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"d":"M4 11a9 9 0 0 1 9 9","children":"$undefined"}],["$","path","1",{"d":"M4 4a16 16 0 0 1 16 16","children":"$undefined"}],["$","circle","2",{"cx":"5","cy":"19","r":"1","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}]]}],["$","div",null,{"className":"hrtgtE fcXWHl cyerGB kKRHCo ","children":["Build with ",["$","$L9",null,{"title":"Hexo official site","rel":"noopener noreferrer external nofollow","href":"https://hexo.io","children":"Hexo"}]," ","and"," ",["$","$L9",null,{"title":"Next.js official site","href":"https://nextjs.org","rel":"noopener noreferrer external nofollow","children":"Next.js"}]]}]]}]]}],["$","$Lb",null,{"children":["$","$Lc",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"template":["$","$Ld",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$","$Lc",null,{"parallelRouterKey":"children","segmentPath":["children","post","children"],"error":"$undefined","errorStyles":"$undefined","loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"template":["$","$Ld",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$","$Lc",null,{"parallelRouterKey":"children","segmentPath":["children","post","children",["slug","get-constructor-type-from-class-in-typescript","d"],"children"],"error":"$undefined","errorStyles":"$undefined","loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"template":["$","$Ld",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$Le",null],"segment":"__PAGE__?{\"slug\":\"get-constructor-type-from-class-in-typescript\"}"},"styles":[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/275839517c59c532.css","precedence":"next"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/95c7fb627fba8423.css","precedence":"next"}],["$","link","2",{"rel":"stylesheet","href":"/_next/static/css/477df780fc5cb593.css","precedence":"next"}],["$","link","3",{"rel":"stylesheet","href":"/_next/static/css/c40a92e7f996f910.css","precedence":"next"}]]}],"segment":["slug","get-constructor-type-from-class-in-typescript","d"]},"styles":[]}],"segment":"post"},"styles":[]}]}],["$","$Lf",null,{"uaId":"UA-103237573-1"}],["$","$L10",null,{}],["$","$L11",null,{}]]}]}]]}] 13:I{"id":"5307","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"TocTitle","async":false} e:[false,["$","main",null,{"className":"prose eUUCKp kTeytq jmezSN cjScYX eqrBPF jdraHW cRUUAa DOWJl hgvoZN iZwowi jGHqUK kwISoH AsNjI","children":[["$","h1",null,{"className":"EKhXX ","children":"在 TypeScript 中获取 constructor 类型"}],"$L12"]}],["$","aside",null,{"className":"cwMEsi dpJmjl gWUoqV kazZiE fsKTUV dkPCxO fcXWHl hrtgtE icKiSN eeREmo fZMRmg hRjOno ","children":["$","div",null,{"className":"doNOqr gepZXl AsideContainer_asideContainer___FNWl","children":["$","div",null,{"className":"bKqOie lkcNSa doNOqr dNtEOi ","children":[["$","div",null,{"className":"hlBtvm ckBWJI XEVlt ","children":"文章目录"}],["$","div",null,{"className":"$undefined","children":["$","ol",null,{"className":"jOeduE ","children":[["$","li",null,{"children":[["$","$L13",null,{"id":"TL-DR","text":"TL;DR"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"typeof","text":"typeof?"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"infer-实现","text":"infer 实现"}],false]}]]}]}]]}]}]}]] 14:I{"id":"4998","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"ArticleContentClient","async":false} 15:I{"id":"7974","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"H2","async":false} 18:I{"id":"7974","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"H1","async":false} 12:["$","$L14",null,{"permalink":"https://www.fengkx.top/post/get-constructor-type-from-class-in-typescript/","dateString":"2023-06-16","comments":true,"aplayer":false,"showCopyright":true,"children":[["$","$L15","410",{"id":"TL-DR","children":["TL;DR"]}],"\n",["$","pre","447",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","446",{"className":"language-typescript","children":[["$","span","430",{"className":"line","children":[["$","span","411",{"style":{"color":"#D73A49"},"children":["export"]}],["$","span","412",{"style":{"color":"#D73A49"},"children":[" type"]}],["$","span","413",{"style":{"color":"#6F42C1"},"children":[" ConstructorType"]}],["$","span","414",{"style":{"color":"#24292E"},"children":["<"]}],["$","span","415",{"style":{"color":"#6F42C1"},"children":["C"]}],["$","span","416",{"style":{"color":"#D73A49"},"children":[" extends"]}],["$","span","417",{"style":{"color":"#D73A49"},"children":[" abstract"]}],["$","span","418",{"style":{"color":"#D73A49"},"children":[" new"]}],["$","span","419",{"style":{"color":"#24292E"},"children":[" ("]}],["$","span","420",{"style":{"color":"#D73A49"},"children":["..."]}],["$","span","421",{"style":{"color":"#E36209"},"children":["args"]}],["$","span","422",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","423",{"style":{"color":"#005CC5"},"children":[" any"]}],["$","span","424",{"style":{"color":"#24292E"},"children":[") "]}],["$","span","425",{"style":{"color":"#D73A49"},"children":["=>"]}],["$","span","426",{"style":{"color":"#005CC5"},"children":[" any"]}],["$","span","427",{"style":{"color":"#24292E"},"children":["> "]}],["$","span","428",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","429",{"style":{"color":"#24292E"},"children":[" ("]}]]}],"\n",["$","span","438",{"className":"line","children":[["$","span","431",{"style":{"color":"#D73A49"},"children":[" ..."]}],["$","span","432",{"style":{"color":"#E36209"},"children":["args"]}],["$","span","433",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","434",{"style":{"color":"#6F42C1"},"children":[" ConstructorParameters"]}],["$","span","435",{"style":{"color":"#24292E"},"children":["<"]}],["$","span","436",{"style":{"color":"#6F42C1"},"children":["C"]}],["$","span","437",{"style":{"color":"#24292E"},"children":[">"]}]]}],"\n",["$","span","445",{"className":"line","children":[["$","span","439",{"style":{"color":"#24292E"},"children":[") "]}],["$","span","440",{"style":{"color":"#D73A49"},"children":["=>"]}],["$","span","441",{"style":{"color":"#6F42C1"},"children":[" InstanceType"]}],["$","span","442",{"style":{"color":"#24292E"},"children":["<"]}],["$","span","443",{"style":{"color":"#6F42C1"},"children":["C"]}],["$","span","444",{"style":{"color":"#24292E"},"children":[">;"]}]]}]]}]]}],"\n",["$","$L15","448",{"id":"typeof","children":["typeof?"]}],"\n",["$","p","450",{"children":["由于 JavaScript 的 class 无法很好 tree shaking,加上函数写起来非常方便,所以平时很少用 class。但最近开始折腾 ","$L16",",它基本上是跟 python 版本一一对应的,所以写得很向对象也大量用了 class。我想写一个工厂函数传入一些默认参数,却发现拿不到准确的 constructor 的类型。在 tg 群友的指点下搞懂了这里问题,关键就在于区分实例类型和 constructor 的类型。"]}],"\n",["$","pre","488",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","487",{"className":"language-typescript","children":[["$","span","456",{"className":"line","children":[["$","span","451",{"style":{"color":"#D73A49"},"children":["import"]}],["$","span","452",{"style":{"color":"#24292E"},"children":[" { OpenAI } "]}],["$","span","453",{"style":{"color":"#D73A49"},"children":["from"]}],["$","span","454",{"style":{"color":"#032F62"},"children":[" \"langchain/llms/openai\""]}],["$","span","455",{"style":{"color":"#24292E"},"children":[";"]}]]}],"\n",["$","span","457",{"className":"line","children":[]}],"\n",["$","span","473",{"className":"line","children":[["$","span","458",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","459",{"style":{"color":"#6F42C1"},"children":[" createOpenAI"]}],["$","span","460",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","461",{"style":{"color":"#6F42C1"},"children":[" OpenAI"]}],["$","span","462",{"style":{"color":"#24292E"},"children":["["]}],["$","span","463",{"style":{"color":"#032F62"},"children":["\"constructor\""]}],["$","span","464",{"style":{"color":"#24292E"},"children":["] "]}],["$","span","465",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","466",{"style":{"color":"#24292E"},"children":[" ("]}],["$","span","467",{"style":{"color":"#E36209"},"children":["options"]}],["$","span","468",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","469",{"style":{"color":"#E36209"},"children":["config"]}],["$","span","470",{"style":{"color":"#24292E"},"children":[") "]}],["$","span","471",{"style":{"color":"#D73A49"},"children":["=>"]}],["$","span","472",{"style":{"color":"#24292E"},"children":[" {"]}]]}],"\n",["$","span","475",{"className":"line","children":[["$","span","474",{"style":{"color":"#6A737D"},"children":[" // ^? Function"]}]]}],"\n",["$","span","484",{"className":"line","children":[["$","span","476",{"style":{"color":"#D73A49"},"children":[" return"]}],["$","span","477",{"style":{"color":"#D73A49"},"children":[" new"]}],["$","span","478",{"style":{"color":"#6F42C1"},"children":[" OpenAI"]}],["$","span","479",{"style":{"color":"#24292E"},"children":["({ temperature: "]}],["$","span","480",{"style":{"color":"#005CC5"},"children":["0"]}],["$","span","481",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","482",{"style":{"color":"#D73A49"},"children":["..."]}],["$","span","483",{"style":{"color":"#24292E"},"children":["options }, config);"]}]]}],"\n",["$","span","486",{"className":"line","children":[["$","span","485",{"style":{"color":"#24292E"},"children":["};"]}]]}]]}]]}],"\n",["$","p","489",{"children":["这个问题可以简化成下面的代码:"]}],"\n",["$","pre","528",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","527",{"className":"language-typescript","children":[["$","span","493",{"className":"line","children":[["$","span","490",{"style":{"color":"#D73A49"},"children":["class"]}],["$","span","491",{"style":{"color":"#6F42C1"},"children":[" Foo"]}],["$","span","492",{"style":{"color":"#24292E"},"children":[" {"]}]]}],"\n",["$","span","500",{"className":"line","children":[["$","span","494",{"style":{"color":"#D73A49"},"children":[" constructor"]}],["$","span","495",{"style":{"color":"#24292E"},"children":["("]}],["$","span","496",{"style":{"color":"#E36209"},"children":["foo"]}],["$","span","497",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","498",{"style":{"color":"#005CC5"},"children":[" string"]}],["$","span","499",{"style":{"color":"#24292E"},"children":[") {}"]}]]}],"\n",["$","span","502",{"className":"line","children":[["$","span","501",{"style":{"color":"#24292E"},"children":["}"]}]]}],"\n",["$","span","503",{"className":"line","children":[]}],"\n",["$","span","509",{"className":"line","children":[["$","span","504",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","505",{"style":{"color":"#6F42C1"},"children":[" A"]}],["$","span","506",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","507",{"style":{"color":"#6F42C1"},"children":[" Foo"]}],["$","span","508",{"style":{"color":"#24292E"},"children":[";"]}]]}],"\n",["$","span","515",{"className":"line","children":[["$","span","510",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","511",{"style":{"color":"#6F42C1"},"children":[" B"]}],["$","span","512",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","513",{"style":{"color":"#D73A49"},"children":[" typeof"]}],["$","span","514",{"style":{"color":"#24292E"},"children":[" Foo;"]}]]}],"\n",["$","span","516",{"className":"line","children":[]}],"\n",["$","span","524",{"className":"line","children":[["$","span","517",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","518",{"style":{"color":"#6F42C1"},"children":[" C"]}],["$","span","519",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","520",{"style":{"color":"#6F42C1"},"children":[" A"]}],["$","span","521",{"style":{"color":"#24292E"},"children":["["]}],["$","span","522",{"style":{"color":"#032F62"},"children":["\"constructor\""]}],["$","span","523",{"style":{"color":"#24292E"},"children":["];"]}]]}],"\n",["$","span","526",{"className":"line","children":[["$","span","525",{"style":{"color":"#6A737D"},"children":["// ^? type C = Function"]}]]}]]}]]}],"\n",["$","p","532",{"children":["如何从",["$","code","529",{"children":["Foo"]}],"通过类型运算获取到",["$","code","530",{"children":["(name: string) => Foo"]}],"这样的类型,而不是像上面一样拿到的是个",["$","code","531",{"children":["Function"]}],"。"]}],"\n",["$","p","537",{"children":["在 TypeScript 中",["$","code","533",{"children":["typeof"]}],"除了运行态的语义外,还可以将 Value 转成 Type 用做类型运算。例如",["$","code","534",{"children":["const a: typeof 123 = 456"]}],"。但上面这个",["$","code","535",{"children":["A"]}],"跟",["$","code","536",{"children":["B"]}],"通过 alias 拿到的都是类型却很不一样。"]}],"\n",["$","p","539",{"children":[["$","strong","538",{"children":["A 是实例化后的 instanceType,而 B 是构造器 constructor 的 type"]}]]}],"\n",["$","p","544",{"children":["在运行态 JavaScript 中实例原型链上的 constructor 字段引用指向",["$","code","540",{"children":["Foo"]}],",所以",["$","code","541",{"children":["A['constructor']"]}],"会提示",["$","code","542",{"children":["Function"]}],"类型(没有精确的参数类型)。这个 ","$L17"," 在讨论这个行为。"]}],"\n",["$","pre","561",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","560",{"className":"language-javascript","children":[["$","span","553",{"className":"line","children":[["$","span","545",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","546",{"style":{"color":"#005CC5"},"children":[" a"]}],["$","span","547",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","548",{"style":{"color":"#D73A49"},"children":[" new"]}],["$","span","549",{"style":{"color":"#6F42C1"},"children":[" Foo"]}],["$","span","550",{"style":{"color":"#24292E"},"children":["("]}],["$","span","551",{"style":{"color":"#032F62"},"children":["\"a\""]}],["$","span","552",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","559",{"className":"line","children":[["$","span","554",{"style":{"color":"#24292E"},"children":["a."]}],["$","span","555",{"style":{"color":"#005CC5"},"children":["constructor"]}],["$","span","556",{"style":{"color":"#D73A49"},"children":[" ==="]}],["$","span","557",{"style":{"color":"#24292E"},"children":[" Foo; "]}],["$","span","558",{"style":{"color":"#6A737D"},"children":["// true"]}]]}]]}]]}],"\n",["$","p","562",{"children":["再来看下面这个例子:"]}],"\n",["$","pre","634",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","633",{"className":"language-typescript","children":[["$","span","566",{"className":"line","children":[["$","span","563",{"style":{"color":"#D73A49"},"children":["class"]}],["$","span","564",{"style":{"color":"#6F42C1"},"children":[" Foo"]}],["$","span","565",{"style":{"color":"#24292E"},"children":[" {"]}]]}],"\n",["$","span","574",{"className":"line","children":[["$","span","567",{"style":{"color":"#D73A49"},"children":[" constructor"]}],["$","span","568",{"style":{"color":"#24292E"},"children":["("]}],["$","span","569",{"style":{"color":"#D73A49"},"children":["public"]}],["$","span","570",{"style":{"color":"#E36209"},"children":[" bar"]}],["$","span","571",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","572",{"style":{"color":"#005CC5"},"children":[" string"]}],["$","span","573",{"style":{"color":"#24292E"},"children":[") {}"]}]]}],"\n",["$","span","580",{"className":"line","children":[["$","span","575",{"style":{"color":"#D73A49"},"children":[" static"]}],["$","span","576",{"style":{"color":"#E36209"},"children":[" baz"]}],["$","span","577",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","578",{"style":{"color":"#005CC5"},"children":[" 123"]}],["$","span","579",{"style":{"color":"#24292E"},"children":[";"]}]]}],"\n",["$","span","582",{"className":"line","children":[["$","span","581",{"style":{"color":"#24292E"},"children":["}"]}]]}],"\n",["$","span","583",{"className":"line","children":[]}],"\n",["$","span","589",{"className":"line","children":[["$","span","584",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","585",{"style":{"color":"#6F42C1"},"children":[" A"]}],["$","span","586",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","587",{"style":{"color":"#6F42C1"},"children":[" Foo"]}],["$","span","588",{"style":{"color":"#24292E"},"children":[";"]}]]}],"\n",["$","span","595",{"className":"line","children":[["$","span","590",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","591",{"style":{"color":"#6F42C1"},"children":[" B"]}],["$","span","592",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","593",{"style":{"color":"#D73A49"},"children":[" typeof"]}],["$","span","594",{"style":{"color":"#24292E"},"children":[" Foo;"]}]]}],"\n",["$","span","596",{"className":"line","children":[]}],"\n",["$","span","605",{"className":"line","children":[["$","span","597",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","598",{"style":{"color":"#6F42C1"},"children":[" C"]}],["$","span","599",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","600",{"style":{"color":"#6F42C1"},"children":[" A"]}],["$","span","601",{"style":{"color":"#24292E"},"children":["["]}],["$","span","602",{"style":{"color":"#032F62"},"children":["\"bar\""]}],["$","span","603",{"style":{"color":"#24292E"},"children":["]; "]}],["$","span","604",{"style":{"color":"#6A737D"},"children":["// string"]}]]}],"\n",["$","span","614",{"className":"line","children":[["$","span","606",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","607",{"style":{"color":"#6F42C1"},"children":[" D"]}],["$","span","608",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","609",{"style":{"color":"#6F42C1"},"children":[" B"]}],["$","span","610",{"style":{"color":"#24292E"},"children":["["]}],["$","span","611",{"style":{"color":"#032F62"},"children":["\"bar\""]}],["$","span","612",{"style":{"color":"#24292E"},"children":["]; "]}],["$","span","613",{"style":{"color":"#6A737D"},"children":["// Property 'bar' does not exist on type 'typeof Foo'.(2339)"]}]]}],"\n",["$","span","623",{"className":"line","children":[["$","span","615",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","616",{"style":{"color":"#6F42C1"},"children":[" E"]}],["$","span","617",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","618",{"style":{"color":"#6F42C1"},"children":[" A"]}],["$","span","619",{"style":{"color":"#24292E"},"children":["["]}],["$","span","620",{"style":{"color":"#032F62"},"children":["\"baz\""]}],["$","span","621",{"style":{"color":"#24292E"},"children":["]; "]}],["$","span","622",{"style":{"color":"#6A737D"},"children":["// Property 'baz' does not exist on type 'Foo'.(2339)"]}]]}],"\n",["$","span","632",{"className":"line","children":[["$","span","624",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","625",{"style":{"color":"#6F42C1"},"children":[" F"]}],["$","span","626",{"style":{"color":"#D73A49"},"children":[" ="]}],["$","span","627",{"style":{"color":"#6F42C1"},"children":[" B"]}],["$","span","628",{"style":{"color":"#24292E"},"children":["["]}],["$","span","629",{"style":{"color":"#032F62"},"children":["\"baz\""]}],["$","span","630",{"style":{"color":"#24292E"},"children":["]; "]}],["$","span","631",{"style":{"color":"#6A737D"},"children":["// 123"]}]]}]]}]]}],"\n",["$","p","635",{"children":["Foo 中声明了两个 field,其中的 baz 是个 static filed,A 由于是实例化过的所以有 bar 没 baz,而 B 由于是 constructor 所以有 baz,没 bar"]}],"\n",["$","$L18","636",{"id":"infer-实现","children":["infer 实现"]}],"\n",["$","p","640",{"children":["实际上 ","$L19"," 中有提到",["$","em","638",{"children":["constructor signature"]}],",构造函数类型可以写成",["$","code","639",{"children":["new (...args: P) => T"]}]]}],"\n",["$","p","643",{"children":["TL;DR 中的实现可以不借助 ","$L1a"," 而用 infer 实现:","$L1b","。"]}],"\n",["$","pre","680",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","679",{"className":"language-typescript","children":[["$","span","664",{"className":"line","children":[["$","span","644",{"style":{"color":"#D73A49"},"children":["type"]}],["$","span","645",{"style":{"color":"#6F42C1"},"children":[" ConstructorType"]}],["$","span","646",{"style":{"color":"#24292E"},"children":["<"]}],["$","span","647",{"style":{"color":"#6F42C1"},"children":["C"]}],["$","span","648",{"style":{"color":"#24292E"},"children":["> "]}],["$","span","649",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","650",{"style":{"color":"#6F42C1"},"children":[" C"]}],["$","span","651",{"style":{"color":"#D73A49"},"children":[" extends"]}],["$","span","652",{"style":{"color":"#D73A49"},"children":[" abstract"]}],["$","span","653",{"style":{"color":"#D73A49"},"children":[" new"]}],["$","span","654",{"style":{"color":"#24292E"},"children":[" ("]}],["$","span","655",{"style":{"color":"#D73A49"},"children":["..."]}],["$","span","656",{"style":{"color":"#E36209"},"children":["args"]}],["$","span","657",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","658",{"style":{"color":"#D73A49"},"children":[" infer"]}],["$","span","659",{"style":{"color":"#6F42C1"},"children":[" P"]}],["$","span","660",{"style":{"color":"#24292E"},"children":[") "]}],["$","span","661",{"style":{"color":"#D73A49"},"children":["=>"]}],["$","span","662",{"style":{"color":"#D73A49"},"children":[" infer"]}],["$","span","663",{"style":{"color":"#6F42C1"},"children":[" R"]}]]}],"\n",["$","span","674",{"className":"line","children":[["$","span","665",{"style":{"color":"#D73A49"},"children":[" ?"]}],["$","span","666",{"style":{"color":"#24292E"},"children":[" ("]}],["$","span","667",{"style":{"color":"#D73A49"},"children":["..."]}],["$","span","668",{"style":{"color":"#E36209"},"children":["args"]}],["$","span","669",{"style":{"color":"#D73A49"},"children":[":"]}],["$","span","670",{"style":{"color":"#6F42C1"},"children":[" P"]}],["$","span","671",{"style":{"color":"#24292E"},"children":[") "]}],["$","span","672",{"style":{"color":"#D73A49"},"children":["=>"]}],["$","span","673",{"style":{"color":"#6F42C1"},"children":[" R"]}]]}],"\n",["$","span","678",{"className":"line","children":[["$","span","675",{"style":{"color":"#D73A49"},"children":[" :"]}],["$","span","676",{"style":{"color":"#005CC5"},"children":[" never"]}],["$","span","677",{"style":{"color":"#24292E"},"children":[";"]}]]}]]}]]}],"\n"]}] 16:["$","a",null,{"href":"https://github.com/hwchase17/langchainjs","children":["langchainjs"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 17:["$","a",null,{"href":"https://github.com/microsoft/TypeScript/issues/3841","children":["GitHub issue"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 19:["$","a",null,{"href":"https://www.typescriptlang.org/docs/handbook/2/classes.html","children":["TypeScript 文档"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1a:["$","a",null,{"href":"https://www.typescriptlang.org/docs/handbook/utility-types.html","children":["内置的 Utility Types"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1b:["$","a",null,{"href":"https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBDAnmApnA3nAogRwK4CGANgDTYAeqAxvAL5wBmUEIcA5AAJKoC0VAFsSIoAdgHMUAZwD0eGMCKS2AKGVUiBSZLgAxCBAzK4xuFQgjJMKHhrQAFGDwAjIsCpwnBKAC44lqMDiAJQYtEYmlgTy7p4AXr4AjABMAMwA3MphygRO-gQ0phpacABCXoYmpub+NjD2BIkh6GFZ3GgAwtVWtdAAKsgoADztAHxwALxw7XAo5DCiACbaOXkFIigA7nB2AHR7XmKSvoEMKFBwAAoh42MnZ3AASnAA-Nt7OwdHl9djT77rADczqplG04AANCZTLrWWxQfqoQZtCAMUpeEbKaTSEwAPWeqjBAH0oQBtcLGLCUFA0QbkyrYfDEYYwnrwgZIgYo3T6EZkOwNPxWQJiH7ciAYyq8umU6gwWn0ky4QhEQbgvkChKispQCUmKUAXRBQA","children":["Playground"],"target":"_blank","rel":"noopener noreferrer external nofollow"}]