Skip to content

Commit

Permalink
demonstrate the changes to run all of TS with new flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KiaraGrouwstra committed Aug 17, 2017
1 parent 4bea1a9 commit 30c9beb
Show file tree
Hide file tree
Showing 187 changed files with 1,388 additions and 1,258 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace ts {
const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters;
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
const strictNullChecks = compilerOptions.strictNullChecks === undefined ? compilerOptions.strict : compilerOptions.strictNullChecks;
const granularConst = compilerOptions.granularConst;
const granularConst = true; // compilerOptions.granularConst;
const noImplicitAny = compilerOptions.noImplicitAny === undefined ? compilerOptions.strict : compilerOptions.noImplicitAny;
const noImplicitThis = compilerOptions.noImplicitThis === undefined ? compilerOptions.strict : compilerOptions.noImplicitThis;

Expand Down
10 changes: 5 additions & 5 deletions src/harness/unittests/programMissingFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ namespace ts {
const program = createProgram(["./nonexistent.ts"], options, testCompilerHost);
const missing = program.getMissingFilePaths();
assert.isDefined(missing);
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"]); // Absolute path
assert.deepEqual(missing, ["d:/pretend/nonexistent.ts"] as string[]); // Absolute path
});

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

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

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

it("normalizes file paths", () => {
Expand Down Expand Up @@ -97,7 +97,7 @@ namespace ts {
"d:/pretend/nonexistent4.d.ts",
"d:/pretend/nonexistent4.ts",
"d:/pretend/nonexistent4.tsx"
]);
] as string[]);
});
});
}
14 changes: 7 additions & 7 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ts.projectSystem {
import protocol = server.protocol;
import CommandNames = server.CommandNames;

const safeList = {
const safeList: FileOrFolder = {
path: <Path>"/safeList.json",
content: JSON.stringify({
commander: "commander",
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace ts.projectSystem {
installTypingHost: server.ServerHost,
readonly typesRegistry = createMap<void>(),
log?: TI.Log) {
super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, log);
super(installTypingHost, globalTypingsCacheLocation, safeList.path as Path, throttleLimit, log);
}

protected postExecActions: PostExecAction[] = [];
Expand Down Expand Up @@ -1496,7 +1496,7 @@ namespace ts.projectSystem {
try {
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) });
const proj = projectService.externalProjects[0];
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path] as string[]);
assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]);
} finally {
projectService.resetSafeList();
Expand Down Expand Up @@ -1534,7 +1534,7 @@ namespace ts.projectSystem {
try {
projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles(files.map(f => f.path)) });
const proj = projectService.externalProjects[0];
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path]);
assert.deepEqual(proj.getFileNames(/*excludeFilesFromExternalLibraries*/ true), [file1.path] as string[]);
assert.deepEqual(proj.getTypeAcquisition().include, ["kendo-ui", "office"]);
} finally {
projectService.resetSafeList();
Expand Down Expand Up @@ -2895,7 +2895,7 @@ namespace ts.projectSystem {

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

it("should restore the states for configured projects", () => {
const moduleFile = {
/* tslint:disable:prefer-const */ let moduleFile = {
path: "/a/b/moduleFile.ts",
content: "export function bar() { };"
};
Expand Down Expand Up @@ -3131,7 +3131,7 @@ namespace ts.projectSystem {
path: "/a/b/app.ts",
content: "let x = 10"
};
const configFile = {
/* tslint:disable:prefer-const */ let configFile = {
path: "/a/b/tsconfig.json",
content: `{
"compilerOptions": {}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,13 +1002,13 @@ interface ReadonlyArray<T> {
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
*/
indexOf(searchElement: T, fromIndex?: number): number;
indexOf(searchElement: any, fromIndex?: number): number;
/**
* Returns the index of the last occurrence of a specified value in an array.
* @param searchElement The value to locate in the array.
* @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.
*/
lastIndexOf(searchElement: T, fromIndex?: number): number;
lastIndexOf(searchElement: any, fromIndex?: number): number;
/**
* Determines whether all the members of an array satisfy the specified test.
* @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.
Expand Down Expand Up @@ -1152,13 +1152,13 @@ interface Array<T> {
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
*/
indexOf(searchElement: T, fromIndex?: number): number;
indexOf(searchElement: any, fromIndex?: number): number;
/**
* Returns the index of the last occurrence of a specified value in an array.
* @param searchElement The value to locate in the array.
* @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.
*/
lastIndexOf(searchElement: T, fromIndex?: number): number;
lastIndexOf(searchElement: any, fromIndex?: number): number;
/**
* Determines whether all the members of an array satisfy the specified test.
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/services/jsTyping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace ts.JsTyping {

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

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/ambientConstLiterals.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ declare const c6 = -123;
declare const c7: boolean;
declare const c8: E;
declare const c9: {
x: string;
x: "abc";
};
declare const c10: number[];
declare const c10: [123];
declare const c11: string;
declare const c12: number;
declare const c13: string;
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/ambientConstLiterals.types
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ const c8 = E.A;
>A : E.A

const c9 = { x: "abc" };
>c9 : { x: string; }
>{ x: "abc" } : { x: string; }
>c9 : { x: "abc"; }
>{ x: "abc" } : { x: "abc"; }
>x : string
>"abc" : "abc"

const c10 = [123];
>c10 : number[]
>[123] : number[]
>c10 : [123]
>[123] : [123]
>123 : 123

const c11 = "abc" + "def";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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]'.
Property '0' is missing in type '(string | number | boolean)[]'.
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]'.
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; }; }'.
Types of property 'x' are incompatible.
Type '(string | number)[]' is not assignable to type '[any, any]'.
Property '0' is missing in type '(string | number)[]'.


==== tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts (3 errors) ====
==== tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts (2 errors) ====
// In a typed function call, argument expressions are contextually typed by their corresponding parameter types.
function foo({x: [a, b], y: {c, d, e}}) { }
function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { }
Expand All @@ -28,8 +27,6 @@ tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextua
!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
!!! error TS2345: Property '0' is missing in type '(string | number | boolean)[]'.
baz(["string", 1, true, ...array]); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'.
foo(o); // Error because x has an array type namely (string|number)[]
~
!!! 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; }; }'.
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/arrayLiteralComments.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/compiler/arrayLiteralComments.ts ===
var testArrayWithFunc = [
>testArrayWithFunc : (string | number | (() => void) | number[] | { a: number; })[]
>[ // 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; })[]
>[ // 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[])[]

// Function comment
function() {
Expand Down
18 changes: 12 additions & 6 deletions tests/baselines/reference/assignmentCompatBug5.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
tests/cases/compiler/assignmentCompatBug5.ts(2,8): error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
tests/cases/compiler/assignmentCompatBug5.ts(2,8): error TS2345: Argument of type '{ b: 5; }' is not assignable to parameter of type '{ a: number; }'.
Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.
tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type '["s", "t"]' is not assignable to parameter of type 'number[]'.
Types of property 'push' are incompatible.
Type '(...items: ("s" | "t")[]) => number' is not assignable to type '(...items: number[]) => number'.
Types of parameters 'items' and 'items' are incompatible.
Type 'number' is not assignable to type '"s" | "t"'.
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'.
Types of parameters 's' and 'n' are incompatible.
Type 'number' is not assignable to type 'string'.
Expand All @@ -13,14 +16,17 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ
function foo1(x: { a: number; }) { }
foo1({ b: 5 });
~~~~
!!! error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
!!! error TS2345: Argument of type '{ b: 5; }' is not assignable to parameter of type '{ a: number; }'.
!!! error TS2345: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.

function foo2(x: number[]) { }
foo2(["s", "t"]);
~~~~~~~~~~
!!! error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
!!! error TS2345: Argument of type '["s", "t"]' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Types of property 'push' are incompatible.
!!! error TS2345: Type '(...items: ("s" | "t")[]) => number' is not assignable to type '(...items: number[]) => number'.
!!! error TS2345: Types of parameters 'items' and 'items' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type '"s" | "t"'.

function foo3(x: (n: number) =>number) { };
foo3((s:string) => { });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration.
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; }'.
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; }'.
Types of property 'name' are incompatible.
Type 'boolean' is not assignable to type 'string'.
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; }'.
Property 'id' is missing in type '{ name: string; }'.
Type 'false' is not assignable to type 'string'.
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; }'.
Property 'id' is missing in type '{ name: "hello"; }'.


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

0 comments on commit 30c9beb

Please sign in to comment.