Skip to content

Commit 0da23e4

Browse files
adidahiyanchen63
authored andcommitted
Wordsmith docs for no-object-literal-type-assertion (palantir#2719)
1 parent 63fc794 commit 0da23e4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/rules/noObjectLiteralTypeAssertionRule.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export class Rule extends Lint.Rules.AbstractRule {
2929
rationale: Lint.Utils.dedent`
3030
Always prefer \`const x: T = { ... };\` to \`const x = { ... } as T;\`.
3131
The type assertion in the latter case is either unnecessary or hides an error.
32-
\`const x: { foo: number } = {}\` will fail, but \`const x = {} as { foo: number }\` succeeds.`,
32+
The compiler will warn for excess properties with this syntax, but not missing required fields.
33+
For example: \`const x: { foo: number } = {}\` will fail to compile, but
34+
\`const x = {} as { foo: number }\` will succeed.`,
3335
optionsDescription: "Not configurable.",
3436
options: null,
3537
optionExamples: [true],
@@ -38,7 +40,7 @@ export class Rule extends Lint.Rules.AbstractRule {
3840
};
3941
/* tslint:enable:object-literal-sort-keys */
4042

41-
public static FAILURE_STRING = "Type assertion applied to object literal.";
43+
public static FAILURE_STRING = "Type assertion on object literals is forbidden, use a type annotation instead.";
4244

4345
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
4446
return this.applyWithFunction(sourceFile, walk);

test/rules/no-object-literal-type-assertion/test.ts.lint

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ x as T;
1212
{} as any;
1313
<any> {};
1414

15-
[0]: Type assertion applied to object literal.
15+
[0]: Type assertion on object literals is forbidden, use a type annotation instead.

0 commit comments

Comments
 (0)