[英]How do I type-check this object in Typescript
I am in a state of confusion on how I would go about type-checking this variable, but I am not able to do it.我对如何对这个变量进行类型检查感到困惑,但我无法做到。
What I understand is that this is an object which contains fields, but these fields are written in a obscure way.我的理解是,这是一个包含字段的 object,但这些字段是以一种晦涩的方式编写的。
The object is called userApproval object 被称为 userApproval
Here is the object when I output it to console.这是 object 当我 output 它到控制台时。
{
l8s.restart_trigger: true, l8s.system_scale: true, manager.cleanup: true,
manager.extend: true
}
Now this is the type I am attempting to type to,现在这是我尝试输入的类型,
export type UserApproval = {
MANAGER_CLEANUP: boolean;
MANAGER_EXTEND: boolean;
L8S_SYSTEM_SCALE: boolean;
L8S_RESTART_TRIGGER: boolean;
};
Is this correct这个对吗
I think the keys of your object are example.test
so based on that try this types.我认为您的 object 的键是
example.test
因此基于此尝试此类型。
type ApprovalTypes = {
'l8s.restart_trigger': boolean;
'l8s.system_scale': boolean;
'manager.cleanup': boolean;
'manager.extend': boolean;
}
const data:ApprovalTypes = {
'l8s.restart_trigger': true,
'l8s.system_scale': true,
'manager.cleanup': true,
'manager.extend': true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.