报错代码如下
export const cycTest=(value:any,testName:string):boolean=>testObject[testName].test(value);
export const cycTestLabel=<T>(value:any,testName:T,label:T):(boolean|Error)=>{
return !cycTest(value,testName)?new Error(`${label}格式错误`):true
};
报错信息如下
解决办法记录
直接<T extend string>可以直接解决
export const cycTest=(value:any,testName:string):boolean=>testObject[testName].test(value);
export const cycTestLabel=<T extends string>(value:any,testName:T,label:T):(boolean|Error)=>{
return !cycTest(value,testName)?new Error(`${label}格式错误`):true
};
博主的wx公众号:"程序员野区"的菜单栏有福利