![](/img/trans.png)
[英]Dynamically get the type for the function returned from a function
[英]how can get object type who returned from a function
我想自动输入className,但我不知道如何
const createClassName = (arr:Array<string>) => {
return Object.fromEntries(arr.map((e,i) => {
const first = i === 0 ? '' : `${arr[0]}__`
return [e.replace(/(\b|-)\w/g, function(m) {
if(e[0] === m){
return m
}
return m.toUpperCase().replace(/-/,'');
}),first + e]
}))
}
const clsArr = [
'admin-login-page',
'dashboard',
'form',
'form-container',
'fieldset',
'input-label',
'link',
]
const className = createClassName(clsArr) // how get type?
我试过做这样的事情,但它不起作用
type c = typeof className
const z:c = className
我需要自动完成,当我做这样的事情时 className.blabla 在 className hasnt blabla only [dashboard,from,etc]
像这样的东西
const obj = {
1:1,
2:2
}
type Z = typeof obj
const obj2:Z = obj
obj2.[ `have only`,`1`,`2`]
您是否尝试过ReturnType
实用程序类型?
type c = ReturnType<typeof createClassName>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.