Disallow assigning a value with type any to variables and properties.
This rule applies only to .ts files.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-unsafe-assignment": "error"
}
} let [x] = ['1']; [x] = ['1'] as [string]; console.info([x].toString()); // generic position examples export const a1: Set<string> = new Set<string>(); export const a2: Map<string, string> = new Map<string, string>(); export const a3: Set<string[]> = new Set<string[]>(); export const a4: Set<Set<Set<string>>> = new Set<Set<Set<string>>>();
let [x] = ['1']; [x] = ['1'] as [any]; [x] = '1' as any; console.info([x].toString()); // generic position examples export const a1: Set<string> = new Set<any>(); export const a2: Map<string, string> = new Map<any, string>(); export const a3: Set<string[]> = new Set<any[]>(); export const a4: Set<Set<Set<string>>> = new Set<Set<Set<any>>>();
plugin:@typescript-eslint/recommended plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.