admin管理员组文章数量:1435534
Object.keys() as const
not working. How can I achieve this? (Suppose I don't know the content of the object, I don't know what keys does my object have)
const values = Object.keys(myObject) as const;
I need the as const
to get string literal types
let name: typeof values[number];
Object.keys() as const
not working. How can I achieve this? (Suppose I don't know the content of the object, I don't know what keys does my object have)
const values = Object.keys(myObject) as const;
I need the as const
to get string literal types
let name: typeof values[number];
Share
Improve this question
asked Jan 20, 2021 at 17:20
Bruno PintosBruno Pintos
4811 gold badge5 silver badges15 bronze badges
1
|
1 Answer
Reset to default 16You can do
let name: keyof typeof myObject
See this question for why strongly typing Object.keys
might be a bad idea.
本文标签:
版权声明:本文标题:javascript - A 'const' assertions can only be applied to references to enum members, or string, number, boolean, 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739336257a2158720.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
as ...
it should know what that is automatically. – Get Off My Lawn Commented Jan 20, 2021 at 17:26