[英]Typescript: Infer exact values from dynamically created object
Is there a way to infer the exact values from an object thats dynamically created with a helper function. 有没有办法从使用辅助函数动态创建的对象推断出确切的值。
The values of the object will always be inferred as type string, but I would like to have their exact value, like my attempt at casting on the SIGN_IN declaration. 对象的值将始终作为类型字符串推断,但我希望得到它们的确切值,就像我尝试在SIGN_IN声明上进行转换一样。
const createAsyncActionTypes = (label: string) => ({
REQUEST: `${label}_${'SUCCESS'}`,
SUCCESS: `${label}_${'SUCCESS'}`,
ERROR: `${label}_${'ERROR'}`,
CANCELLED: `${label}_${'CANCELLED'}`,
});
const SIGN_OUT = createAsyncActionTypes('SIGN_OUT');
const SIGN_IN: {
REQUEST: 'SIGN_IN_REQUEST';
SUCCESS: 'SIGN_IN_SUCCESS';
ERROR: 'SIGN_IN_ERROR';
CANCELLED: 'SIGN_IN_CANCELLED';
} = createAsyncActionTypes('SIGN_IN');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.