Navigation Menu

Skip to content

Commit

Permalink
fix(eslint-plugin): [no-type-alias] handle readonly types in aliases (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashenry committed May 11, 2020
1 parent 51ca404 commit 56d9870
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/eslint-plugin/src/rules/no-type-alias.ts
Expand Up @@ -262,7 +262,11 @@ export default util.createRule<Options, MessageIds>({
} else if (
// eslint-disable-next-line @typescript-eslint/internal/prefer-ast-types-enum
type.node.type.endsWith('Keyword') ||
aliasTypes.has(type.node.type)
aliasTypes.has(type.node.type) ||
(type.node.type === AST_NODE_TYPES.TSTypeOperator &&
type.node.operator === 'readonly' &&
type.node.typeAnnotation &&
aliasTypes.has(type.node.typeAnnotation.type))
) {
// alias / keyword
checkAndReport(allowAliases!, isTopLevel, type, 'Aliases');
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/tests/rules/no-type-alias.test.ts
Expand Up @@ -213,6 +213,10 @@ type Foo = Bar & string;
code: 'type Foo = string | string[];',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = string | readonly string[];',
options: [{ allowAliases: 'in-unions-and-intersections' }],
},
{
code: 'type Foo = string | string[];',
options: [{ allowAliases: 'in-unions' }],
Expand Down

0 comments on commit 56d9870

Please sign in to comment.