const json: {} | null | undefined = JSON.parse(queryData);
{
"defaultSeverity": "error",
"extends": [
"tslint:all"
],
"rules": {
}
}
Unsafe use of expression of type 'any'.
I can do const json: any = JSON.parse(queryData); but i want to keep the no-any rules
How can i get the return of JSON.parse without get Unsafe use of expression of type 'any'.
I'm really not sure what you're expecting here... You want to use any, but want to keep the no-any rule? That completely contradicts each other. What prevents you from just declaring the matching type for your query data and then just do const json: YourType = JSON.parse(queryData);?
Thanks for reply. I was not clear
My goal is to keep the no-any rules and i search a way to get the result of JSON.parse(queryData) without warning.
Fo now i do json: any = JSON.parse(queryData); => but i have to disable the no-any.
If i do your solution : const json: YourType = JSON.parse(queryData);
I will have then have to disable the no-unsafe-any rules.
This i why in my first approach i try the : const json: {} | null | undefined = JSON.parse(queryData); Looking on the doc https://palantir.github.io/tslint/rules/no-unsafe-any/ => i will not have the no-unsafe-any and the no any warning.
But JSON.parse can also return other type like string so this solution is not the one.
I actually not certain that there is a solution but before prefere to ask you guys specialist.
@ohrrkan your use case is a good one - normally what folks do is JSON.parse(queryData) as MyType. Closing this as non-actionable for now, since there hasn't been much demand for any action on TSLint's part. Hope that helps!