Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-type-alias] handle Template Literal Types#5092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 2 commits intotypescript-eslint:mainfroma-tarasyuk:fix/5043
May 29, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletionspackages/eslint-plugin/docs/rules/no-type-alias.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,6 +118,8 @@ type Foo = string | string[];

type Foo = string & string[];

type Foo = `foo-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand All@@ -139,6 +141,8 @@ type Foo = string;

type Foo = string & string[];

type Foo = `foo-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand All@@ -156,6 +160,8 @@ type Foo = 'a' | 'b';

type Foo = string | string[];

type Foo = `a-${number}` | `b-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand All@@ -175,6 +181,8 @@ type Foo = string;

type Foo = string | string[];

type Foo = `a-${number}` | `b-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand All@@ -190,6 +198,8 @@ Examples of **correct** code for the `{ "allowAliases": "in-intersections" }` op
// primitives
type Foo = string & string[];

type Foo = `a-${number}` & `b-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand All@@ -205,6 +215,8 @@ type Foo = 'a';

type Foo = string;

type Foo = `foo-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand All@@ -222,6 +234,10 @@ type Foo = string | string[];

type Foo = string & string[];

type Foo = `a-${number}` & `b-${number}`;

type Foo = `a-${number}` | `b-${number}`;

// reference types
interface Bar {}
class Baz implements Bar {}
Expand Down
1 change: 1 addition & 0 deletionspackages/eslint-plugin/src/rules/no-type-alias.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -133,6 +133,7 @@ export default util.createRule<Options, MessageIds>({
AST_NODE_TYPES.TSLiteralType,
AST_NODE_TYPES.TSTypeQuery,
AST_NODE_TYPES.TSIndexedAccessType,
AST_NODE_TYPES.TSTemplateLiteralType,
]);

/**
Expand Down
121 changes: 121 additions & 0 deletionspackages/eslint-plugin/tests/rules/no-type-alias.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,6 +131,66 @@ ruleTester.run('no-type-alias', rule, {
code: 'type Foo = 1 | (2 & 3);',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = `a-${number}`;',
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = `a-${number}` | `b-${number}`;',
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = `a-${number}` | `b-${number}`;',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = `a-${number}` | `b-${number}`;',
options: [{ allowAliases: 'in-unions' }],
},
{
code: 'type Foo = `a-${number}` | `b-${number}` | `c-${number}`;',
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = `a-${number}` | `b-${number}` | `c-${number}`;',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = `a-${number}` | `b-${number}` | `c-${number}`;',
options: [{ allowAliases: 'in-unions' }],
},
{
code: 'type Foo = `a-${number}` & `b-${number}`;',
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = `a-${number}` & `b-${number}`;',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = `a-${number}` & `b-${number}`;',
options: [{ allowAliases: 'in-intersections' }],
},
{
code: 'type Foo = `a-${number}` & `b-${number}` & `c-${number}`;',
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = `a-${number}` & `b-${number}` & `c-${number}`;',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = `a-${number}` & `b-${number}` & `c-${number}`;',
options: [{ allowAliases: 'in-intersections' }],
},
{
code: 'type Foo = `a-${number}` | (`b-${number}` & `c-${number}`);',
options: [{ allowAliases: 'always' }],
},
{
code: 'type Foo = `a-${number}` | (`b-${number}` & `c-${number}`);',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = true;',
options: [{ allowAliases: 'always' }],
Expand DownExpand Up@@ -3340,5 +3400,66 @@ type Foo<T> = {
},
],
},
{
code: 'type Foo = `foo-${number}`;',
errors: [
{
messageId: 'noTypeAlias',
data: {
alias: 'aliases',
},
line: 1,
column: 12,
},
],
},
{
code: 'type Foo = `a-${number}` | `b-${number}`;',
options: [{ allowAliases: 'never' }],
errors: [
{
messageId: 'noCompositionAlias',
data: {
typeName: 'Aliases',
compositionType: 'union',
},
line: 1,
column: 12,
},
{
messageId: 'noCompositionAlias',
data: {
typeName: 'Aliases',
compositionType: 'union',
},
line: 1,
column: 28,
},
],
},
{
code: 'type Foo = `a-${number}` & `b-${number}`;',
options: [{ allowAliases: 'never' }],
errors: [
{
messageId: 'noCompositionAlias',
data: {
typeName: 'Aliases',
compositionType: 'intersection',
},
line: 1,
column: 12,
},
{
messageId: 'noCompositionAlias',
data: {
typeName: 'Aliases',
compositionType: 'intersection',
},
line: 1,
column: 28,
},
],
},
],
});

[8]ページ先頭

©2009-2025 Movatter.jp