问题描述
我需要创建一个对象,并且一旦创建就不需要引用。我有以下代码:
const myPieChart = new Chart(context,{
type: "pie",data: dataSource
});
但是我收到警告'myPieChart' is declared but its value is never read.ts(6133)
,SolarLint说Remove this useless assignment to variable "myPieChart".sonarlint(typescript:S1854)
如果我改用此代码:
new Chart(context,data: dataSource
});
TSLint抱怨:unused expression,expected an assignment or function call (no-unused-expression)tslint(1)
解决方法
function main(){
return new Chart(context,{
type: "pie",data: dataSource
});
}
main();
或
export const myPieChart = new Chart(context,data: dataSource
});