From 0da23e4631745f10ad69fd9a7a8693a649becbd4 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 8 May 2017 23:41:17 -0400 Subject: [PATCH] Wordsmith docs for no-object-literal-type-assertion (#2719) --- src/rules/noObjectLiteralTypeAssertionRule.ts | 6 ++++-- test/rules/no-object-literal-type-assertion/test.ts.lint | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rules/noObjectLiteralTypeAssertionRule.ts b/src/rules/noObjectLiteralTypeAssertionRule.ts index be26ae829b5..248a3c0ac3d 100644 --- a/src/rules/noObjectLiteralTypeAssertionRule.ts +++ b/src/rules/noObjectLiteralTypeAssertionRule.ts @@ -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], @@ -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); diff --git a/test/rules/no-object-literal-type-assertion/test.ts.lint b/test/rules/no-object-literal-type-assertion/test.ts.lint index 1269adb4290..73405b74746 100644 --- a/test/rules/no-object-literal-type-assertion/test.ts.lint +++ b/test/rules/no-object-literal-type-assertion/test.ts.lint @@ -12,4 +12,4 @@ x as T; {} as any; {}; -[0]: Type assertion applied to object literal. +[0]: Type assertion on object literals is forbidden, use a type annotation instead.