This repository was archived by the owner on Mar 25, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
test/rules/no-object-literal-type-assertion/default Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7373 "tslint-config-prettier" : " ^1.18.0" ,
7474 "tslint-plugin-prettier" : " ^2.0.1" ,
7575 "tslint-test-config-non-relative" : " file:test/external/tslint-test-config-non-relative" ,
76- "typescript" : " ~3.1.6 " ,
76+ "typescript" : " ~3.4.0 " ,
7777 "yarn-deduplicate" : " ^1.1.1"
7878 },
7979 "engines" : {
Original file line number Diff line number Diff line change @@ -48,7 +48,9 @@ export class Rule extends Lint.Rules.AbstractRule {
4848 The type assertion in the latter case is either unnecessary or hides an error.
4949 The compiler will warn for excess properties with this syntax, but not missing required fields.
5050 For example: \`const x: { foo: number } = {}\` will fail to compile, but
51- \`const x = {} as { foo: number }\` will succeed.` ,
51+ \`const x = {} as { foo: number }\` will succeed.
52+ Additionally, the const assertion \`const x = { foo: 1 } as const\`,
53+ introduced in TypeScript 3.4, is considered beneficial and is ignored by this rule.` ,
5254 optionsDescription : Lint . Utils . dedent `
5355 One option may be configured:
5456
@@ -86,6 +88,8 @@ function walk(ctx: Lint.WalkContext<Options>): void {
8688 if (
8789 isAssertionExpression ( node ) &&
8890 node . type . kind !== ts . SyntaxKind . AnyKeyword &&
91+ // Allow const assertions, introduced in TS 3.4
92+ ! ( ts . isConstTypeReference !== undefined && ts . isConstTypeReference ( node . type ) ) &&
8993 // Compare with UnknownKeyword if using TS 3.0 or above
9094 ( ! ! ( ts . SyntaxKind as any ) . UnknownKeyword
9195 ? node . type . kind !== ( ts . SyntaxKind as any ) . UnknownKeyword
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ x as T;
1616{} as unknown;
1717<unknown> {};
1818
19+ #if typescript >= 3.4.0
20+ // Allow const assertion
21+ ({}) as const;
22+ <const> ({});
23+ #endif
24+
1925foo({} as T);
2026 ~~~~~~~ [0]
2127
Original file line number Diff line number Diff line change @@ -1851,10 +1851,10 @@ type-detect@^1.0.0:
18511851 resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"
18521852 integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI=
18531853
1854- typescript@~3.1.6 :
1855- version "3.1.6 "
1856- resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6 .tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68 "
1857- integrity sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA ==
1854+ typescript@~3.4.0 :
1855+ version "3.4.5 "
1856+ resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5 .tgz#2d2618d10bb566572b8d7aad5180d84257d70a99 "
1857+ integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw ==
18581858
18591859uglify-js@^3.1.4 :
18601860 version "3.5.4"
You can’t perform that action at this time.
0 commit comments