Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Allow const assertions in no-object-literal-type-assertion #4681

Merged
merged 4 commits into from May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -73,7 +73,7 @@
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",
"typescript": "~3.1.6",
"typescript": "~3.4.0",
"yarn-deduplicate": "^1.1.1"
},
"engines": {
Expand Down
7 changes: 7 additions & 0 deletions src/rules/noObjectLiteralTypeAssertionRule.ts
Expand Up @@ -86,6 +86,13 @@ function walk(ctx: Lint.WalkContext<Options>): void {
if (
isAssertionExpression(node) &&
node.type.kind !== ts.SyntaxKind.AnyKeyword &&
// Allow const assertions, introduced in TS 3.4
!(
node.type.kind === ts.SyntaxKind.TypeReference &&
(ts.isConstTypeReference !== undefined
? ts.isConstTypeReference(node.type)
: node.type.getText(ctx.sourceFile) === "const")
asmundg marked this conversation as resolved.
Show resolved Hide resolved
) &&
// Compare with UnknownKeyword if using TS 3.0 or above
(!!(ts.SyntaxKind as any).UnknownKeyword
? node.type.kind !== (ts.SyntaxKind as any).UnknownKeyword
Expand Down
Expand Up @@ -16,6 +16,10 @@ x as T;
{} as unknown;
<unknown> {};

// Allow const assertion
({}) as const;
<const> ({});
asmundg marked this conversation as resolved.
Show resolved Hide resolved

foo({} as T);
~~~~~~~ [0]

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -1851,10 +1851,10 @@ type-detect@^1.0.0:
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"
integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI=

typescript@~3.1.6:
version "3.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6.tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68"
integrity sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==
typescript@~3.4.0:
version "3.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==

uglify-js@^3.1.4:
version "3.5.4"
Expand Down