Skip to content

Commit 2521b85

Browse files
rhysdbradzacher
authored andcommitted
fix(eslint-plugin): no-object-literal-type-assertion: fix as const is reported (#390)
1 parent 6f77ba6 commit 2521b85

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export default util.createRule<Options, MessageIds>({
5050
case AST_NODE_TYPES.TSAnyKeyword:
5151
case AST_NODE_TYPES.TSUnknownKeyword:
5252
return false;
53+
case AST_NODE_TYPES.TSTypeReference:
54+
// Ignore `as const` and `<const>` (#166)
55+
return (
56+
node.typeName.type === AST_NODE_TYPES.Identifier &&
57+
node.typeName.name !== 'const'
58+
);
5359
default:
5460
return true;
5561
}

Diff for: packages/eslint-plugin/tests/rules/no-object-literal-type-assertion.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ ruleTester.run('no-object-literal-type-assertion', rule, {
2626
// Allow cast to 'unknown'
2727
`const foo = {} as unknown;`,
2828
`const foo = <unknown> {};`,
29+
`const foo = {} as const;`,
30+
`const foo = <const> {};`,
2931
{
3032
code: `print({ bar: 5 } as Foo)`,
3133
options: [

0 commit comments

Comments
 (0)