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

Commit

Permalink
Wordsmith docs for no-object-literal-type-assertion (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored and nchen63 committed May 9, 2017
1 parent 63fc794 commit 0da23e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/rules/noObjectLiteralTypeAssertionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class Rule extends Lint.Rules.AbstractRule {
rationale: Lint.Utils.dedent`
Always prefer \`const x: T = { ... };\` to \`const x = { ... } as T;\`.
The type assertion in the latter case is either unnecessary or hides an error.
\`const x: { foo: number } = {}\` will fail, but \`const x = {} as { foo: number }\` succeeds.`,
The compiler will warn for excess properties with this syntax, but not missing required fields.
For example: \`const x: { foo: number } = {}\` will fail to compile, but
\`const x = {} as { foo: number }\` will succeed.`,
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
Expand All @@ -38,7 +40,7 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

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

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithFunction(sourceFile, walk);
Expand Down
2 changes: 1 addition & 1 deletion test/rules/no-object-literal-type-assertion/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ x as T;
{} as any;
<any> {};

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

0 comments on commit 0da23e4

Please sign in to comment.