Skip to content

Commit

Permalink
fix(eslint-plugin): no-object-literal-type-assertion: fix as const
Browse files Browse the repository at this point in the history
…is reported (#390)
  • Loading branch information
rhysd authored and bradzacher committed Apr 7, 2019
1 parent 6f77ba6 commit 2521b85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Expand Up @@ -50,6 +50,12 @@ export default util.createRule<Options, MessageIds>({
case AST_NODE_TYPES.TSAnyKeyword:
case AST_NODE_TYPES.TSUnknownKeyword:
return false;
case AST_NODE_TYPES.TSTypeReference:
// Ignore `as const` and `<const>` (#166)
return (
node.typeName.type === AST_NODE_TYPES.Identifier &&
node.typeName.name !== 'const'
);
default:
return true;
}
Expand Down
Expand Up @@ -26,6 +26,8 @@ ruleTester.run('no-object-literal-type-assertion', rule, {
// Allow cast to 'unknown'
`const foo = {} as unknown;`,
`const foo = <unknown> {};`,
`const foo = {} as const;`,
`const foo = <const> {};`,
{
code: `print({ bar: 5 } as Foo)`,
options: [
Expand Down

0 comments on commit 2521b85

Please sign in to comment.