Skip to content

Commit 4e85864

Browse files
committed
Merge pull request microsoft#3823 from Microsoft/strictObjectLiterals
Strict object literal assignment checking
2 parents d057f56 + 5f7bc51 commit 4e85864

File tree

217 files changed

+3372
-5955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+3372
-5955
lines changed

src/compiler/checker.ts

Lines changed: 194 additions & 86 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ namespace ts {
254254
Only_a_void_function_can_be_called_with_the_new_keyword: { code: 2350, category: DiagnosticCategory.Error, key: "Only a void function can be called with the 'new' keyword." },
255255
Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature: { code: 2351, category: DiagnosticCategory.Error, key: "Cannot use 'new' with an expression whose type lacks a call or construct signature." },
256256
Neither_type_0_nor_type_1_is_assignable_to_the_other: { code: 2352, category: DiagnosticCategory.Error, key: "Neither type '{0}' nor type '{1}' is assignable to the other." },
257+
Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1: { code: 2353, category: DiagnosticCategory.Error, key: "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'." },
257258
No_best_common_type_exists_among_return_expressions: { code: 2354, category: DiagnosticCategory.Error, key: "No best common type exists among return expressions." },
258259
A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2355, category: DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement." },
259260
An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type: { code: 2356, category: DiagnosticCategory.Error, key: "An arithmetic operand must be of type 'any', 'number' or an enum type." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,10 @@
10051005
"category": "Error",
10061006
"code": 2352
10071007
},
1008+
"Object literal may only specify known properties, and '{0}' does not exist in type '{1}'.": {
1009+
"category": "Error",
1010+
"code": 2353
1011+
},
10081012
"No best common type exists among return expressions.": {
10091013
"category": "Error",
10101014
"code": 2354

src/compiler/types.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,10 +1762,12 @@ namespace ts {
17621762
FromSignature = 0x00040000, // Created for signature assignment check
17631763
ObjectLiteral = 0x00080000, // Originates in an object literal
17641764
/* @internal */
1765-
ContainsUndefinedOrNull = 0x00100000, // Type is or contains Undefined or Null type
1765+
FreshObjectLiteral = 0x00100000, // Fresh object literal type
17661766
/* @internal */
1767-
ContainsObjectLiteral = 0x00200000, // Type is or contains object literal type
1768-
ESSymbol = 0x00400000, // Type of symbol primitive introduced in ES6
1767+
ContainsUndefinedOrNull = 0x00200000, // Type is or contains Undefined or Null type
1768+
/* @internal */
1769+
ContainsObjectLiteral = 0x00400000, // Type is or contains object literal type
1770+
ESSymbol = 0x00800000, // Type of symbol primitive introduced in ES6
17691771

17701772
/* @internal */
17711773
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
@@ -1858,6 +1860,14 @@ namespace ts {
18581860
numberIndexType?: Type; // Numeric index type
18591861
}
18601862

1863+
/* @internal */
1864+
// Object literals are initially marked fresh. Freshness disappears following an assignment,
1865+
// before a type assertion, or when when an object literal's type is widened. The regular
1866+
// version of a fresh type is identical except for the TypeFlags.FreshObjectLiteral flag.
1867+
export interface FreshObjectLiteralType extends ResolvedType {
1868+
regularType: ResolvedType; // Regular version of fresh type
1869+
}
1870+
18611871
// Just a place to cache element types of iterables and iterators
18621872
/* @internal */
18631873
export interface IterableOrIteratorType extends ObjectType, UnionType {
@@ -2211,6 +2221,7 @@ namespace ts {
22112221

22122222
export interface CompilerHost {
22132223
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
2224+
getCancellationToken?(): CancellationToken;
22142225
getDefaultLibFileName(options: CompilerOptions): string;
22152226
writeFile: WriteFileCallback;
22162227
getCurrentDirectory(): string;

src/harness/fourslash.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ module FourSlash {
2626
export interface FourSlashFile {
2727
// The contents of the file (with markers, etc stripped out)
2828
content: string;
29-
3029
fileName: string;
31-
30+
version: number;
3231
// File-specific options (name/value pairs)
3332
fileOptions: { [index: string]: string; };
3433
}

src/harness/loggedIO.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface FindFileResult {
1212
}
1313

1414
interface IOLog {
15+
timestamp: string;
1516
arguments: string[];
1617
executingPath: string;
1718
currentDirectory: string;

src/server/client.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ namespace ts.server {
202202
return {
203203
isMemberCompletion: false,
204204
isNewIdentifierLocation: false,
205-
entries: response.body,
206-
fileName: fileName,
207-
position: position
205+
entries: response.body
208206
};
209207
}
210208

src/services/services.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ namespace ts {
11051105
}
11061106

11071107
export interface HighlightSpan {
1108+
fileName?: string;
11081109
textSpan: TextSpan;
11091110
kind: string;
11101111
}
@@ -1411,7 +1412,9 @@ namespace ts {
14111412
* @param fileName The name of the file to be released
14121413
* @param compilationSettings The compilation settings used to acquire the file
14131414
*/
1414-
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void
1415+
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
1416+
1417+
reportStats(): string;
14151418
}
14161419

14171420
// TODO: move these to enums

src/services/shims.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,11 @@ namespace ts {
454454
}
455455
}
456456

457-
export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; } []{
457+
export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; code: number; } []{
458458
return diagnostics.map(d => realizeDiagnostic(d, newLine));
459459
}
460460

461-
function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } {
461+
function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; code: number; } {
462462
return {
463463
message: flattenDiagnosticMessageText(diagnostic.messageText, newLine),
464464
start: diagnostic.start,

tests/baselines/reference/ES5For-of30.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'string | number' is not an array type.
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'number | string' is not an array type.
22
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'.
33
tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'number'.
44

@@ -8,7 +8,7 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error
88
var tuple: [number, string] = [2, "3"];
99
for ([a = 1, b = ""] of tuple) {
1010
~~~~~~~~~~~~~~~
11-
!!! error TS2461: Type 'string | number' is not an array type.
11+
!!! error TS2461: Type 'number | string' is not an array type.
1212
~
1313
!!! error TS2322: Type 'number' is not assignable to type 'string'.
1414
~

0 commit comments

Comments
 (0)