Skip to content

Commit 30c9beb

Browse files
demonstrate the changes to run all of TS with new flag
Note the widened indexOf is for demo purposes only to make existing tests run without further casts, and not required. In reality, it's a *good* thing TS errors when you do `[1,2,3].indexOf(4)`. it's telling you you're being dumb for trying to search for something we know isn't there.
1 parent 4bea1a9 commit 30c9beb

File tree

187 files changed

+1388
-1258
lines changed

Some content is hidden

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

187 files changed

+1388
-1258
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace ts {
6464
const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters;
6565
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
6666
const strictNullChecks = compilerOptions.strictNullChecks === undefined ? compilerOptions.strict : compilerOptions.strictNullChecks;
67-
const granularConst = compilerOptions.granularConst;
67+
const granularConst = true; // compilerOptions.granularConst;
6868
const noImplicitAny = compilerOptions.noImplicitAny === undefined ? compilerOptions.strict : compilerOptions.noImplicitAny;
6969
const noImplicitThis = compilerOptions.noImplicitThis === undefined ? compilerOptions.strict : compilerOptions.noImplicitThis;
7070

src/harness/unittests/programMissingFiles.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ namespace ts {
4848
const program = createProgram(["./nonexistent.ts"], options, testCompilerHost);
4949
const missing = program.getMissingFilePaths();
5050
assert.isDefined(missing);
51-
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"]); // Absolute path
51+
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"] as string[]); // Absolute path
5252
});
5353

5454
it("handles multiple missing root files", () => {
5555
const program = createProgram(["./nonexistent0.ts", "./nonexistent1.ts"], options, testCompilerHost);
5656
const missing = program.getMissingFilePaths().sort();
57-
assert.deepEqual(missing, ["d:/pretend/nonexistent0.ts", "d:/pretend/nonexistent1.ts"]);
57+
assert.deepEqual(missing, ["d:/pretend/nonexistent0.ts", "d:/pretend/nonexistent1.ts"] as string[]);
5858
});
5959

6060
it("handles a mix of present and missing root files", () => {
6161
const program = createProgram(["./nonexistent0.ts", emptyFileRelativePath, "./nonexistent1.ts"], options, testCompilerHost);
6262
const missing = program.getMissingFilePaths().sort();
63-
assert.deepEqual(missing, ["d:/pretend/nonexistent0.ts", "d:/pretend/nonexistent1.ts"]);
63+
assert.deepEqual(missing, ["d:/pretend/nonexistent0.ts", "d:/pretend/nonexistent1.ts"] as string[]);
6464
});
6565

6666
it("handles repeatedly specified root files", () => {
6767
const program = createProgram(["./nonexistent.ts", "./nonexistent.ts"], options, testCompilerHost);
6868
const missing = program.getMissingFilePaths();
6969
assert.isDefined(missing);
70-
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"]);
70+
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"] as string[]);
7171
});
7272

7373
it("normalizes file paths", () => {
@@ -97,7 +97,7 @@ namespace ts {
9797
"d:/pretend/nonexistent4.d.ts",
9898
"d:/pretend/nonexistent4.ts",
9999
"d:/pretend/nonexistent4.tsx"
100-
]);
100+
] as string[]);
101101
});
102102
});
103103
}

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ts.projectSystem {
66
import protocol = server.protocol;
77
import CommandNames = server.CommandNames;
88

9-
const safeList = {
9+
const safeList: FileOrFolder = {
1010
path: <Path>"/safeList.json",
1111
content: JSON.stringify({
1212
commander: "commander",
@@ -58,7 +58,7 @@ namespace ts.projectSystem {
5858
installTypingHost: server.ServerHost,
5959
readonly typesRegistry = createMap<void>(),
6060
log?: TI.Log) {
61-
super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, log);
61+
super(installTypingHost, globalTypingsCacheLocation, safeList.path as Path, throttleLimit, log);
6262
}
6363

6464
protected postExecActions: PostExecAction[] = [];
@@ -1496,7 +1496,7 @@ namespace ts.projectSystem {
14961496
try {
14971497
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
14981498
const proj = projectService.externalProjects[0];
1499-
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
1499+
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path] as string[]);
15001500
assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]);
15011501
} finally {
15021502
projectService.resetSafeList();
@@ -1534,7 +1534,7 @@ namespace ts.projectSystem {
15341534
try {
15351535
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles(files.map(f => f.path)) });
15361536
const proj = projectService.externalProjects[0];
1537-
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
1537+
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path] as string[]);
15381538
assert.deepEqual(proj.getTypeAcquisition().include, ["kendo-ui", "office"]);
15391539
} finally {
15401540
projectService.resetSafeList();
@@ -2895,7 +2895,7 @@ namespace ts.projectSystem {
28952895

28962896
describe("rename a module file and rename back", () => {
28972897
it("should restore the states for inferred projects", () => {
2898-
const moduleFile = {
2898+
/* tslint:disable:prefer-const */ let moduleFile = {
28992899
path: "/a/b/moduleFile.ts",
29002900
content: "export function bar() { };"
29012901
};
@@ -2943,7 +2943,7 @@ namespace ts.projectSystem {
29432943
});
29442944

29452945
it("should restore the states for configured projects", () => {
2946-
const moduleFile = {
2946+
/* tslint:disable:prefer-const */ let moduleFile = {
29472947
path: "/a/b/moduleFile.ts",
29482948
content: "export function bar() { };"
29492949
};
@@ -3131,7 +3131,7 @@ namespace ts.projectSystem {
31313131
path: "/a/b/app.ts",
31323132
content: "let x = 10"
31333133
};
3134-
const configFile = {
3134+
/* tslint:disable:prefer-const */ let configFile = {
31353135
path: "/a/b/tsconfig.json",
31363136
content: `{
31373137
"compilerOptions": {}

src/lib/es5.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,13 +1002,13 @@ interface ReadonlyArray<T> {
10021002
* @param searchElement The value to locate in the array.
10031003
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
10041004
*/
1005-
indexOf(searchElement: T, fromIndex?: number): number;
1005+
indexOf(searchElement: any, fromIndex?: number): number;
10061006
/**
10071007
* Returns the index of the last occurrence of a specified value in an array.
10081008
* @param searchElement The value to locate in the array.
10091009
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
10101010
*/
1011-
lastIndexOf(searchElement: T, fromIndex?: number): number;
1011+
lastIndexOf(searchElement: any, fromIndex?: number): number;
10121012
/**
10131013
* Determines whether all the members of an array satisfy the specified test.
10141014
* @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
@@ -1152,13 +1152,13 @@ interface Array<T> {
11521152
* @param searchElement The value to locate in the array.
11531153
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
11541154
*/
1155-
indexOf(searchElement: T, fromIndex?: number): number;
1155+
indexOf(searchElement: any, fromIndex?: number): number;
11561156
/**
11571157
* Returns the index of the last occurrence of a specified value in an array.
11581158
* @param searchElement The value to locate in the array.
11591159
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
11601160
*/
1161-
lastIndexOf(searchElement: T, fromIndex?: number): number;
1161+
lastIndexOf(searchElement: any, fromIndex?: number): number;
11621162
/**
11631163
* Determines whether all the members of an array satisfy the specified test.
11641164
* @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.

src/services/jsTyping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace ts.JsTyping {
157157

158158
filesToWatch.push(jsonPath);
159159
const jsonConfig: PackageJson = readConfigFile(jsonPath, path => host.readFile(path)).config;
160-
const jsonTypingNames = flatMap([jsonConfig.dependencies, jsonConfig.devDependencies, jsonConfig.optionalDependencies, jsonConfig.peerDependencies], getOwnKeys);
160+
const jsonTypingNames = flatMap(<MapLike<string>[]> [jsonConfig.dependencies, jsonConfig.devDependencies, jsonConfig.optionalDependencies, jsonConfig.peerDependencies], getOwnKeys);
161161
addInferredTypings(jsonTypingNames, `Typing names in '${jsonPath}' dependencies`);
162162
}
163163

tests/baselines/reference/ambientConstLiterals.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ declare const c6 = -123;
6262
declare const c7: boolean;
6363
declare const c8: E;
6464
declare const c9: {
65-
x: string;
65+
x: "abc";
6666
};
67-
declare const c10: number[];
67+
declare const c10: [123];
6868
declare const c11: string;
6969
declare const c12: number;
7070
declare const c13: string;

tests/baselines/reference/ambientConstLiterals.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ const c8 = E.A;
5656
>A : E.A
5757

5858
const c9 = { x: "abc" };
59-
>c9 : { x: string; }
60-
>{ x: "abc" } : { x: string; }
59+
>c9 : { x: "abc"; }
60+
>{ x: "abc" } : { x: "abc"; }
6161
>x : string
6262
>"abc" : "abc"
6363

6464
const c10 = [123];
65-
>c10 : number[]
66-
>[123] : number[]
65+
>c10 : [123]
66+
>[123] : [123]
6767
>123 : 123
6868

6969
const c11 = "abc" + "def";

tests/baselines/reference/argumentExpressionContextualTyping.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(16,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
22
Property '0' is missing in type '(string | number | boolean)[]'.
3-
tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(17,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
43
tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(18,5): error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'.
54
Types of property 'x' are incompatible.
65
Type '(string | number)[]' is not assignable to type '[any, any]'.
76
Property '0' is missing in type '(string | number)[]'.
87

98

10-
==== tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts (3 errors) ====
9+
==== tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts (2 errors) ====
1110
// In a typed function call, argument expressions are contextually typed by their corresponding parameter types.
1211
function foo({x: [a, b], y: {c, d, e}}) { }
1312
function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { }
@@ -28,8 +27,6 @@ tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextua
2827
!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
2928
!!! error TS2345: Property '0' is missing in type '(string | number | boolean)[]'.
3029
baz(["string", 1, true, ...array]); // Error
31-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32-
!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
3330
foo(o); // Error because x has an array type namely (string|number)[]
3431
~
3532
!!! error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'.

tests/baselines/reference/arrayLiteralComments.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/arrayLiteralComments.ts ===
22
var testArrayWithFunc = [
33
>testArrayWithFunc : (string | number | (() => void) | number[] | { a: number; })[]
4-
>[ // Function comment function() { let x = 1; }, // String comment '1', // Numeric comment 2, // Object comment { a: 1 }, // Array comment [1, 2, 3]] : (string | number | (() => void) | number[] | { a: number; })[]
4+
>[ // Function comment function() { let x = 1; }, // String comment '1', // Numeric comment 2, // Object comment { a: 1 }, // Array comment [1, 2, 3]] : (string | number | (() => void) | { a: number; } | number[])[]
55

66
// Function comment
77
function() {

tests/baselines/reference/assignmentCompatBug5.errors.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
tests/cases/compiler/assignmentCompatBug5.ts(2,8): error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
1+
tests/cases/compiler/assignmentCompatBug5.ts(2,8): error TS2345: Argument of type '{ b: 5; }' is not assignable to parameter of type '{ a: number; }'.
22
Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.
3-
tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
4-
Type 'string' is not assignable to type 'number'.
3+
tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type '["s", "t"]' is not assignable to parameter of type 'number[]'.
4+
Types of property 'push' are incompatible.
5+
Type '(...items: ("s" | "t")[]) => number' is not assignable to type '(...items: number[]) => number'.
6+
Types of parameters 'items' and 'items' are incompatible.
7+
Type 'number' is not assignable to type '"s" | "t"'.
58
tests/cases/compiler/assignmentCompatBug5.ts(8,6): error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'.
69
Types of parameters 's' and 'n' are incompatible.
710
Type 'number' is not assignable to type 'string'.
@@ -13,14 +16,17 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ
1316
function foo1(x: { a: number; }) { }
1417
foo1({ b: 5 });
1518
~~~~
16-
!!! error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
19+
!!! error TS2345: Argument of type '{ b: 5; }' is not assignable to parameter of type '{ a: number; }'.
1720
!!! error TS2345: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.
1821

1922
function foo2(x: number[]) { }
2023
foo2(["s", "t"]);
2124
~~~~~~~~~~
22-
!!! error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
23-
!!! error TS2345: Type 'string' is not assignable to type 'number'.
25+
!!! error TS2345: Argument of type '["s", "t"]' is not assignable to parameter of type 'number[]'.
26+
!!! error TS2345: Types of property 'push' are incompatible.
27+
!!! error TS2345: Type '(...items: ("s" | "t")[]) => number' is not assignable to type '(...items: number[]) => number'.
28+
!!! error TS2345: Types of parameters 'items' and 'items' are incompatible.
29+
!!! error TS2345: Type 'number' is not assignable to type '"s" | "t"'.
2430

2531
function foo3(x: (n: number) =>number) { };
2632
foo3((s:string) => { });
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration.
2-
tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(4,5): error TS2345: Argument of type '{ id: number; name: boolean; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
2+
tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(4,5): error TS2345: Argument of type '{ id: 1234; name: false; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
33
Types of property 'name' are incompatible.
4-
Type 'boolean' is not assignable to type 'string'.
5-
tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(5,5): error TS2345: Argument of type '{ name: string; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
6-
Property 'id' is missing in type '{ name: string; }'.
4+
Type 'false' is not assignable to type 'string'.
5+
tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(5,5): error TS2345: Argument of type '{ name: "hello"; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
6+
Property 'id' is missing in type '{ name: "hello"; }'.
77

88

99
==== tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts (3 errors) ====
@@ -14,10 +14,10 @@ tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(5,5): error TS
1414
foo({ id: 1234, name: "hello" }); // Ok
1515
foo({ id: 1234, name: false }); // Error, name of wrong type
1616
~~~~~~~~~~~~~~~~~~~~~~~~~
17-
!!! error TS2345: Argument of type '{ id: number; name: boolean; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
17+
!!! error TS2345: Argument of type '{ id: 1234; name: false; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
1818
!!! error TS2345: Types of property 'name' are incompatible.
19-
!!! error TS2345: Type 'boolean' is not assignable to type 'string'.
19+
!!! error TS2345: Type 'false' is not assignable to type 'string'.
2020
foo({ name: "hello" }); // Error, id required but missing
2121
~~~~~~~~~~~~~~~~~
22-
!!! error TS2345: Argument of type '{ name: string; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
23-
!!! error TS2345: Property 'id' is missing in type '{ name: string; }'.
22+
!!! error TS2345: Argument of type '{ name: "hello"; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
23+
!!! error TS2345: Property 'id' is missing in type '{ name: "hello"; }'.

0 commit comments

Comments
 (0)