Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): no-object-literal-type-assertion: fix as const is reported #390

Merged
merged 5 commits into from Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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