Skip to content

Commit 4cb399a

Browse files
committed
test: add test
1 parent 91dd50d commit 4cb399a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

packages/eslint-plugin/tests/rules/no-unnecessary-type-parameters.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,52 @@ function join(els: (string & number)[]) {
17921792
},
17931793
{
17941794
code: `
1795+
function join<T extends (string & number) | boolean>(els: T[]) {
1796+
return els.map(el => '' + el).join(',');
1797+
}
1798+
`,
1799+
errors: [
1800+
{
1801+
data: { descriptor: 'function', name: 'T', uses: 'used only once' },
1802+
messageId: 'sole',
1803+
suggestions: [
1804+
{
1805+
messageId: 'replaceUsagesWithConstraint',
1806+
output: `
1807+
function join(els: ((string & number) | boolean)[]) {
1808+
return els.map(el => '' + el).join(',');
1809+
}
1810+
`,
1811+
},
1812+
],
1813+
},
1814+
],
1815+
},
1816+
{
1817+
code: noFormat`
1818+
function join<T extends (string | number)>(els: T[]) {
1819+
return els.map(el => '' + el).join(',');
1820+
}
1821+
`,
1822+
errors: [
1823+
{
1824+
data: { descriptor: 'function', name: 'T', uses: 'used only once' },
1825+
messageId: 'sole',
1826+
suggestions: [
1827+
{
1828+
messageId: 'replaceUsagesWithConstraint',
1829+
output: `
1830+
function join(els: (string | number)[]) {
1831+
return els.map(el => '' + el).join(',');
1832+
}
1833+
`,
1834+
},
1835+
],
1836+
},
1837+
],
1838+
},
1839+
{
1840+
code: `
17951841
function join<T extends { hoge: string } | { hoge: number }>(els: T['hoge'][]) {
17961842
return els.map(el => '' + el).join(',');
17971843
}

0 commit comments

Comments
 (0)