This repository was archived by the owner on Mar 25, 2021. It is now read-only.
File tree 4 files changed +16
-6
lines changed
test/rules/no-object-literal-type-assertion/default
4 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 73
73
"tslint-config-prettier" : " ^1.18.0" ,
74
74
"tslint-plugin-prettier" : " ^2.0.1" ,
75
75
"tslint-test-config-non-relative" : " file:test/external/tslint-test-config-non-relative" ,
76
- "typescript" : " ~3.1.6 " ,
76
+ "typescript" : " ~3.4.0 " ,
77
77
"yarn-deduplicate" : " ^1.1.1"
78
78
},
79
79
"engines" : {
Original file line number Diff line number Diff line change @@ -48,7 +48,9 @@ export class Rule extends Lint.Rules.AbstractRule {
48
48
The type assertion in the latter case is either unnecessary or hides an error.
49
49
The compiler will warn for excess properties with this syntax, but not missing required fields.
50
50
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.` ,
52
54
optionsDescription : Lint . Utils . dedent `
53
55
One option may be configured:
54
56
@@ -86,6 +88,8 @@ function walk(ctx: Lint.WalkContext<Options>): void {
86
88
if (
87
89
isAssertionExpression ( node ) &&
88
90
node . type . kind !== ts . SyntaxKind . AnyKeyword &&
91
+ // Allow const assertions, introduced in TS 3.4
92
+ ! ( ts . isConstTypeReference !== undefined && ts . isConstTypeReference ( node . type ) ) &&
89
93
// Compare with UnknownKeyword if using TS 3.0 or above
90
94
( ! ! ( ts . SyntaxKind as any ) . UnknownKeyword
91
95
? 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;
16
16
{} as unknown;
17
17
<unknown> {};
18
18
19
+ #if typescript >= 3.4.0
20
+ // Allow const assertion
21
+ ({}) as const;
22
+ <const> ({});
23
+ #endif
24
+
19
25
foo({} as T);
20
26
~~~~~~~ [0]
21
27
Original file line number Diff line number Diff line change @@ -1851,10 +1851,10 @@ type-detect@^1.0.0:
1851
1851
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"
1852
1852
integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI=
1853
1853
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 ==
1858
1858
1859
1859
uglify-js@^3.1.4 :
1860
1860
version "3.5.4"
You can’t perform that action at this time.
0 commit comments