Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9bdd07

Browse files
authored
test(eslint-plugin): [no-unsafe-assignment] add missing test cases (typescript-eslint#3070)
1 parent 022fddf commit e9bdd07

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

packages/eslint-plugin/tests/rules/no-unsafe-assignment.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,22 @@ class Foo {
100100
'const x: Set<string> = new Set();',
101101
'const x: Set<string> = new Set<string>();',
102102
'const [x] = [1];',
103+
'const [x, y] = [1, 2] as number[];',
103104
'const [x, ...y] = [1, 2, 3, 4, 5];',
104105
'const [x, ...y] = [1];',
106+
'const [{ ...x }] = [{ x: 1 }] as [{ x: any }];',
105107
'function foo(x = 1) {}',
106108
'function foo([x] = [1]) {}',
107109
'function foo([x, ...y] = [1, 2, 3, 4, 5]) {}',
108110
'function foo([x, ...y] = [1]) {}',
109111
// this is not checked, because there's no annotation to compare it with
110112
'const x = new Set<any>();',
111113
'const x = { y: 1 };',
114+
'const x = { y = 1 };',
115+
'const x = { y(); };',
112116
'const x: { y: number } = { y: 1 };',
113117
'const x = [...[1, 2, 3]];',
118+
'const [{ [`x${1}`]: x }] = [{ [`x`]: 1 }] as [{ [`x`]: any }];',
114119
{
115120
code: `
116121
type Props = { a: string };
@@ -119,15 +124,23 @@ declare function Foo(props: Props): never;
119124
`,
120125
filename: 'react.tsx',
121126
},
122-
`
123-
const x: unknown = y as any;
124-
`,
125-
`
126-
const x: unknown[] = y as any[];
127-
`,
128-
`
129-
const x: Set<unknown> = y as Set<any>;
130-
`,
127+
{
128+
code: `
129+
declare function Foo(props: { a: string }): never;
130+
<Foo a="foo" />;
131+
`,
132+
filename: 'react.tsx',
133+
},
134+
{
135+
code: `
136+
declare function Foo(props: { a: string }): never;
137+
<Foo a={} />;
138+
`,
139+
filename: 'react.tsx',
140+
},
141+
'const x: unknown = y as any;',
142+
'const x: unknown[] = y as any[];',
143+
'const x: Set<unknown> = y as Set<any>;',
131144
],
132145
invalid: [
133146
...batchedSingleLineTests({
@@ -238,6 +251,8 @@ const x: Set<Set<Set<string>>> = new Set<Set<Set<any>>>();
238251
['[[[[x]]]] = [[[[1 as any]]]]', 5, 6],
239252
['[[[[x]]]] = [1 as any]', 2, 9, true],
240253
['[{x}] = [{x: 1}] as [{x: any}]', 3, 4],
254+
['[{["x"]: x}] = [{["x"]: 1}] as [{["x"]: any}]', 10, 11],
255+
['[{[`x`]: x}] = [{[`x`]: 1}] as [{[`x`]: any}]', 10, 11],
241256
]),
242257
{
243258
// TS treats the assignment pattern weirdly in this case

0 commit comments

Comments
 (0)