Merge branch 'master' into completionFixes

Conflicts:
	src/services/services.ts
This commit is contained in:
Mohamed Hegazy
2014-10-23 12:57:22 -07:00
379 changed files with 11428 additions and 8832 deletions
+1
View File
@@ -37,4 +37,5 @@ tests/*.d.ts
scripts/debug.bat
scripts/run.bat
scripts/word2md.js
scripts/ior.js
coverage/
+1 -1
View File
@@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr
## Legal
You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright.
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
## Housekeeping
Your pull request should:
+8 -5
View File
@@ -10,6 +10,7 @@ var servicesDirectory = "src/services/";
var harnessDirectory = "src/harness/";
var libraryDirectory = "src/lib/";
var scriptsDirectory = "scripts/";
var unittestsDirectory = "tests/cases/unittests/";
var docDirectory = "doc/";
var builtDirectory = "built/";
@@ -74,13 +75,17 @@ var harnessSources = [
"typeWriter.ts",
"fourslashRunner.ts",
"projectsRunner.ts",
"unittestrunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
"runner.ts"
].map(function (f) {
return path.join(harnessDirectory, f);
});
}).concat([
"services/colorization.ts",
"services/documentRegistry.ts"
].map(function (f) {
return path.join(unittestsDirectory, f);
}));
var librarySourceMap = [
{ target: "lib.core.d.ts", sources: ["core.d.ts"] },
@@ -279,7 +284,6 @@ var word2mdJs = path.join(scriptsDirectory, "word2md.js");
var word2mdTs = path.join(scriptsDirectory, "word2md.ts");
var specWord = path.join(docDirectory, "TypeScript Language Specification.docx");
var specMd = path.join(docDirectory, "spec.md");
var headerMd = path.join(docDirectory, "header.md");
file(word2mdTs);
@@ -292,9 +296,8 @@ compileFile(word2mdJs,
// The generated spec.md; built for the 'generate-spec' task
file(specMd, [word2mdJs, specWord], function () {
jake.cpR(headerMd, specMd, {silent: true});
var specWordFullPath = path.resolve(specWord);
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd;
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd;
console.log(cmd);
child_process.exec(cmd, function () {
complete();
+4
View File
@@ -1,3 +1,7 @@
[![Build Status](https://travis-ci.org/Microsoft/TypeScript.svg?branch=master)](https://travis-ci.org/Microsoft/TypeScript)
[![Issue Stats](http://issuestats.com/github/Microsoft/TypeScript/badge/pr)](http://issuestats.com/github/microsoft/typescript)
[![Issue Stats](http://issuestats.com/github/Microsoft/TypeScript/badge/issue)](http://issuestats.com/github/microsoft/typescript)
# TypeScript
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang).
Binary file not shown.
Binary file not shown.
-2
View File
@@ -1,2 +0,0 @@
# TypeScript Language Specification
+611 -392
View File
File diff suppressed because it is too large Load Diff
+123
View File
@@ -0,0 +1,123 @@
/// <reference path="../src/harness/external/node.d.ts" />
import fs = require('fs');
import path = require('path');
interface IOLog {
filesRead: {
path: string;
result: { contents: string; };
}[];
arguments: string[];
}
module Commands {
export function dir(obj: IOLog) {
obj.filesRead.filter(f => f.result !== undefined).forEach(f => {
console.log(f.path);
});
}
dir['description'] = ': displays a list of files';
export function find(obj: IOLog, str: string) {
obj.filesRead.filter(f => f.result !== undefined).forEach(f => {
var lines = f.result.contents.split('\n');
var printedHeader = false;
lines.forEach(line => {
if (line.indexOf(str) >= 0) {
if (!printedHeader) {
console.log(' === ' + f.path + ' ===');
printedHeader = true;
}
console.log(line);
}
});
});
}
find['description'] = ' string: finds text in files';
export function grab(obj: IOLog, filename: string) {
obj.filesRead.filter(f => f.result !== undefined).forEach(f => {
if (path.basename(f.path) === filename) {
fs.writeFile(filename, f.result.contents);
}
});
}
grab['description'] = ' filename.ts: writes out the specified file to disk';
export function extract(obj: IOLog, outputFolder: string) {
var directorySeparator = "/";
function directoryExists(path: string): boolean {
return fs.existsSync(path) && fs.statSync(path).isDirectory();
}
function getDirectoryPath(path: string) {
return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator)));
}
function getRootLength(path: string): number {
if (path.charAt(0) === directorySeparator) {
if (path.charAt(1) !== directorySeparator) return 1;
var p1 = path.indexOf(directorySeparator, 2);
if (p1 < 0) return 2;
var p2 = path.indexOf(directorySeparator, p1 + 1);
if (p2 < 0) return p1 + 1;
return p2 + 1;
}
if (path.charAt(1) === ":") {
if (path.charAt(2) === directorySeparator) return 3;
return 2;
}
return 0;
}
function ensureDirectoriesExist(directoryPath: string) {
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
var parentDirectory = getDirectoryPath(directoryPath);
ensureDirectoriesExist(parentDirectory);
console.log("creating directory: " + directoryPath);
fs.mkdirSync(directoryPath);
}
}
function transalatePath(outputFolder:string, path: string): string {
return outputFolder + directorySeparator + path.replace(":", "");
}
function fileExists(path: string): boolean {
return fs.existsSync(path);
}
obj.filesRead.forEach(f => {
var filename = transalatePath(outputFolder, f.path);
ensureDirectoriesExist(getDirectoryPath(filename));
console.log("writing filename: " + filename);
fs.writeFile(filename, f.result.contents, (err) => { });
});
console.log("Command: tsc ");
obj.arguments.forEach(a => {
if (getRootLength(a) > 0) {
console.log(transalatePath(outputFolder, a));
}
else {
console.log(a);
}
console.log(" ");
});
}
extract['description'] = ' outputFolder: extract all input files to <outputFolder>';
}
var args = process.argv.slice(2);
if (args.length < 2) {
console.log('Usage: node ior.js path_to_file.json [command]');
console.log('List of commands: ');
Object.keys(Commands).forEach(k => console.log(' ' + k + Commands[k]['description']));
} else {
var cmd: Function = Commands[args[1]];
if (cmd === undefined) {
console.log('Unknown command ' + args[1]);
} else {
fs.readFile(args[0], 'utf-8', (err, data) => {
if (err) throw err;
var json = JSON.parse(data);
cmd.apply(undefined, [json].concat(args.slice(2)));
});
}
}
+32 -4
View File
@@ -1,4 +1,8 @@
var sys = (function () {
var fileStream = new ActiveXObject("ADODB.Stream");
fileStream.Type = 2;
var binaryStream = new ActiveXObject("ADODB.Stream");
binaryStream.Type = 1;
var args = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
args[i] = WScript.Arguments.Item(i);
@@ -6,7 +10,24 @@ var sys = (function () {
return {
args: args,
createObject: function (typeName) { return new ActiveXObject(typeName); },
write: function (s) { return WScript.StdOut.Write(s); }
write: function (s) {
WScript.StdOut.Write(s);
},
writeFile: function (fileName, data) {
fileStream.Open();
binaryStream.Open();
try {
fileStream.Charset = "utf-8";
fileStream.WriteText(data);
fileStream.Position = 3;
fileStream.CopyTo(binaryStream);
binaryStream.SaveToFile(fileName, 2);
}
finally {
binaryStream.Close();
fileStream.Close();
}
}
};
})();
function convertDocumentToMarkdown(doc) {
@@ -149,6 +170,10 @@ function convertDocumentToMarkdown(doc) {
lastInTable = inTable;
}
function writeDocument() {
var title = doc.builtInDocumentProperties.item(1) + "";
if (title.length) {
write("# " + title + "\n\n");
}
for (var p = doc.paragraphs.first; p; p = p.next()) {
writeParagraph(p);
}
@@ -168,16 +193,19 @@ function convertDocumentToMarkdown(doc) {
findReplace("^19 REF", {}, "[^&](#^&)", {});
doc.fields.toggleShowCodes();
writeDocument();
result = result.replace(/\x85/g, "\u2026");
result = result.replace(/\x96/g, "\u2013");
result = result.replace(/\x97/g, "\u2014");
return result;
}
function main(args) {
if (args.length !== 1) {
sys.write("Syntax: word2md <filename>\n");
if (args.length !== 2) {
sys.write("Syntax: word2md <inputfile> <outputfile>\n");
return;
}
var app = sys.createObject("Word.Application");
var doc = app.documents.open(args[0]);
sys.write(convertDocumentToMarkdown(doc));
sys.writeFile(args[1], convertDocumentToMarkdown(doc));
doc.close(false);
app.quit();
}
+36 -4
View File
@@ -103,6 +103,7 @@ module Word {
export interface Document {
fields: Fields;
paragraphs: Paragraphs;
builtInDocumentProperties: Collection<any>;
close(saveChanges: boolean): void;
range(): Range;
}
@@ -118,6 +119,10 @@ module Word {
}
var sys = (function () {
var fileStream = new ActiveXObject("ADODB.Stream");
fileStream.Type = 2 /*text*/;
var binaryStream = new ActiveXObject("ADODB.Stream");
binaryStream.Type = 1 /*binary*/;
var args: string[] = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
args[i] = WScript.Arguments.Item(i);
@@ -125,7 +130,26 @@ var sys = (function () {
return {
args: args,
createObject: (typeName: string) => new ActiveXObject(typeName),
write: (s: string) => WScript.StdOut.Write(s)
write(s: string): void {
WScript.StdOut.Write(s);
},
writeFile: (fileName: string, data: string): void => {
fileStream.Open();
binaryStream.Open();
try {
// Write characters in UTF-8 encoding
fileStream.Charset = "utf-8";
fileStream.WriteText(data);
// We don't want the BOM, skip it by setting the starting location to 3 (size of BOM).
fileStream.Position = 3;
fileStream.CopyTo(binaryStream);
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
}
finally {
binaryStream.Close();
fileStream.Close();
}
}
};
})();
@@ -298,6 +322,10 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
}
function writeDocument() {
var title = doc.builtInDocumentProperties.item(1) + "";
if (title.length) {
write("# " + title + "\n\n");
}
for (var p = doc.paragraphs.first; p; p = p.next()) {
writeParagraph(p);
}
@@ -321,17 +349,21 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
writeDocument();
result = result.replace(/\x85/g, "\u2026");
result = result.replace(/\x96/g, "\u2013");
result = result.replace(/\x97/g, "\u2014");
return result;
}
function main(args: string[]) {
if (args.length !== 1) {
sys.write("Syntax: word2md <filename>\n");
if (args.length !== 2) {
sys.write("Syntax: word2md <inputfile> <outputfile>\n");
return;
}
var app: Word.Application = sys.createObject("Word.Application");
var doc = app.documents.open(args[0]);
sys.write(convertDocumentToMarkdown(doc));
sys.writeFile(args[1], convertDocumentToMarkdown(doc));
doc.close(false);
app.quit();
}
+1459 -772
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -82,7 +82,7 @@ module ts {
return array1.concat(array2);
}
export function uniqueElements<T>(array: T[]): T[] {
export function deduplicate<T>(array: T[]): T[] {
if (array) {
var result: T[] = [];
for (var i = 0, len = array.length; i < len; i++) {
@@ -114,6 +114,7 @@ module ts {
Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." },
Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" },
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -180,8 +181,6 @@ module ts {
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." },
No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}', '{1}', and '{2}'." },
No_best_common_type_exists_between_0_and_1: { code: 2367, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}' and '{1}'." },
Type_parameter_name_cannot_be_0: { code: 2368, category: DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: DiagnosticCategory.Error, key: "A rest parameter must be of an array type." },
+10 -14
View File
@@ -11,7 +11,7 @@
"category": "Error",
"code": 1005
},
"A file cannot have a reference to itself.": {
"A file cannot have a reference to itself.": {
"category": "Error",
"code": 1006
},
@@ -187,7 +187,7 @@
"category": "Error",
"code": 1066
},
"Unexpected token. A constructor, method, accessor, or property was expected." : {
"Unexpected token. A constructor, method, accessor, or property was expected.": {
"category": "Error",
"code": 1068
},
@@ -444,9 +444,13 @@
"code": 1149
},
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
"category": "Error",
"code": 1150
},
"category": "Error",
"code": 1150
},
"An enum member cannot have a numeric name.": {
"category": "Error",
"code": 1151
},
"Duplicate identifier '{0}'.": {
"category": "Error",
@@ -556,7 +560,7 @@
"category": "Error",
"code": 2326
},
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
"category": "Error",
"code": 2327
},
@@ -712,14 +716,6 @@
"category": "Error",
"code": 2365
},
"No best common type exists between '{0}', '{1}', and '{2}'.": {
"category": "Error",
"code": 2366
},
"No best common type exists between '{0}' and '{1}'.": {
"category": "Error",
"code": 2367
},
"Type parameter name cannot be '{0}'": {
"category": "Error",
"code": 2368
+36 -26
View File
@@ -4,8 +4,11 @@
/// <reference path="parser.ts"/>
module ts {
interface EmitTextWriter extends SymbolWriter {
interface EmitTextWriter {
write(s: string): void;
writeLine(): void;
increaseIndent(): void;
decreaseIndent(): void;
getText(): string;
rawWrite(s: string): void;
writeLiteral(s: string): void;
@@ -15,6 +18,9 @@ module ts {
getIndent(): number;
}
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{
}
var indentStrings: string[] = ["", " "];
export function getIndentString(level: number) {
if (indentStrings[level] === undefined) {
@@ -28,7 +34,7 @@ module ts {
}
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
if (!(sourceFile.flags & NodeFlags.DeclarationFile)) {
if (!isDeclarationFile(sourceFile)) {
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
return true;
}
@@ -38,7 +44,7 @@ module ts {
}
export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0;
return isExternalModule(sourceFile) || isDeclarationFile(sourceFile);
}
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
@@ -103,7 +109,7 @@ module ts {
};
}
function createTextWriter(trackSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter {
function createTextWriter(): EmitTextWriter {
var output = "";
var indent = 0;
var lineStart = true;
@@ -149,17 +155,8 @@ module ts {
}
}
function writeKind(text: string, kind: SymbolDisplayPartKind) {
write(text);
}
function writeSymbol(text: string, symbol: Symbol) {
write(text);
}
return {
write: write,
trackSymbol: trackSymbol,
writeKind: writeKind,
writeSymbol: writeSymbol,
rawWrite: rawWrite,
writeLiteral: writeLiteral,
writeLine: writeLine,
@@ -170,7 +167,6 @@ module ts {
getLine: () => lineCount + 1,
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
getText: () => output,
clear: () => { }
};
}
@@ -318,7 +314,7 @@ module ts {
}
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(trackSymbol);
var writer = createTextWriter();
var write = writer.write;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
@@ -374,8 +370,6 @@ module ts {
/** Sourcemap data that will get encoded */
var sourceMapData: SourceMapData;
function trackSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { }
function initializeEmitterWithSourceMaps() {
var sourceMapDir: string; // The directory in which sourcemap will be
@@ -2314,7 +2308,7 @@ module ts {
}
function emitDeclarations(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(trackSymbol);
var writer = createTextWriterWithSymbolWriter();
var write = writer.write;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
@@ -2338,11 +2332,24 @@ module ts {
typeName?: Identifier
}
function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
var writer = <EmitTextWriterWithSymbolWriter>createTextWriter();
writer.trackSymbol = trackSymbol;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
writer.writePunctuation = writer.write;
writer.writeSpace = writer.write;
writer.writeStringLiteral = writer.writeLiteral;
writer.writeParameter = writer.write;
writer.writeSymbol = writer.write;
return writer;
}
function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
var oldWriter = writer;
forEach(importDeclarations, aliasToWrite => {
var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
writer = createTextWriter(trackSymbol);
writer = createTextWriterWithSymbolWriter();
for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
writer.increaseIndent();
}
@@ -2861,7 +2868,7 @@ module ts {
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node.parameters[0],
errorNode: <Node>node.parameters[0],
typeName: node.name
};
}
@@ -2882,7 +2889,7 @@ module ts {
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node.name,
errorNode: <Node>node.name,
typeName: undefined
};
}
@@ -3253,14 +3260,17 @@ module ts {
if (compilerOptions.out) {
emitFile(compilerOptions.out);
}
} else {
// targetSourceFile is specified (e.g calling emitter from language service)
}
else {
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
// If shouldEmitToOwnFile is true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
// If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
emitFile(jsFilePath, targetSourceFile);
} else {
// If shouldEmitToOwnFile is false, then emit all, non-external-module file, into one single output file
}
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
// Otherwise, if --out is specified and targetSourceFile is not a declaration file,
// Emit all, non-external-module file, into one single output file
emitFile(compilerOptions.out);
}
}
+99 -12
View File
@@ -111,6 +111,10 @@ module ts {
return file.externalModuleIndicator !== undefined;
}
export function isDeclarationFile(file: SourceFile): boolean {
return (file.flags & NodeFlags.DeclarationFile) !== 0;
}
export function isPrologueDirective(node: Node): boolean {
return node.kind === SyntaxKind.ExpressionStatement && (<ExpressionStatement>node).expression.kind === SyntaxKind.StringLiteral;
}
@@ -221,6 +225,10 @@ module ts {
return child((<ArrayTypeNode>node).elementType);
case SyntaxKind.TupleType:
return children((<TupleTypeNode>node).elementTypes);
case SyntaxKind.UnionType:
return children((<UnionTypeNode>node).types);
case SyntaxKind.ParenType:
return child((<ParenTypeNode>node).type);
case SyntaxKind.ArrayLiteral:
return children((<ArrayLiteral>node).elements);
case SyntaxKind.ObjectLiteral:
@@ -1072,7 +1080,7 @@ module ts {
return isParameter();
case ParsingContext.TypeArguments:
case ParsingContext.TupleElementTypes:
return isType();
return token === SyntaxKind.CommaToken || isType();
}
Debug.fail("Non-exhaustive case in 'isListElement'.");
@@ -1654,6 +1662,14 @@ module ts {
return finishNode(node);
}
function parseParenType(): ParenTypeNode {
var node = <ParenTypeNode>createNode(SyntaxKind.ParenType);
parseExpected(SyntaxKind.OpenParenToken);
node.type = parseType();
parseExpected(SyntaxKind.CloseParenToken);
return finishNode(node);
}
function parseFunctionType(signatureKind: SyntaxKind): TypeLiteralNode {
var node = <TypeLiteralNode>createNode(SyntaxKind.TypeLiteral);
var member = <SignatureDeclaration>createNode(signatureKind);
@@ -1687,10 +1703,7 @@ module ts {
case SyntaxKind.OpenBracketToken:
return parseTupleType();
case SyntaxKind.OpenParenToken:
case SyntaxKind.LessThanToken:
return parseFunctionType(SyntaxKind.CallSignature);
case SyntaxKind.NewKeyword:
return parseFunctionType(SyntaxKind.ConstructSignature);
return parseParenType();
default:
if (isIdentifier()) {
return parseTypeReference();
@@ -1714,20 +1727,20 @@ module ts {
case SyntaxKind.NewKeyword:
return true;
case SyntaxKind.OpenParenToken:
// Only consider an ( as the start of a type if we have () or (id
// We don't want to consider things like (1) as a function type.
// Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier,
// or something that starts a type. We don't want to consider things like '(1)' a type.
return lookAhead(() => {
nextToken();
return token === SyntaxKind.CloseParenToken || isParameter();
return token === SyntaxKind.CloseParenToken || isParameter() || isType();
});
default:
return isIdentifier();
}
}
function parseType(): TypeNode {
function parsePrimaryType(): TypeNode {
var type = parseNonArrayType();
while (type && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
parseExpected(SyntaxKind.CloseBracketToken);
var node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
node.elementType = type;
@@ -1736,6 +1749,64 @@ module ts {
return type;
}
function parseUnionType(): TypeNode {
var type = parsePrimaryType();
if (token === SyntaxKind.BarToken) {
var types = <NodeArray<TypeNode>>[type];
types.pos = type.pos;
while (parseOptional(SyntaxKind.BarToken)) {
types.push(parsePrimaryType());
}
types.end = getNodeEnd();
var node = <UnionTypeNode>createNode(SyntaxKind.UnionType, type.pos);
node.types = types;
type = finishNode(node);
}
return type;
}
function isFunctionType(): boolean {
return token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken && lookAhead(() => {
nextToken();
if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) {
// ( )
// ( ...
return true;
}
if (isIdentifier() || isModifier(token)) {
nextToken();
if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken ||
token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken ||
isIdentifier() || isModifier(token)) {
// ( id :
// ( id ,
// ( id ?
// ( id =
// ( modifier id
return true;
}
if (token === SyntaxKind.CloseParenToken) {
nextToken();
if (token === SyntaxKind.EqualsGreaterThanToken) {
// ( id ) =>
return true;
}
}
}
return false;
});
}
function parseType(): TypeNode {
if (isFunctionType()) {
return parseFunctionType(SyntaxKind.CallSignature);
}
if (token === SyntaxKind.NewKeyword) {
return parseFunctionType(SyntaxKind.ConstructSignature);
}
return parseUnionType();
}
function parseTypeAnnotation(): TypeNode {
return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined;
}
@@ -2322,13 +2393,29 @@ module ts {
function parseTypeArguments(): NodeArray<TypeNode> {
var typeArgumentListStart = scanner.getTokenPos();
var errorCountBeforeTypeParameterList = file.syntacticErrors.length;
var result = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken);
// We pass parseSingleTypeArgument instead of parseType as the element parser
// because parseSingleTypeArgument knows how to parse a missing type argument.
// This is useful for signature help. parseType has the disadvantage that when
// it sees a missing type, it changes the LookAheadMode to Error, and the result
// is a broken binary expression, which breaks signature help.
var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken);
if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) {
grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty);
}
return result;
}
function parseSingleTypeArgument(): TypeNode {
if (token === SyntaxKind.CommaToken) {
var errorStart = scanner.getTokenPos();
var errorLength = scanner.getTextPos() - errorStart;
grammarErrorAtPos(errorStart, errorLength, Diagnostics.Type_expected);
return createNode(SyntaxKind.Missing);
}
return parseType();
}
function parsePrimaryExpression(): Expression {
switch (token) {
case SyntaxKind.ThisKeyword:
@@ -4031,7 +4118,7 @@ module ts {
}
}
}
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || file.flags & NodeFlags.DeclarationFile)) {
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) {
// TypeScript 1.0 spec (April 2014): 12.1.6
// An AmbientExternalModuleDeclaration declares an external module.
// This type of declaration is permitted only in the global module.
+1 -1
View File
@@ -68,7 +68,7 @@ var sys: System = (function () {
return fileStream.ReadText();
}
catch (e) {
throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e;
throw e;
}
finally {
fileStream.Close();
+7 -2
View File
@@ -142,14 +142,19 @@ module ts {
// otherwise use toLowerCase as a canonical form.
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
}
// returned by CScript sys environment
var unsupportedFileEncodingErrorCode = -2147024809;
function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
try {
var text = sys.readFile(filename, options.charset);
}
catch (e) {
if (onError) {
onError(e.message);
onError(e.number === unsupportedFileEncodingErrorCode ?
getDiagnosticText(Diagnostics.Unsupported_file_encoding) :
e.message);
}
text = "";
}
+70 -62
View File
@@ -154,6 +154,8 @@ module ts {
TypeLiteral,
ArrayType,
TupleType,
UnionType,
ParenType,
// Expression
ArrayLiteral,
ObjectLiteral,
@@ -224,7 +226,7 @@ module ts {
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypeReference,
LastTypeNode = TupleType,
LastTypeNode = ParenType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = EndOfFileToken,
@@ -337,6 +339,14 @@ module ts {
elementTypes: NodeArray<TypeNode>;
}
export interface UnionTypeNode extends TypeNode {
types: NodeArray<TypeNode>;
}
export interface ParenTypeNode extends TypeNode {
type: TypeNode;
}
export interface StringLiteralTypeNode extends TypeNode {
text: string;
}
@@ -634,28 +644,25 @@ module ts {
getParentOfSymbol(symbol: Symbol): Symbol;
getTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
getPropertyOfType(type: Type, propetyName: string): Symbol;
getPropertyOfType(type: Type, propertyName: string): Symbol;
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
getReturnTypeOfSignature(signature: Signature): Type;
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
getSymbolInfo(node: Node): Symbol;
getTypeOfNode(node: Node): Type;
getApparentType(type: Type): ApparentType;
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void;
getSymbolDisplayBuilder(): SymbolDisplayBuilder;
getFullyQualifiedName(symbol: Symbol): string;
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
getRootSymbol(symbol: Symbol): Symbol;
getAugmentedPropertiesOfType(type: Type): Symbol[];
getRootSymbols(symbol: Symbol): Symbol[];
getContextualType(node: Node): Type;
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
writeSignature(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
isImplementationOfOverload(node: FunctionDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
// computed value.
@@ -665,8 +672,25 @@ module ts {
getAliasedSymbol(symbol: Symbol): Symbol;
}
export interface SymbolDisplayBuilder {
buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void;
buildSignatureDisplay(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildParameterDisplay(parameter: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
}
export interface SymbolWriter {
writeKind(text: string, kind: SymbolDisplayPartKind): void;
writeKeyword(text: string): void;
writeOperator(text: string): void;
writePunctuation(text: string): void;
writeSpace(text: string): void;
writeStringLiteral(text: string): void;
writeParameter(text: string): void;
writeSymbol(text: string, symbol: Symbol): void;
writeLine(): void;
increaseIndent(): void;
@@ -687,6 +711,7 @@ module ts {
WriteArrowStyleSignature = 0x00000008, // Write arrow style signature
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
InElementType = 0x00000040, // Writing an array or union element type
}
export enum SymbolFormatFlags {
@@ -695,6 +720,9 @@ module ts {
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
// var a: C<number>;
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
UseOnlyExternalAliasing = 0x00000002, // Use only external alias information to get the symbol name in the given context
// eg. module m { export class c { } } import x = m.c;
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
}
export enum SymbolAccessibility {
@@ -762,11 +790,11 @@ module ts {
Instantiated = 0x00800000, // Instantiated symbol
Merged = 0x01000000, // Merged symbol (created during program binding)
Transient = 0x02000000, // Transient symbol (created during type check)
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
Undefined = 0x08000000, // Symbol for the undefined
Prototype = 0x04000000, // Prototype property (no source representation)
UnionProperty = 0x08000000, // Property in union type
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
Namespace = ValueModule | NamespaceModule,
Module = ValueModule | NamespaceModule,
@@ -824,6 +852,7 @@ module ts {
mapper?: TypeMapper; // Type mapper for instantiation alias
referenced?: boolean; // True if alias symbol has been referenced as a value
exportAssignSymbol?: Symbol; // Symbol exported from external module
unionType?: UnionType; // Containing union type for union property
}
export interface TransientSymbol extends Symbol, SymbolLinks { }
@@ -846,14 +875,15 @@ module ts {
}
export interface NodeLinks {
resolvedType?: Type; // Cached type of type node
resolvedSignature?: Signature; // Cached signature of signature node or call expression
resolvedSymbol?: Symbol; // Cached name resolution result
flags?: NodeCheckFlags; // Set of flags specific to Node
enumMemberValue?: number; // Constant value of enum member
resolvedType?: Type; // Cached type of type node
resolvedSignature?: Signature; // Cached signature of signature node or call expression
resolvedSymbol?: Symbol; // Cached name resolution result
flags?: NodeCheckFlags; // Set of flags specific to Node
enumMemberValue?: number; // Constant value of enum member
isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list
isVisible?: boolean; // Is this node visible
localModuleName?: string; // Local name for module instance
isVisible?: boolean; // Is this node visible
localModuleName?: string; // Local name for module instance
assignmentChecks?: Map<boolean>; // Cache of assignment checks
}
export enum TypeFlags {
@@ -871,13 +901,14 @@ module ts {
Interface = 0x00000800, // Interface
Reference = 0x00001000, // Generic type reference
Tuple = 0x00002000, // Tuple
Anonymous = 0x00004000, // Anonymous
FromSignature = 0x00008000, // Created for signature assignment check
Union = 0x00004000, // Union
Anonymous = 0x00008000, // Anonymous
FromSignature = 0x00010000, // Created for signature assignment check
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
StringLike = String | StringLiteral,
NumberLike = Number | Enum,
ObjectType = Class | Interface | Reference | Tuple | Anonymous
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
}
// Properties common to all types
@@ -900,12 +931,6 @@ module ts {
// Object types (TypeFlags.ObjectType)
export interface ObjectType extends Type { }
export interface ApparentType extends Type {
// This property is not used. It is just to make the type system think ApparentType
// is a strict subtype of Type.
_apparentTypeBrand: any;
}
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
export interface InterfaceType extends ObjectType {
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
@@ -935,8 +960,13 @@ module ts {
baseArrayType: TypeReference; // Array<T> where T is best common type of element types
}
// Resolved object type
export interface ResolvedObjectType extends ObjectType {
export interface UnionType extends Type {
types: Type[]; // Constituent types
resolvedProperties: SymbolTable; // Cache of resolved properties
}
// Resolved object or union type
export interface ResolvedType extends ObjectType, UnionType {
members: SymbolTable; // Properties by name
properties: Symbol[]; // Properties
callSignatures: Signature[]; // Call signatures of type
@@ -967,6 +997,7 @@ module ts {
hasStringLiterals: boolean; // True if specialized
target?: Signature; // Instantiation target
mapper?: TypeMapper; // Instantiation mapper
unionSignatures?: Signature[]; // Underlying signatures of a union signature
erasedSignatureCache?: Signature; // Erased version of signature (deferred)
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
}
@@ -981,9 +1012,11 @@ module ts {
}
export interface InferenceContext {
typeParameters: TypeParameter[];
inferences: Type[][];
inferredTypes: Type[];
typeParameters: TypeParameter[]; // Type parameters for which inferences are made
inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType)
inferenceCount: number; // Incremented for every inference made (whether new or not)
inferences: Type[][]; // Inferences made for each type parameter
inferredTypes: Type[]; // Inferred type for each type parameter
}
export interface DiagnosticMessage {
@@ -1212,32 +1245,7 @@ module ts {
tab = 0x09, // \t
verticalTab = 0x0B, // \v
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
}
export interface CancellationToken {
isCancellationRequested(): boolean;
}
+13 -56
View File
@@ -61,9 +61,11 @@ class CompilerBaselineRunner extends RunnerBase {
var otherFiles: { unitName: string; content: string }[];
var harnessCompiler: Harness.Compiler.HarnessCompiler;
var declToBeCompiled: { unitName: string; content: string }[] = [];
var declOtherFiles: { unitName: string; content: string }[] = [];
var declResult: Harness.Compiler.CompilerResult;
var declFileCompilationResult: {
declInputFiles: { unitName: string; content: string }[];
declOtherFiles: { unitName: string; content: string }[];
declResult: Harness.Compiler.CompilerResult;
};
var createNewInstance = false;
@@ -147,9 +149,7 @@ class CompilerBaselineRunner extends RunnerBase {
toBeCompiled = undefined;
otherFiles = undefined;
harnessCompiler = undefined;
declToBeCompiled = undefined;
declOtherFiles = undefined;
declResult = undefined;
declFileCompilationResult = undefined;
});
function getByteOrderMarkText(file: Harness.Compiler.GeneratedFile): string {
@@ -173,61 +173,18 @@ class CompilerBaselineRunner extends RunnerBase {
// Source maps?
it('Correct sourcemap content for ' + fileName, () => {
if (result.sourceMapRecord) {
if (options.sourceMap) {
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => {
return result.sourceMapRecord;
return result.getSourceMapRecord();
});
}
});
// Compile .d.ts files
it('Correct compiler generated.d.ts for ' + fileName, () => {
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) {
throw new Error('There were no errors and declFiles generated did not match number of js files generated');
}
// if the .d.ts is non-empty, confirm it compiles correctly as well
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) {
function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) {
if (Harness.Compiler.isDTS(file.unitName)) {
dtsFiles.push(file);
}
else {
var declFile = findResultCodeFile(file.unitName);
// Look if there is --out file corresponding to this ts file
if (!declFile && options.out) {
declFile = findResultCodeFile(options.out);
if (!declFile || findUnit(declFile.fileName, declToBeCompiled) ||
findUnit(declFile.fileName, declOtherFiles)) {
return;
}
}
if (declFile) {
dtsFiles.push({ unitName: declFile.fileName, content: declFile.code });
return;
}
}
function findResultCodeFile(fileName: string) {
return ts.forEach(result.declFilesCode,
declFile => declFile.fileName === (fileName.substr(0, fileName.length - ".ts".length) + ".d.ts")
? declFile : undefined);
}
function findUnit(fileName: string, units: { unitName: string; content: string }[]) {
return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined);
}
}
ts.forEach(toBeCompiled, file => addDtsFile(file, declToBeCompiled));
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
harnessCompiler.compileFiles(declToBeCompiled, declOtherFiles, function (compileResult) {
declResult = compileResult;
}, function (settings) {
harnessCompiler.setCompilerSettings(tcSettings);
});
}
declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) {
harnessCompiler.setCompilerSettings(tcSettings);
}, options);
});
@@ -267,10 +224,10 @@ class CompilerBaselineRunner extends RunnerBase {
}
}
if (declResult && declResult.errors.length) {
if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) {
jsCode += '\r\n\r\n//// [DtsFileErrors]\r\n';
jsCode += '\r\n\r\n';
jsCode += getErrorBaseline(declToBeCompiled, declOtherFiles, declResult);
jsCode += getErrorBaseline(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles, declFileCompilationResult.declResult);
}
if (jsCode.length > 0) {
+31 -7
View File
@@ -146,7 +146,7 @@ module FourSlash {
function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings {
var settings: ts.CompilationSettings = {};
// Convert all property in globalOptions into ts.CompilationSettings
// Convert all property in globalOptions into ts.CompilationSettings
for (var prop in globalOptions) {
if (globalOptions.hasOwnProperty(prop)) {
switch (prop) {
@@ -1610,9 +1610,11 @@ module FourSlash {
Harness.IO.log(this.getNameOrDottedNameSpan(pos));
}
private verifyClassifications(expected: { classificationType: string; text: string }[], actual: ts.ClassifiedSpan[]) {
private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) {
if (actual.length !== expected.length) {
this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + ', but was ' + actual.length);
this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length +
', but was ' + actual.length +
jsonMismatchString());
}
for (var i = 0; i < expected.length; i++) {
@@ -1623,17 +1625,38 @@ module FourSlash {
if (expectedType !== actualClassification.classificationType) {
this.raiseError('verifyClassifications failed - expected classifications type to be ' +
expectedType + ', but was ' +
actualClassification.classificationType);
actualClassification.classificationType +
jsonMismatchString());
}
var expectedSpan = expectedClassification.textSpan;
var actualSpan = actualClassification.textSpan;
if (expectedSpan) {
var expectedLength = expectedSpan.end - expectedSpan.start;
if (expectedSpan.start !== actualSpan.start() || expectedLength !== actualSpan.length()) {
this.raiseError("verifyClassifications failed - expected span of text to be " +
"{start=" + expectedSpan.start + ", length=" + expectedLength + "}, but was " +
"{start=" + actualSpan.start() + ", length=" + actualSpan.length() + "}" +
jsonMismatchString());
}
}
var actualText = this.activeFile.content.substr(actualSpan.start(), actualSpan.length());
if (expectedClassification.text !== actualText) {
this.raiseError('verifyClassifications failed - expected classificatied text to be ' +
this.raiseError('verifyClassifications failed - expected classified text to be ' +
expectedClassification.text + ', but was ' +
actualText);
actualText +
jsonMismatchString());
}
}
function jsonMismatchString() {
return sys.newLine +
"expected: '" + sys.newLine + JSON.stringify(expected, (k,v) => v, 2) + "'" + sys.newLine +
"actual: '" + sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'";
}
}
public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) {
@@ -1984,7 +2007,8 @@ module FourSlash {
var newlinePos = text.indexOf('\n');
if (newlinePos === -1) {
return text;
} else {
}
else {
if (text.charAt(newlinePos - 1) === '\r') {
newlinePos--;
}
+86 -13
View File
@@ -139,6 +139,7 @@ module Harness {
deleteFile(filename: string): void;
listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[];
log(text: string): void;
getMemoryUsage? (): number;
}
module IOImpl {
@@ -275,6 +276,13 @@ module Harness {
return filesInFolder(path);
}
export var getMemoryUsage: typeof IO.getMemoryUsage = () => {
if (global.gc) {
global.gc();
}
return process.memoryUsage().heapUsed;
}
}
export module Network {
@@ -804,15 +812,81 @@ module Harness {
});
this.lastErrors = errors;
var result = new CompilerResult(fileOutputs, errors, []);
// Covert the source Map data into the baseline
result.updateSourceMapRecord(program, emitResult ? emitResult.sourceMaps : undefined);
var result = new CompilerResult(fileOutputs, errors, program, sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined);
onComplete(result, checker);
// reset what newline means in case the last test changed it
sys.newLine = '\r\n';
return options;
}
public compileDeclarationFiles(inputFiles: { unitName: string; content: string; }[],
otherFiles: { unitName: string; content: string; }[],
result: CompilerResult,
settingsCallback?: (settings: ts.CompilerOptions) => void,
options?: ts.CompilerOptions) {
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) {
throw new Error('There were no errors and declFiles generated did not match number of js files generated');
}
// if the .d.ts is non-empty, confirm it compiles correctly as well
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) {
var declInputFiles: { unitName: string; content: string }[] = [];
var declOtherFiles: { unitName: string; content: string }[] = [];
var declResult: Harness.Compiler.CompilerResult;
ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) {
declResult = compileResult;
}, settingsCallback, options);
return { declInputFiles: declInputFiles, declOtherFiles: declOtherFiles, declResult: declResult };
}
function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) {
if (isDTS(file.unitName)) {
dtsFiles.push(file);
}
else if (isTS(file.unitName)) {
var declFile = findResultCodeFile(file.unitName);
if (!findUnit(declFile.fileName, declInputFiles) && !findUnit(declFile.fileName, declOtherFiles)) {
dtsFiles.push({ unitName: declFile.fileName, content: declFile.code });
}
}
function findResultCodeFile(fileName: string) {
var dTsFileName = ts.forEach(result.program.getSourceFiles(), sourceFile => {
if (sourceFile.filename === fileName) {
// Is this file going to be emitted separately
var sourceFileName: string;
if (ts.isExternalModule(sourceFile) || !options.out) {
if (options.outDir) {
var sourceFilePath = ts.getNormalizedPathFromPathComponents(ts.getNormalizedPathComponents(sourceFile.filename, result.currentDirectoryForProgram));
sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), "");
sourceFileName = ts.combinePaths(options.outDir, sourceFilePath);
}
else {
sourceFileName = sourceFile.filename;
}
}
else {
// Goes to single --out file
sourceFileName = options.out;
}
return ts.removeFileExtension(sourceFileName) + ".d.ts";
}
});
return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined);
}
function findUnit(fileName: string, units: { unitName: string; content: string; }[]) {
return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined);
}
}
}
}
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
@@ -948,10 +1022,6 @@ module Harness {
}
*/
/** Recreate the harness compiler instance to its default settings */
export function recreate(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) {
}
/** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a test case (i.e., describe/it) */
var harnessCompiler: HarnessCompiler;
@@ -991,6 +1061,10 @@ module Harness {
return str.substr(str.length - end.length) === end;
}
export function isTS(fileName: string) {
return stringEndsWith(fileName, '.ts');
}
export function isDTS(fileName: string) {
return stringEndsWith(fileName, '.d.ts');
}
@@ -1009,10 +1083,10 @@ module Harness {
public errors: HarnessDiagnostic[] = [];
public declFilesCode: GeneratedFile[] = [];
public sourceMaps: GeneratedFile[] = [];
public sourceMapRecord: string;
/** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], sourceMapRecordLines: string[]) {
constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program,
public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) {
var lines: string[] = [];
fileResults.forEach(emittedFile => {
@@ -1030,12 +1104,11 @@ module Harness {
});
this.errors = errors;
this.sourceMapRecord = sourceMapRecordLines.join('\r\n');
}
public updateSourceMapRecord(program: ts.Program, sourceMapData: ts.SourceMapData[]) {
if (sourceMapData) {
this.sourceMapRecord = Harness.SourceMapRecoder.getSourceMapRecord(sourceMapData, program, this.files);
public getSourceMapRecord() {
if (this.sourceMapData) {
return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files);
}
}
+10
View File
@@ -419,6 +419,16 @@ class ProjectRunner extends RunnerBase {
// })
//});
}
after(() => {
// Mocha holds onto the closure environment of the describe callback even after the test is done.
// Therefore we have to clean out large objects after the test is done.
nodeCompilerResult = undefined;
amdCompilerResult = undefined;
testCase = undefined;
testFileText = undefined;
testCaseJustName = undefined;
});
});
}
}
-7
View File
@@ -18,7 +18,6 @@
// ///<reference path='fourslashRunner.ts' />
/// <reference path='projectsRunner.ts' />
/// <reference path='rwcRunner.ts' />
/// <reference path='unittestrunner.ts' />
function runTests(runners: RunnerBase[]) {
if (reverse) {
@@ -67,9 +66,6 @@ if (testConfigFile !== '') {
case 'fourslash-generated':
runners.push(new GeneratedFourslashRunner());
break;
case 'unittests':
runners.push(new UnitTestRunner());
break;
case 'rwc':
runners.push(new RWCRunner());
break;
@@ -93,9 +89,6 @@ if (runners.length === 0) {
// language services
runners.push(new FourslashRunner());
//runners.push(new GeneratedFourslashRunner());
// unittests
runners.push(new UnitTestRunner());
}
sys.newLine = '\r\n';
+138 -111
View File
@@ -46,144 +46,171 @@ module RWC {
}
export function runRWCTest(jsonPath: string) {
var harnessCompiler = Harness.Compiler.getCompiler();
var opts: ts.ParsedCommandLine;
describe("Testing a RWC project: " + jsonPath, () => {
var inputFiles: { unitName: string; content: string; }[] = [];
var otherFiles: { unitName: string; content: string; }[] = [];
var compilerResult: Harness.Compiler.CompilerResult;
var compilerOptions: ts.CompilerOptions;
var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' };
var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2];
// Compile .d.ts files
var declFileCompilationResult: {
declInputFiles: { unitName: string; content: string }[];
declOtherFiles: { unitName: string; content: string }[];
declResult: Harness.Compiler.CompilerResult;
};
var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath));
var errors = '';
it('has parsable options', () => {
runWithIOLog(ioLog, () => {
opts = ts.parseCommandLine(ioLog.arguments);
assert.equal(opts.errors.length, 0);
});
});
var inputFiles: { unitName: string; content: string; }[] = [];
var otherFiles: { unitName: string; content: string; }[] = [];
var compilerResult: Harness.Compiler.CompilerResult;
it('can compile', () => {
runWithIOLog(ioLog, () => {
harnessCompiler.reset();
// Load the files
ts.forEach(opts.filenames, fileName => {
inputFiles.push(getHarnessCompilerInputUnit(fileName));
});
if (!opts.options.noLib) {
// Find the lib.d.ts file in the input file and add it to the input files list
var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined);
if (libFile) {
inputFiles.push(getHarnessCompilerInputUnit(libFile));
}
}
ts.forEach(ioLog.filesRead, fileRead => {
var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path));
var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath);
if (!inInputList) {
// Add the file to other files
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
}
});
// do not use lib since we already read it in above
opts.options.noLib = true;
// Emit the results
harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => {
compilerResult = compileResult;
}, /*settingsCallback*/ undefined, opts.options);
after(() => {
// Mocha holds onto the closure environment of the describe callback even after the test is done.
// Therefore we have to clean out large objects after the test is done.
inputFiles = undefined;
otherFiles = undefined;
compilerResult = undefined;
compilerOptions = undefined;
baselineOpts = undefined;
baseName = undefined;
declFileCompilationResult = undefined;
});
function getHarnessCompilerInputUnit(fileName: string) {
var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName));
try {
var content = sys.readFile(resolvedPath);
it('can compile', () => {
var harnessCompiler = Harness.Compiler.getCompiler();
var opts: ts.ParsedCommandLine;
var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath));
runWithIOLog(ioLog, () => {
opts = ts.parseCommandLine(ioLog.arguments);
assert.equal(opts.errors.length, 0);
});
runWithIOLog(ioLog, () => {
harnessCompiler.reset();
// Load the files
ts.forEach(opts.filenames, fileName => {
inputFiles.push(getHarnessCompilerInputUnit(fileName));
});
if (!opts.options.noLib) {
// Find the lib.d.ts file in the input file and add it to the input files list
var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined);
if (libFile) {
inputFiles.push(getHarnessCompilerInputUnit(libFile));
}
}
ts.forEach(ioLog.filesRead, fileRead => {
var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path));
var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath);
if (!inInputList) {
// Add the file to other files
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
}
});
// do not use lib since we already read it in above
opts.options.noLib = true;
// Emit the results
compilerOptions = harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => {
compilerResult = compileResult;
}, /*settingsCallback*/ undefined, opts.options);
});
function getHarnessCompilerInputUnit(fileName: string) {
var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName));
try {
var content = sys.readFile(resolvedPath);
}
catch (e) {
// Leave content undefined.
}
return { unitName: resolvedPath, content: content };
}
catch (e) {
// Leave content undefined.
}
return { unitName: resolvedPath, content: content };
}
});
});
// Baselines
var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' };
var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2];
// Baselines
it('Correct compiler generated.d.ts', () => {
declFileCompilationResult = Harness.Compiler.getCompiler().compileDeclarationFiles(inputFiles, otherFiles, compilerResult, /*settingscallback*/ undefined, compilerOptions);
});
it('has the expected emitted code', () => {
Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => {
return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s));
}, false, baselineOpts);
});
it('has the expected declaration file content', () => {
Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => {
if (compilerResult.errors.length || !compilerResult.declFilesCode.length) {
return null;
}
return collateOutputs(compilerResult.declFilesCode);
}, false, baselineOpts);
});
it('has the expected source maps', () => {
Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => {
if (!compilerResult.sourceMaps.length) {
return null;
}
return collateOutputs(compilerResult.sourceMaps);
}, false, baselineOpts);
});
it('has correct source map record', () => {
if (compilerResult.sourceMapRecord) {
Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => {
return compilerResult.sourceMapRecord;
it('has the expected emitted code', () => {
Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => {
return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s));
}, false, baselineOpts);
}
});
});
it('has the expected errors', () => {
Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => {
if (compilerResult.errors.length === 0) {
return null;
it('has the expected declaration file content', () => {
Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => {
if (compilerResult.errors.length || !compilerResult.declFilesCode.length) {
return null;
}
return collateOutputs(compilerResult.declFilesCode);
}, false, baselineOpts);
});
it('has the expected source maps', () => {
Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => {
if (!compilerResult.sourceMaps.length) {
return null;
}
return collateOutputs(compilerResult.sourceMaps);
}, false, baselineOpts);
});
//it('has correct source map record', () => {
// if (compilerOptions.sourceMap) {
// Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => {
// return compilerResult.getSourceMapRecord();
// }, false, baselineOpts);
// }
//});
it('has the expected errors', () => {
Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => {
if (compilerResult.errors.length === 0) {
return null;
}
return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors);
}, false, baselineOpts);
});
it('has no errors in generated declaration files', () => {
if (compilerOptions.declaration && !compilerResult.errors.length) {
Harness.Baseline.runBaseline('has no errors in generated declaration files', baseName + '.dts.errors.txt', () => {
if (declFileCompilationResult.declResult.errors.length === 0) {
return null;
}
return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) +
sys.newLine + sys.newLine +
Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors);
}, false, baselineOpts);
}
});
return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors);
}, false, baselineOpts);
// TODO: Type baselines (need to refactor out from compilerRunner)
});
// TODO: Type baselines (need to refactor out from compilerRunner)
}
}
class RWCRunner extends RunnerBase {
private runnerPath = "tests/runners/rwc";
private sourcePath = "tests/cases/rwc/";
private harnessCompiler: Harness.Compiler.HarnessCompiler;
private static sourcePath = "tests/cases/rwc/";
/** Setup the runner's tests so that they are ready to be executed by the harness
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
*/
public initializeTests(): void {
// Recreate the compiler with the default lib
Harness.Compiler.recreate({ useMinimalDefaultLib: false, noImplicitAny: false });
this.harnessCompiler = Harness.Compiler.getCompiler();
// Read in and evaluate the test list
var testList = Harness.IO.listFiles(this.sourcePath, /.+\.json$/);
var testList = Harness.IO.listFiles(RWCRunner.sourcePath, /.+\.json$/);
for (var i = 0; i < testList.length; i++) {
this.runTest(testList[i]);
}
}
private runTest(jsonFilename: string) {
describe("Testing a RWC project: " + jsonFilename, () => {
RWC.runRWCTest(jsonFilename);
});
RWC.runRWCTest(jsonFilename);
}
}
-73
View File
@@ -1,73 +0,0 @@
///<reference path="harness.ts" />
///<reference path="runnerbase.ts" />
class UnitTestRunner extends RunnerBase {
constructor() {
super();
}
public initializeTests() {
this.tests = this.enumerateFiles('tests/cases/unittests/services', /\.ts/i);
var outfile = new Harness.Compiler.WriterAggregator()
var outerr = new Harness.Compiler.WriterAggregator();
// note this is running immediately to generate tests to be run later inside describe/it
// need a fresh instance so that the previous runner's last test is not hanging around
var harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false });
var toBeAdded = this.tests.map(test => {
return { unitName: test, content: Harness.IO.readFile(test) }
});
harnessCompiler.addInputFiles(toBeAdded);
harnessCompiler.setCompilerOptions({ noResolve: true });
var stdout = new Harness.Compiler.EmitterIOHost();
var emitDiagnostics = harnessCompiler.emitAll(stdout);
var results = stdout.toArray();
var lines: string[] = [];
results.forEach(v => lines = lines.concat(v.file.lines));
var code = lines.join("\n")
var nodeContext: any = undefined;
if (Utils.getExecutionEnvironment() === Utils.ExecutionEnvironment.Node) {
nodeContext = {
require: require,
process: process,
describe: describe,
it: it,
assert: assert,
beforeEach: beforeEach,
afterEach: afterEach,
before: before,
after: after,
Harness: Harness,
IO: Harness.IO,
ts: ts,
TypeScript: TypeScript
// FourSlash: FourSlash
};
}
describe("Setup compiler for compiler unittests", () => {
// ensures a clean compiler instance when tests are eventually executed following this describe block
harnessCompiler = Harness.Compiler.getCompiler({
useExistingInstance: false,
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
});
});
// this generated code is a series of top level describe/it blocks that will run in between the setup and cleanup blocks in this file
Utils.evalFile(code, "generated_test_code.js", nodeContext);
describe("Cleanup after unittests", () => {
var harnessCompiler = Harness.Compiler.getCompiler({
useExistingInstance: false,
optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false }
});
});
// note this runs immediately (ie before this same code in the describe block above)
// to make sure the next runner doesn't include the previous one's stuff
harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false });
}
}
@@ -476,8 +476,6 @@ module TypeScript {
//}
}
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
var funcSignature = funcPullDecl.getSignatureSymbol(this.semanticInfoChain);
this.emitDeclarationComments(funcDecl);
this.emitIndent();
@@ -603,11 +601,6 @@ module TypeScript {
private emitConstructSignature(funcDecl: ConstructSignatureSyntax) {
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
var start = new Date().getTime();
var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl);
TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start;
this.emitDeclarationComments(funcDecl);
this.emitIndent();
@@ -633,11 +626,6 @@ module TypeScript {
private emitMethodSignature(funcDecl: MethodSignatureSyntax) {
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
var start = new Date().getTime();
var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl);
TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start;
this.emitDeclarationComments(funcDecl);
this.emitIndent();
@@ -817,7 +805,6 @@ module TypeScript {
var parameter = funcDecl.callSignature.parameterList.parameters[i];
var parameterDecl = this.semanticInfoChain.getDeclForAST(parameter);
if (hasFlag(parameterDecl.flags, PullElementFlags.PropertyParameter)) {
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
this.emitDeclarationComments(parameter);
this.declFile.Write(this.getIndentString());
this.emitClassElementModifiers(parameter.modifiers);
@@ -838,7 +825,6 @@ module TypeScript {
var className = classDecl.identifier.text();
this.emitDeclarationComments(classDecl);
var classPullDecl = this.semanticInfoChain.getDeclForAST(classDecl);
this.emitDeclFlags(classDecl, "class");
this.declFile.Write(className);
@@ -934,7 +920,6 @@ module TypeScript {
var interfaceName = interfaceDecl.identifier.text();
this.emitDeclarationComments(interfaceDecl);
var interfacePullDecl = this.semanticInfoChain.getDeclForAST(interfaceDecl);
this.emitDeclFlags(interfaceDecl, "interface");
this.declFile.Write(interfaceName);
@@ -980,7 +965,6 @@ module TypeScript {
}
this.emitDeclarationComments(moduleDecl);
var modulePullDecl = this.semanticInfoChain.getDeclForAST(moduleDecl);
this.emitDeclFlags(moduleDecl, "enum");
this.declFile.WriteLine(moduleDecl.identifier.text() + " {");
+1 -5
View File
@@ -512,7 +512,7 @@ module TypeScript {
for (var i = 0, n = fileNames.length; i < n; i++) {
var fileName = fileNames[i];
var document = this.getDocument(fileNames[i]);
var document = this.getDocument(fileName);
sharedEmitter = this._emitDocumentDeclarations(document, emitOptions,
file => emitOutput.outputFiles.push(file), sharedEmitter);
@@ -578,7 +578,6 @@ module TypeScript {
var sourceUnit = document.sourceUnit();
Debug.assert(this._shouldEmit(document));
var typeScriptFileName = document.fileName;
if (!emitter) {
var javaScriptFileName = this.mapOutputFileName(document, emitOptions, TypeScriptCompiler.mapToJSFileName);
var outFile = new TextWriter(javaScriptFileName, this.writeByteOrderMarkForDocument(document), OutputFileType.JavaScript);
@@ -799,8 +798,6 @@ module TypeScript {
}
private extractResolutionContextFromAST(resolver: PullTypeResolver, ast: ISyntaxElement, document: Document, propagateContextualTypes: boolean): { ast: ISyntaxElement; enclosingDecl: PullDecl; resolutionContext: PullTypeResolutionContext; inContextuallyTypedAssignment: boolean; inWithBlock: boolean; } {
var scriptName = document.fileName;
var enclosingDecl: PullDecl = null;
var enclosingDeclAST: ISyntaxElement = null;
var inContextuallyTypedAssignment = false;
@@ -981,7 +978,6 @@ module TypeScript {
case SyntaxKind.ReturnStatement:
if (propagateContextualTypes) {
var returnStatement = <ReturnStatementSyntax>current;
var contextualType: PullTypeSymbol = null;
if (enclosingDecl && (enclosingDecl.kind & PullElementKind.SomeFunction)) {
-6
View File
@@ -7,12 +7,6 @@ module TypeScript {
}
export function integerMultiplyLow32Bits(n1: number, n2: number): number {
var n1Low16 = n1 & 0x0000ffff;
var n1High16 = n1 >>> 16;
var n2Low16 = n2 & 0x0000ffff;
var n2High16 = n2 >>> 16;
var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0;
return resultLow32;
}
+299 -202
View File
@@ -580,7 +580,7 @@ module ts {
return this.checker.getPropertyOfType(this, propertyName);
}
getApparentProperties(): Symbol[] {
return this.checker.getAugmentedPropertiesOfApparentType(this);
return this.checker.getAugmentedPropertiesOfType(this);
}
getCallSignatures(): Signature[] {
return this.checker.getSignaturesOfType(this, SignatureKind.Call);
@@ -999,12 +999,37 @@ module ts {
containerKind: string;
containerName: string;
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
}
export interface SymbolDisplayPart {
text: string;
kind: string;
}
export interface QuickInfo {
kind: string;
kindModifiers: string;
@@ -1310,7 +1335,12 @@ module ts {
resetWriter();
return {
displayParts: () => displayParts,
writeKind: writeKind,
writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword),
writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator),
writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation),
writeSpace: text => writeKind(text, SymbolDisplayPartKind.space),
writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral),
writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName),
writeSymbol: writeSymbol,
writeLine: writeLine,
increaseIndent: () => { indent++; },
@@ -1434,7 +1464,7 @@ module ts {
}
}
function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] {
export function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] {
writeDisplayParts(displayPartWriter);
var result = displayPartWriter.displayParts();
displayPartWriter.clear();
@@ -1443,19 +1473,19 @@ module ts {
export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
return mapToDisplayParts(writer => {
typechecker.writeType(type, writer, enclosingDeclaration, flags);
typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
});
}
export function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[] {
return mapToDisplayParts(writer => {
typeChecker.writeSymbol(symbol, writer, enclosingDeclaration, meaning, flags);
typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags);
});
}
function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]{
return mapToDisplayParts(writer => {
typechecker.writeSignature(signature, writer, enclosingDeclaration, flags);
typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
});
}
@@ -2287,7 +2317,7 @@ module ts {
return undefined;
}
function createCompletionEntry(symbol: Symbol): CompletionEntry {
function createCompletionEntry(symbol: Symbol, typeChecker: TypeChecker): CompletionEntry {
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
// We would like to only show things that can be added after a dot, so for instance numeric properties can
// not be accessed with a dot (a.1 <- invalid)
@@ -2302,7 +2332,7 @@ module ts {
// We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
return {
name: displayName,
kind: getSymbolKind(symbol, SemanticMeaning.All),
kind: getSymbolKind(symbol, typeChecker),
kindModifiers: getSymbolModifiers(symbol)
};
}
@@ -2310,7 +2340,7 @@ module ts {
function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) {
function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void {
forEach(symbols, symbol => {
var entry = createCompletionEntry(symbol);
var entry = createCompletionEntry(symbol, session.typeChecker);
if (entry && !lookUp(session.symbols, entry.name)) {
session.entries.push(entry);
session.symbols[entry.name] = symbol;
@@ -2567,10 +2597,9 @@ module ts {
}
var type = typeInfoResolver.getTypeOfNode(node);
var apparentType = type && typeInfoResolver.getApparentType(type);
if (apparentType) {
if (type) {
// Filter private properties
forEach(apparentType.getApparentProperties(), symbol => {
forEach(type.getApparentProperties(), symbol => {
if (typeInfoResolver.isValidPropertyAccess(<PropertyAccess>(node.parent), symbol.name)) {
symbols.push(symbol);
}
@@ -2638,7 +2667,7 @@ module ts {
if (symbol) {
var type = session.typeChecker.getTypeOfSymbol(symbol);
Debug.assert(type, "Could not find type for symbol");
var completionEntry = createCompletionEntry(symbol);
var completionEntry = createCompletionEntry(symbol, session.typeChecker);
// TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind'
// which is permissible given that it is backwards compatible; but really we should consider
// passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
@@ -2687,20 +2716,16 @@ module ts {
}
}
function getSymbolKind(symbol: Symbol, meaningAtLocation: SemanticMeaning): string {
var flags = typeInfoResolver.getRootSymbol(symbol).getFlags();
// TODO(drosen): use contextual SemanticMeaning.
function getSymbolKind(symbol: Symbol, typeResolver: TypeChecker): string {
var flags = symbol.getFlags();
if (flags & SymbolFlags.Class) return ScriptElementKind.classElement;
if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement;
// The following should only apply if encountered at a type position,
// and need to have precedence over other meanings if this is the case.
if (meaningAtLocation & SemanticMeaning.Type) {
if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement;
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
}
var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags);
if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement;
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver);
if (result === ScriptElementKind.unknown) {
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
if (flags & SymbolFlags.EnumMember) return ScriptElementKind.variableElement;
@@ -2710,23 +2735,40 @@ module ts {
return result;
}
function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags) {
function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags, typeResolver: TypeChecker) {
if (typeResolver.isUndefinedSymbol(symbol)) {
return ScriptElementKind.variableElement;
}
if (typeResolver.isArgumentsSymbol(symbol)) {
return ScriptElementKind.localVariableElement;
}
if (flags & SymbolFlags.Variable) {
if (isFirstDeclarationOfSymbolParameter(symbol)) {
return ScriptElementKind.parameterElement;
}
return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement;
}
if (flags & SymbolFlags.Undefined) {
return ScriptElementKind.variableElement;
}
if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement;
if (flags & SymbolFlags.GetAccessor) return ScriptElementKind.memberGetAccessorElement;
if (flags & SymbolFlags.SetAccessor) return ScriptElementKind.memberSetAccessorElement;
if (flags & SymbolFlags.Method) return ScriptElementKind.memberFunctionElement;
if (flags & SymbolFlags.Property) return ScriptElementKind.memberVariableElement;
if (flags & SymbolFlags.Constructor) return ScriptElementKind.constructorImplementationElement;
if (flags & SymbolFlags.Property) {
if (flags & SymbolFlags.UnionProperty) {
return forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => {
var rootSymbolFlags = rootSymbol.getFlags();
if (rootSymbolFlags & SymbolFlags.Property) {
return ScriptElementKind.memberVariableElement;
}
if (rootSymbolFlags & SymbolFlags.GetAccessor) return ScriptElementKind.memberVariableElement;
if (rootSymbolFlags & SymbolFlags.SetAccessor) return ScriptElementKind.memberVariableElement;
Debug.assert(rootSymbolFlags & SymbolFlags.Method);
}) || ScriptElementKind.memberFunctionElement;
}
return ScriptElementKind.memberVariableElement;
}
return ScriptElementKind.unknown;
}
@@ -2778,19 +2820,15 @@ module ts {
semanticMeaning = getMeaningFromLocation(location)) {
var displayParts: SymbolDisplayPart[] = [];
var documentation: SymbolDisplayPart[];
var symbolFlags = typeResolver.getRootSymbol(symbol).flags;
var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags);
var symbolFlags = symbol.flags;
var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver);
var hasAddedSymbolInfo: boolean;
// Class at constructor site need to be shown as constructor apart from property,method, vars
if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Signature || symbolFlags & SymbolFlags.Class) {
if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Import) {
// If it is accessor they are allowed only if location is at name of the accessor
if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) {
symbolKind = ScriptElementKind.memberVariableElement;
}
else if (symbol.name === "undefined") {
// undefined is symbol and not property
symbolKind = ScriptElementKind.variableElement;
}
var type = typeResolver.getTypeOfSymbol(symbol);
if (type) {
@@ -2833,6 +2871,18 @@ module ts {
symbolKind = ScriptElementKind.constructorImplementationElement;
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
}
else if (symbolFlags & SymbolFlags.Import) {
symbolKind = ScriptElementKind.alias;
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(textPart(symbolKind));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
if (useConstructSignatures) {
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
displayParts.push(spacePart());
}
addFullSymbolName(symbol);
}
else {
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
}
@@ -2893,27 +2943,27 @@ module ts {
if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) {
displayParts.push(keywordPart(SyntaxKind.ClassKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
addFullSymbolName(symbol);
writeTypeParametersOfSymbol(symbol, sourceFile);
}
if ((symbolFlags & SymbolFlags.Interface) && (semanticMeaning & SemanticMeaning.Type)) {
addNewLineIfDisplayPartsExist();
displayParts.push(keywordPart(SyntaxKind.InterfaceKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
addFullSymbolName(symbol);
writeTypeParametersOfSymbol(symbol, sourceFile);
}
if (symbolFlags & SymbolFlags.Enum) {
addNewLineIfDisplayPartsExist();
displayParts.push(keywordPart(SyntaxKind.EnumKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
addFullSymbolName(symbol);
}
if (symbolFlags & SymbolFlags.Module) {
addNewLineIfDisplayPartsExist();
displayParts.push(keywordPart(SyntaxKind.ModuleKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
addFullSymbolName(symbol);
}
if ((symbolFlags & SymbolFlags.TypeParameter) && (semanticMeaning & SemanticMeaning.Type)) {
addNewLineIfDisplayPartsExist();
@@ -2921,13 +2971,13 @@ module ts {
displayParts.push(textPart("type parameter"));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration));
addFullSymbolName(symbol);
displayParts.push(spacePart());
displayParts.push(keywordPart(SyntaxKind.InKeyword));
displayParts.push(spacePart());
if (symbol.parent) {
// Class/Interface type parameter
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol.parent, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments))
addFullSymbolName(symbol.parent, enclosingDeclaration);
writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration);
}
else {
@@ -2939,7 +2989,7 @@ module ts {
displayParts.push(spacePart());
}
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, signatureDeclaration.symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments))
addFullSymbolName(signatureDeclaration.symbol);
}
displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
}
@@ -2959,24 +3009,43 @@ module ts {
}
if (symbolFlags & SymbolFlags.Import) {
addNewLineIfDisplayPartsExist();
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(textPart("alias"));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
addFullSymbolName(symbol);
displayParts.push(spacePart());
displayParts.push(punctuationPart(SyntaxKind.EqualsToken));
displayParts.push(spacePart());
ts.forEach(symbol.declarations, declaration => {
if (declaration.kind === SyntaxKind.ImportDeclaration) {
var importDeclaration = <ImportDeclaration>declaration;
if (importDeclaration.externalModuleName) {
displayParts.push(keywordPart(SyntaxKind.RequireKeyword));
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(displayPart(getTextOfNode(importDeclaration.externalModuleName), SymbolDisplayPartKind.stringLiteral));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
}
else {
var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName);
addFullSymbolName(internalAliasSymbol, enclosingDeclaration);
}
return true;
}
});
}
if (!hasAddedSymbolInfo) {
if (symbolKind !== ScriptElementKind.unknown) {
if (type) {
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
// For properties, variables and local vars: show the type
if (symbolKind === ScriptElementKind.memberVariableElement ||
symbolFlags & SymbolFlags.Variable) {
symbolFlags & SymbolFlags.Variable ||
symbolKind === ScriptElementKind.localVariableElement) {
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
displayParts.push(spacePart());
// If the type is type parameter, format it specially
if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) {
var typeParameterParts = mapToDisplayParts(writer => {
typeResolver.writeTypeParameter(<TypeParameter>type, writer, enclosingDeclaration);
typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(<TypeParameter>type, writer, enclosingDeclaration);
});
displayParts.push.apply(displayParts, typeParameterParts);
}
@@ -2988,14 +3057,15 @@ module ts {
symbolFlags & SymbolFlags.Method ||
symbolFlags & SymbolFlags.Constructor ||
symbolFlags & SymbolFlags.Signature ||
symbolFlags & SymbolFlags.Accessor) {
symbolFlags & SymbolFlags.Accessor ||
symbolKind === ScriptElementKind.memberFunctionElement) {
var allSignatures = type.getCallSignatures();
addSignatureDisplayParts(allSignatures[0], allSignatures);
}
}
}
else {
symbolKind = getSymbolKind(symbol, semanticMeaning);
symbolKind = getSymbolKind(symbol, typeResolver);
}
}
@@ -3011,6 +3081,12 @@ module ts {
}
}
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
var fullSymbolDisplayParts = symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);
displayParts.push.apply(displayParts, fullSymbolDisplayParts);
}
function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) {
addNewLineIfDisplayPartsExist();
if (symbolKind) {
@@ -3018,8 +3094,7 @@ module ts {
displayParts.push(textPart(symbolKind));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
// Write type parameters of class/Interface if it is property/method of the generic class/interface
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
addFullSymbolName(symbol);
}
}
@@ -3039,7 +3114,7 @@ module ts {
function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node) {
var typeParameterParts = mapToDisplayParts(writer => {
typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration);
typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration);
});
displayParts.push.apply(displayParts, typeParameterParts);
}
@@ -3057,12 +3132,6 @@ module ts {
var symbol = typeInfoResolver.getSymbolInfo(node);
if (!symbol) {
return undefined;
}
var symbol = typeInfoResolver.getSymbolInfo(node);
if (!symbol) {
// Try getting just type at this position and show
switch (node.kind) {
case SyntaxKind.Identifier:
@@ -3070,7 +3139,7 @@ module ts {
case SyntaxKind.QualifiedName:
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
// For the identifiers/this/usper etc get the type at position
// For the identifiers/this/super etc get the type at position
var type = typeInfoResolver.getTypeOfNode(node);
if (type) {
return {
@@ -3097,7 +3166,7 @@ module ts {
}
/// Goto definition
function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[]{
function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[] {
function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo {
return {
fileName: node.getSourceFile().filename,
@@ -3129,7 +3198,7 @@ module ts {
result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName));
return true;
}
return false;
}
@@ -3193,7 +3262,7 @@ module ts {
// Could not find a symbol e.g. node is string or number keyword,
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
if (!symbol || !(symbol.getDeclarations())) {
if (!symbol) {
return undefined;
}
@@ -3201,7 +3270,7 @@ module ts {
var declarations = symbol.getDeclarations();
var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
var symbolKind = getSymbolKind(symbol, getMeaningFromLocation(node));
var symbolKind = getSymbolKind(symbol, typeInfoResolver);
var containerSymbol = symbol.parent;
var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : "";
@@ -3726,18 +3795,20 @@ module ts {
return [getReferenceEntryFromNode(node)];
}
// the symbol was an internal symbol and does not have a declaration e.g.undefined symbol
if (!symbol.getDeclarations()) {
var declarations = symbol.declarations;
// The symbol was an internal symbol and does not have a declaration e.g.undefined symbol
if (!declarations || !declarations.length) {
return undefined;
}
var result: ReferenceEntry[];
// Compute the meaning from the location and the symbol it references
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations());
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
// Get the text to search for, we need to normalize it as external module names will have quote
var symbolName = getNormalizedSymbolName(symbol);
var symbolName = getNormalizedSymbolName(symbol.name, declarations);
// Get syntactic diagnostics
var scope = getSymbolScope(symbol);
@@ -3759,15 +3830,15 @@ module ts {
return result;
function getNormalizedSymbolName(symbol: Symbol): string {
function getNormalizedSymbolName(symbolName: string, declarations: Declaration[]): string {
// Special case for function expressions, whose names are solely local to their bodies.
var functionExpression = getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression);
var functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined);
if (functionExpression && functionExpression.name) {
var name = functionExpression.name.text;
}
else {
var name = symbol.name;
var name = symbolName;
}
var length = name.length;
@@ -3794,22 +3865,24 @@ module ts {
var scope: Node = undefined;
var declarations = symbol.getDeclarations();
for (var i = 0, n = declarations.length; i < n; i++) {
var container = getContainerNode(declarations[i]);
if (declarations) {
for (var i = 0, n = declarations.length; i < n; i++) {
var container = getContainerNode(declarations[i]);
if (scope && scope !== container) {
// Different declarations have different containers, bail out
return undefined;
if (scope && scope !== container) {
// Different declarations have different containers, bail out
return undefined;
}
if (container.kind === SyntaxKind.SourceFile && !isExternalModule(<SourceFile>container)) {
// This is a global variable and not an external module, any declaration defined
// within this scope is visible outside the file
return undefined;
}
// The search scope is the container node
scope = container;
}
if (container.kind === SyntaxKind.SourceFile && !isExternalModule(<SourceFile>container)) {
// This is a global variable and not an external module, any declaration defined
// within this scope is visible outside the file
return undefined;
}
// The search scope is the container node
scope = container;
}
return scope;
@@ -3945,14 +4018,7 @@ module ts {
}
var referenceSymbol = typeInfoResolver.getSymbolInfo(referenceLocation);
// Could not find a symbol e.g. node is string or number keyword,
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
if (!referenceSymbol || !(referenceSymbol.getDeclarations())) {
return;
}
if (isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) {
if (referenceSymbol && isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) {
result.push(getReferenceEntryFromNode(referenceLocation));
}
});
@@ -4114,24 +4180,27 @@ module ts {
// The search set contains at least the current symbol
var result = [symbol];
// If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list
var rootSymbol = typeInfoResolver.getRootSymbol(symbol);
if (rootSymbol && rootSymbol !== symbol) {
result.push(rootSymbol);
}
// If the location is in a context sensitive location (i.e. in an object literal) try
// to get a contextual type for it, and add the property symbol from the contextual
// type to the search set
if (isNameOfPropertyAssignment(location)) {
var symbolFromContextualType = getPropertySymbolFromContextualType(location);
if (symbolFromContextualType) result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType));
forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => {
result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol));
});
}
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
if (symbol.parent && symbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result);
}
// If this is a union property, add all the symbols from all its source symbols in all unioned types.
// If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list
forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => {
if (rootSymbol !== symbol) {
result.push(rootSymbol);
}
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result);
}
});
return result;
}
@@ -4167,11 +4236,7 @@ module ts {
}
function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean {
// Unwrap symbols to get to the root (e.g. transient symbols as a result of widening)
var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol);
// if it is in the list, then we are done
if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) {
if (searchSymbols.indexOf(referenceSymbol) >= 0) {
return true;
}
@@ -4179,29 +4244,61 @@ module ts {
// object literal, lookup the property symbol in the contextual type, and use this symbol to
// compare to our searchSymbol
if (isNameOfPropertyAssignment(referenceLocation)) {
var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation);
if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) {
return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => {
return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0);
});
}
// Unwrap symbols to get to the root (e.g. transient symbols as a result of widening)
// Or a union property, use its underlying unioned symbols
return forEach(typeInfoResolver.getRootSymbols(referenceSymbol), rootSymbol => {
// if it is in the list, then we are done
if (searchSymbols.indexOf(rootSymbol) >= 0) {
return true;
}
}
// Finally, try all properties with the same name in any type the containing type extend or implemented, and
// see if any is in the list
if (referenceSymbol.parent && referenceSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
var result: Symbol[] = [];
getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result);
return forEach(result, s => searchSymbols.indexOf(s) >= 0);
}
// Finally, try all properties with the same name in any type the containing type extended or implemented, and
// see if any is in the list
if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
var result: Symbol[] = [];
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result);
return forEach(result, s => searchSymbols.indexOf(s) >= 0);
}
return false;
return false;
});
}
function getPropertySymbolFromContextualType(node: Node): Symbol {
function getPropertySymbolsFromContextualType(node: Node): Symbol[] {
if (isNameOfPropertyAssignment(node)) {
var objectLiteral = node.parent.parent;
var contextualType = typeInfoResolver.getContextualType(objectLiteral);
var name = (<Identifier>node).text;
if (contextualType) {
return typeInfoResolver.getPropertyOfType(contextualType, (<Identifier>node).text);
if (contextualType.flags & TypeFlags.Union) {
// This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types)
// if not, search the constituent types for the property
var unionProperty = contextualType.getProperty(name)
if (unionProperty) {
return [unionProperty];
}
else {
var result: Symbol[] = [];
forEach((<UnionType>contextualType).types, t => {
var symbol = t.getProperty(name);
if (symbol) {
result.push(symbol);
}
});
return result;
}
}
else {
var symbol = contextualType.getProperty(name);
if (symbol) {
return [symbol];
}
}
}
}
return undefined;
@@ -4718,7 +4815,24 @@ module ts {
}
}
else if (flags & SymbolFlags.Module) {
return ClassificationTypeNames.moduleName;
// Only classify a module as such if
// - It appears in a namespace context.
// - There exists a module declaration which actually impacts the value side.
if (meaningAtPosition & SemanticMeaning.Namespace ||
(meaningAtPosition & SemanticMeaning.Value && hasValueSideModule(symbol))) {
return ClassificationTypeNames.moduleName;
}
}
return undefined;
/**
* Returns true if there exists a module that introduces entities on the value side.
*/
function hasValueSideModule(symbol: Symbol): boolean {
return forEach(symbol.declarations, declaration => {
return declaration.kind === SyntaxKind.ModuleDeclaration && isInstantiated(declaration);
});
}
}
@@ -4749,115 +4863,99 @@ module ts {
var sourceFile = getCurrentSourceFile(fileName);
var result: ClassifiedSpan[] = [];
processElement(sourceFile.getSourceUnit());
processElement(sourceFile);
return result;
function classifyTrivia(trivia: TypeScript.ISyntaxTrivia) {
if (trivia.isComment() && span.intersectsWith(trivia.fullStart(), trivia.fullWidth())) {
function classifyComment(comment: CommentRange) {
var width = comment.end - comment.pos;
if (span.intersectsWith(comment.pos, width)) {
result.push({
textSpan: new TypeScript.TextSpan(trivia.fullStart(), trivia.fullWidth()),
textSpan: new TypeScript.TextSpan(comment.pos, width),
classificationType: ClassificationTypeNames.comment
});
}
}
function classifyTriviaList(trivia: TypeScript.ISyntaxTriviaList) {
for (var i = 0, n = trivia.count(); i < n; i++) {
classifyTrivia(trivia.syntaxTriviaAt(i));
}
}
function classifyToken(token: Node): void {
forEach(getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment);
function classifyToken(token: TypeScript.ISyntaxToken) {
if (token.hasLeadingComment()) {
classifyTriviaList(token.leadingTrivia());
}
if (TypeScript.width(token) > 0) {
if (token.getWidth() > 0) {
var type = classifyTokenType(token);
if (type) {
result.push({
textSpan: new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)),
textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()),
classificationType: type
});
}
}
if (token.hasTrailingComment()) {
classifyTriviaList(token.trailingTrivia());
}
forEach(getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment);
}
function classifyTokenType(token: TypeScript.ISyntaxToken): string {
var tokenKind = token.kind();
if (TypeScript.SyntaxFacts.isAnyKeyword(token.kind())) {
function classifyTokenType(token: Node): string {
var tokenKind = token.kind;
if (isKeyword(tokenKind)) {
return ClassificationTypeNames.keyword;
}
// Special case < and > If they appear in a generic context they are punctation,
// Special case < and > If they appear in a generic context they are punctuation,
// not operators.
if (tokenKind === TypeScript.SyntaxKind.LessThanToken || tokenKind === TypeScript.SyntaxKind.GreaterThanToken) {
var tokenParentKind = token.parent.kind();
if (tokenParentKind === TypeScript.SyntaxKind.TypeArgumentList ||
tokenParentKind === TypeScript.SyntaxKind.TypeParameterList) {
if (tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) {
// If the node owning the token has a type argument list or type parameter list, then
// we can effectively assume that a '<' and '>' belong to those lists.
if (getTypeArgumentOrTypeParameterList(token.parent)) {
return ClassificationTypeNames.punctuation;
}
}
if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(tokenKind) ||
TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(tokenKind)) {
return ClassificationTypeNames.operator;
if (isPunctuation(token)) {
// the '=' in a variable declaration is special cased here.
if (token.parent.kind === SyntaxKind.BinaryExpression ||
token.parent.kind === SyntaxKind.VariableDeclaration ||
token.parent.kind === SyntaxKind.PrefixOperator ||
token.parent.kind === SyntaxKind.PostfixOperator ||
token.parent.kind === SyntaxKind.ConditionalExpression) {
return ClassificationTypeNames.operator;
}
else {
return ClassificationTypeNames.punctuation;
}
}
else if (TypeScript.SyntaxFacts.isAnyPunctuation(tokenKind)) {
return ClassificationTypeNames.punctuation;
}
else if (tokenKind === TypeScript.SyntaxKind.NumericLiteral) {
else if (tokenKind === SyntaxKind.NumericLiteral) {
return ClassificationTypeNames.numericLiteral;
}
else if (tokenKind === TypeScript.SyntaxKind.StringLiteral) {
else if (tokenKind === SyntaxKind.StringLiteral) {
return ClassificationTypeNames.stringLiteral;
}
else if (tokenKind === TypeScript.SyntaxKind.RegularExpressionLiteral) {
// TODO: we shoudl get another classification type for these literals.
else if (tokenKind === SyntaxKind.RegularExpressionLiteral) {
// TODO: we should get another classification type for these literals.
return ClassificationTypeNames.stringLiteral;
}
else if (tokenKind === TypeScript.SyntaxKind.IdentifierName) {
var current: TypeScript.ISyntaxNodeOrToken = token;
var parent = token.parent;
while (parent.kind() === TypeScript.SyntaxKind.QualifiedName) {
current = parent;
parent = parent.parent;
}
switch (parent.kind()) {
case TypeScript.SyntaxKind.SimplePropertyAssignment:
if ((<TypeScript.SimplePropertyAssignmentSyntax>parent).propertyName === token) {
return ClassificationTypeNames.identifier;
}
return;
case TypeScript.SyntaxKind.ClassDeclaration:
if ((<TypeScript.ClassDeclarationSyntax>parent).identifier === token) {
else if (tokenKind === SyntaxKind.Identifier) {
switch (token.parent.kind) {
case SyntaxKind.ClassDeclaration:
if ((<ClassDeclaration>token.parent).name === token) {
return ClassificationTypeNames.className;
}
return;
case TypeScript.SyntaxKind.TypeParameter:
if ((<TypeScript.TypeParameterSyntax>parent).identifier === token) {
case SyntaxKind.TypeParameter:
if ((<TypeParameterDeclaration>token.parent).name === token) {
return ClassificationTypeNames.typeParameterName;
}
return;
case TypeScript.SyntaxKind.InterfaceDeclaration:
if ((<TypeScript.InterfaceDeclarationSyntax>parent).identifier === token) {
case SyntaxKind.InterfaceDeclaration:
if ((<InterfaceDeclaration>token.parent).name === token) {
return ClassificationTypeNames.interfaceName;
}
return;
case TypeScript.SyntaxKind.EnumDeclaration:
if ((<TypeScript.EnumDeclarationSyntax>parent).identifier === token) {
case SyntaxKind.EnumDeclaration:
if ((<EnumDeclaration>token.parent).name === token) {
return ClassificationTypeNames.enumName;
}
return;
case TypeScript.SyntaxKind.ModuleDeclaration:
if ((<TypeScript.ModuleDeclarationSyntax>parent).name === current) {
case SyntaxKind.ModuleDeclaration:
if ((<ModuleDeclaration>token.parent).name === token) {
return ClassificationTypeNames.moduleName;
}
return;
@@ -4867,19 +4965,18 @@ module ts {
}
}
function processElement(element: TypeScript.ISyntaxElement) {
function processElement(element: Node) {
// Ignore nodes that don't intersect the original span to classify.
if (!TypeScript.isShared(element) && span.intersectsWith(TypeScript.fullStart(element), TypeScript.fullWidth(element))) {
for (var i = 0, n = TypeScript.childCount(element); i < n; i++) {
var child = TypeScript.childAt(element, i);
if (child) {
if (TypeScript.isToken(child)) {
classifyToken(<TypeScript.ISyntaxToken>child);
}
else {
// Recurse into our child nodes.
processElement(child);
}
if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) {
var children = element.getChildren();
for (var i = 0, n = children.length; i < n; i++) {
var child = children[i];
if (isToken(child)) {
classifyToken(child);
}
else {
// Recurse into our child nodes.
processElement(child);
}
}
}
@@ -5179,7 +5276,7 @@ module ts {
// Only allow a symbol to be renamed if it actually has at least one declaration.
if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) {
var kind = getSymbolKind(symbol, getMeaningFromLocation(node));
var kind = getSymbolKind(symbol, typeInfoResolver);
if (kind) {
return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind,
getSymbolModifiers(symbol),
+68 -64
View File
@@ -258,6 +258,13 @@ module ts.SignatureHelp {
return undefined;
}
function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node {
var children = parent.getChildren(sourceFile);
var indexOfOpenerToken = children.indexOf(openerToken);
Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1);
return children[indexOfOpenerToken + 1];
}
/**
* The selectedItemIndex could be negative for several reasons.
* 1. There are too many arguments for all of the overloads
@@ -287,74 +294,51 @@ module ts.SignatureHelp {
function createSignatureHelpItems(candidates: Signature[], bestSignature: Signature, argumentInfoOrTypeArgumentInfo: ListItemInfo): SignatureHelpItems {
var argumentListOrTypeArgumentList = argumentInfoOrTypeArgumentInfo.list;
var parent = <CallExpression>argumentListOrTypeArgumentList.parent;
var isTypeParameterHelp = parent.typeArguments && parent.typeArguments.pos === argumentListOrTypeArgumentList.pos;
Debug.assert(isTypeParameterHelp || parent.arguments.pos === argumentListOrTypeArgumentList.pos);
var callTargetNode = (<CallExpression>argumentListOrTypeArgumentList.parent).func;
var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode);
var callTargetDisplayParts = callTargetSymbol && symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined);
var items: SignatureHelpItem[] = map(candidates, candidateSignature => {
var parameters = candidateSignature.parameters;
var parameterHelpItems: SignatureHelpParameter[] = parameters.length === 0 ? emptyArray : map(parameters, p => {
var displayParts: SymbolDisplayPart[] = [];
var signatureHelpParameters: SignatureHelpParameter[];
var prefixParts: SymbolDisplayPart[] = [];
var suffixParts: SymbolDisplayPart[] = [];
if (candidateSignature.hasRestParameter && parameters[parameters.length - 1] === p) {
displayParts.push(punctuationPart(SyntaxKind.DotDotDotToken));
}
displayParts.push(symbolPart(p.name, p));
var isOptional = !!(p.valueDeclaration.flags & NodeFlags.QuestionMark);
if (isOptional) {
displayParts.push(punctuationPart(SyntaxKind.QuestionToken));
}
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
displayParts.push(spacePart());
var typeParts = typeToDisplayParts(typeInfoResolver, typeInfoResolver.getTypeOfSymbol(p), argumentListOrTypeArgumentList);
displayParts.push.apply(displayParts, typeParts);
return {
name: p.name,
documentation: p.getDocumentationComment(),
displayParts: displayParts,
isOptional: isOptional
};
});
var callTargetNode = (<CallExpression>argumentListOrTypeArgumentList.parent).func;
var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode);
var prefixParts = callTargetSymbol ? symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : [];
var separatorParts = [punctuationPart(SyntaxKind.CommaToken), spacePart()];
// TODO(jfreeman): Constraints?
if (candidateSignature.typeParameters && candidateSignature.typeParameters.length) {
prefixParts.push(punctuationPart(SyntaxKind.LessThanToken));
for (var i = 0, n = candidateSignature.typeParameters.length; i < n; i++) {
if (i) {
prefixParts.push.apply(prefixParts, separatorParts);
}
var tp = candidateSignature.typeParameters[i].symbol;
prefixParts.push(symbolPart(tp.name, tp));
}
prefixParts.push(punctuationPart(SyntaxKind.GreaterThanToken));
if (callTargetDisplayParts) {
prefixParts.push.apply(prefixParts, callTargetDisplayParts);
}
prefixParts.push(punctuationPart(SyntaxKind.OpenParenToken));
if (isTypeParameterHelp) {
prefixParts.push(punctuationPart(SyntaxKind.LessThanToken));
var typeParameters = candidateSignature.typeParameters;
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
suffixParts.push(punctuationPart(SyntaxKind.GreaterThanToken));
var parameterParts = mapToDisplayParts(writer =>
typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, argumentListOrTypeArgumentList));
suffixParts.push.apply(suffixParts, parameterParts);
}
else {
var typeParameterParts = mapToDisplayParts(writer =>
typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, argumentListOrTypeArgumentList));
prefixParts.push.apply(prefixParts, typeParameterParts);
prefixParts.push(punctuationPart(SyntaxKind.OpenParenToken));
var parameters = candidateSignature.parameters;
signatureHelpParameters = parameters.length > 0 ? map(parameters, createSignatureHelpParameterForParameter) : emptyArray;
suffixParts.push(punctuationPart(SyntaxKind.CloseParenToken));
}
var suffixParts = [punctuationPart(SyntaxKind.CloseParenToken)];
suffixParts.push(punctuationPart(SyntaxKind.ColonToken));
suffixParts.push(spacePart());
var typeParts = typeToDisplayParts(typeInfoResolver, candidateSignature.getReturnType(), argumentListOrTypeArgumentList);
suffixParts.push.apply(suffixParts, typeParts);
var returnTypeParts = mapToDisplayParts(writer =>
typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, argumentListOrTypeArgumentList));
suffixParts.push.apply(suffixParts, returnTypeParts);
return {
isVariadic: candidateSignature.hasRestParameter,
prefixDisplayParts: prefixParts,
suffixDisplayParts: suffixParts,
separatorDisplayParts: separatorParts,
parameters: parameterHelpItems,
separatorDisplayParts: [punctuationPart(SyntaxKind.CommaToken), spacePart()],
parameters: signatureHelpParameters,
documentation: candidateSignature.getDocumentationComment()
};
});
@@ -400,12 +384,32 @@ module ts.SignatureHelp {
argumentIndex: argumentIndex,
argumentCount: argumentCount
};
function createSignatureHelpParameterForParameter(parameter: Symbol): SignatureHelpParameter {
var displayParts = mapToDisplayParts(writer =>
typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, argumentListOrTypeArgumentList));
var isOptional = !!(parameter.valueDeclaration.flags & NodeFlags.QuestionMark);
return {
name: parameter.name,
documentation: parameter.getDocumentationComment(),
displayParts: displayParts,
isOptional: isOptional
};
}
function createSignatureHelpParameterForTypeParameter(typeParameter: TypeParameter): SignatureHelpParameter {
var displayParts = mapToDisplayParts(writer =>
typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, argumentListOrTypeArgumentList));
return {
name: typeParameter.symbol.name,
documentation: emptyArray,
displayParts: displayParts,
isOptional: false
};
}
}
}
function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node {
var children = parent.getChildren(sourceFile);
var indexOfOpenerToken = children.indexOf(openerToken);
return children[indexOfOpenerToken + 1];
}
}
-1
View File
@@ -84,7 +84,6 @@ module TypeScript {
private cacheSyntaxTreeInfo(): void {
// If we're not keeping around the syntax tree, store the diagnostics and line
// map so they don't have to be recomputed.
var sourceUnit = this.sourceUnit();
var firstToken = firstSyntaxTreeToken(this);
var leadingTrivia = firstToken.leadingTrivia(this.text);
+21 -5
View File
@@ -230,19 +230,35 @@ module ts {
return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0;
}
export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray<Node> {
if (node.kind === SyntaxKind.TypeReference || node.kind === SyntaxKind.CallExpression) {
return (<CallExpression>node).typeArguments;
}
if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) {
return (<FunctionDeclaration>node).typeParameters;
}
return undefined;
}
export function isToken(n: Node): boolean {
return n.kind >= SyntaxKind.FirstToken && n.kind <= SyntaxKind.LastToken;
}
function isKeyword(n: Node): boolean {
return n.kind >= SyntaxKind.FirstKeyword && n.kind <= SyntaxKind.LastKeyword;
}
function isWord(n: Node): boolean {
return n.kind === SyntaxKind.Identifier || isKeyword(n);
return n.kind === SyntaxKind.Identifier || isKeyword(n.kind);
}
function isPropertyName(n: Node): boolean {
return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n);
}
export function isComment(n: Node): boolean {
return n.kind === SyntaxKind.SingleLineCommentTrivia || n.kind === SyntaxKind.MultiLineCommentTrivia;
}
export function isPunctuation(n: Node): boolean {
return SyntaxKind.FirstPunctuation <= n.kind && n.kind <= SyntaxKind.LastPunctuation;
}
}
@@ -17,7 +17,7 @@ interface IHasVisualizationModel {
var xs: IHasVisualizationModel[] = [moduleA];
>xs : IHasVisualizationModel[]
>IHasVisualizationModel : IHasVisualizationModel
>[moduleA] : IHasVisualizationModel[]
>[moduleA] : typeof moduleA[]
>moduleA : typeof moduleA
var xs2: typeof moduleA[] = [moduleA];
@@ -53,7 +53,7 @@ var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x
>f : { x: IHasVisualizationModel; }
>x : IHasVisualizationModel
>IHasVisualizationModel : IHasVisualizationModel
><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: IHasVisualizationModel; }
><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: typeof moduleA; }
><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; }
>x : IHasVisualizationModel
>IHasVisualizationModel : IHasVisualizationModel
+214 -98
View File
@@ -1,55 +1,109 @@
//// [arrayBestCommonTypes.ts]
interface iface { }
class base implements iface { }
class base2 implements iface { }
class derived extends base { }
module EmptyTypes {
interface iface { }
class base implements iface { }
class base2 implements iface { }
class derived extends base { }
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y =false): any { return null; }
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y = false): any { return null; }
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny([[3,4],[null]][0][0]));
var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ];
var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ];
var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ];
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ];
var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ];
var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
var b1 = [ baseObj, base2Obj, ifaceObj ];
var b2 = [ base2Obj, baseObj, ifaceObj ];
var b3 = [ baseObj, ifaceObj, base2Obj ];
var b4 = [ ifaceObj, baseObj, base2Obj ];
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
}
}
}
module NonEmptyTypes {
interface iface { x: string; }
class base implements iface { x: string; y: string; }
class base2 implements iface { x: string; z: string; }
class derived extends base { a: string; }
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y = false): any { return null; }
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
}
}
}
@@ -60,59 +114,121 @@ var __extends = this.__extends || function (d, b) {
__.prototype = b.prototype;
d.prototype = new __();
};
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
var EmptyTypes;
(function (EmptyTypes) {
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
})(EmptyTypes || (EmptyTypes = {}));
var NonEmptyTypes;
(function (NonEmptyTypes) {
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
})(NonEmptyTypes || (NonEmptyTypes = {}));
@@ -1,47 +1,50 @@
=== tests/cases/compiler/arrayBestCommonTypes.ts ===
interface iface { }
module EmptyTypes {
>EmptyTypes : typeof EmptyTypes
interface iface { }
>iface : iface
class base implements iface { }
class base implements iface { }
>base : base
>iface : iface
class base2 implements iface { }
class base2 implements iface { }
>base2 : base2
>iface : iface
class derived extends base { }
class derived extends base { }
>derived : derived
>base : base
class f {
class f {
>f : f
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: boolean, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : boolean
>y : boolean
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : string
>y : boolean
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : number
>y : boolean
public voidIfAny(x: any, y =false): any { return null; }
public voidIfAny(x: any, y = false): any { return null; }
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : any
>y : boolean
public x() {
public x() {
>x : () => void
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2][0]));
><number>(this.voidIfAny([4, 2][0])) : number
>(this.voidIfAny([4, 2][0])) : number
>this.voidIfAny([4, 2][0]) : number
@@ -51,7 +54,7 @@ class f {
>[4, 2][0] : number
>[4, 2] : number[]
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
><number>(this.voidIfAny([4, 2, undefined][0])) : number
>(this.voidIfAny([4, 2, undefined][0])) : number
>this.voidIfAny([4, 2, undefined][0]) : number
@@ -62,7 +65,7 @@ class f {
>[4, 2, undefined] : number[]
>undefined : undefined
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
><number>(this.voidIfAny([undefined, 2, 4][0])) : number
>(this.voidIfAny([undefined, 2, 4][0])) : number
>this.voidIfAny([undefined, 2, 4][0]) : number
@@ -73,7 +76,7 @@ class f {
>[undefined, 2, 4] : number[]
>undefined : undefined
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
><number>(this.voidIfAny([null, 2, 4][0])) : number
>(this.voidIfAny([null, 2, 4][0])) : number
>this.voidIfAny([null, 2, 4][0]) : number
@@ -83,7 +86,7 @@ class f {
>[null, 2, 4][0] : number
>[null, 2, 4] : number[]
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([2, 4, null][0]));
><number>(this.voidIfAny([2, 4, null][0])) : number
>(this.voidIfAny([2, 4, null][0])) : number
>this.voidIfAny([2, 4, null][0]) : number
@@ -93,7 +96,7 @@ class f {
>[2, 4, null][0] : number
>[2, 4, null] : number[]
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
><number>(this.voidIfAny([undefined, 4, null][0])) : number
>(this.voidIfAny([undefined, 4, null][0])) : number
>this.voidIfAny([undefined, 4, null][0]) : number
@@ -104,7 +107,7 @@ class f {
>[undefined, 4, null] : number[]
>undefined : undefined
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q"][0]));
><number>(this.voidIfAny(['', "q"][0])) : number
>(this.voidIfAny(['', "q"][0])) : number
>this.voidIfAny(['', "q"][0]) : number
@@ -114,7 +117,7 @@ class f {
>['', "q"][0] : string
>['', "q"] : string[]
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
><number>(this.voidIfAny(['', "q", undefined][0])) : number
>(this.voidIfAny(['', "q", undefined][0])) : number
>this.voidIfAny(['', "q", undefined][0]) : number
@@ -125,7 +128,7 @@ class f {
>['', "q", undefined] : string[]
>undefined : undefined
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
><number>(this.voidIfAny([undefined, "q", ''][0])) : number
>(this.voidIfAny([undefined, "q", ''][0])) : number
>this.voidIfAny([undefined, "q", ''][0]) : number
@@ -136,7 +139,7 @@ class f {
>[undefined, "q", ''] : string[]
>undefined : undefined
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
><number>(this.voidIfAny([null, "q", ''][0])) : number
>(this.voidIfAny([null, "q", ''][0])) : number
>this.voidIfAny([null, "q", ''][0]) : number
@@ -146,7 +149,7 @@ class f {
>[null, "q", ''][0] : string
>[null, "q", ''] : string[]
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny(["q", '', null][0]));
><number>(this.voidIfAny(["q", '', null][0])) : number
>(this.voidIfAny(["q", '', null][0])) : number
>this.voidIfAny(["q", '', null][0]) : number
@@ -156,7 +159,7 @@ class f {
>["q", '', null][0] : string
>["q", '', null] : string[]
<number>(this.voidIfAny([undefined, '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
><number>(this.voidIfAny([undefined, '', null][0])) : number
>(this.voidIfAny([undefined, '', null][0])) : number
>this.voidIfAny([undefined, '', null][0]) : number
@@ -167,26 +170,26 @@ class f {
>[undefined, '', null] : string[]
>undefined : undefined
<number>(this.voidIfAny([[3,4],[null]][0][0]));
><number>(this.voidIfAny([[3,4],[null]][0][0])) : number
>(this.voidIfAny([[3,4],[null]][0][0])) : number
>this.voidIfAny([[3,4],[null]][0][0]) : number
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
><number>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>this.voidIfAny([[3, 4], [null]][0][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[[3,4],[null]][0][0] : number
>[[3,4],[null]][0] : number[]
>[[3,4],[null]] : number[][]
>[3,4] : number[]
>[[3, 4], [null]][0][0] : number
>[[3, 4], [null]][0] : number[]
>[[3, 4], [null]] : number[][]
>[3, 4] : number[]
>[null] : null[]
var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ];
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
>t1 : { x: number; y: base; }[]
>x : number
>y : base
>base : base
>[ { x: 7, y: new derived() }, { x: 5, y: new base() } ] : { x: number; y: base; }[]
>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: derived; }[]
>{ x: 7, y: new derived() } : { x: number; y: derived; }
>x : number
>y : derived
@@ -198,12 +201,12 @@ class f {
>new base() : base
>base : typeof base
var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
>t2 : { x: boolean; y: base; }[]
>x : boolean
>y : base
>base : base
>[ { x: true, y: new derived() }, { x: false, y: new base() } ] : { x: boolean; y: base; }[]
>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: derived; }[]
>{ x: true, y: new derived() } : { x: boolean; y: derived; }
>x : boolean
>y : derived
@@ -215,12 +218,12 @@ class f {
>new base() : base
>base : typeof base
var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
>t3 : { x: string; y: base; }[]
>x : string
>y : base
>base : base
>[ { x: undefined, y: new base() }, { x: '', y: new derived() } ] : { x: string; y: base; }[]
>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: derived; }[]
>{ x: undefined, y: new base() } : { x: undefined; y: base; }
>x : undefined
>undefined : undefined
@@ -233,95 +236,429 @@ class f {
>new derived() : derived
>derived : typeof derived
var anyObj: any = null;
var anyObj: any = null;
>anyObj : any
// Order matters here so test all the variants
var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ];
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
>a1 : { x: any; y: string; }[]
>[ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ] : { x: any; y: string; }[]
>{x: 0, y: 'a'} : { x: number; y: string; }
>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{x: 'a', y: 'a'} : { x: string; y: string; }
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
>{x: anyObj, y: 'a'} : { x: any; y: string; }
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
>a2 : { x: any; y: string; }[]
>[ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[]
>{x: anyObj, y: 'a'} : { x: any; y: string; }
>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{x: 0, y: 'a'} : { x: number; y: string; }
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{x: 'a', y: 'a'} : { x: string; y: string; }
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
>a3 : { x: any; y: string; }[]
>[ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[]
>{x: 0, y: 'a'} : { x: number; y: string; }
>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{x: anyObj, y: 'a'} : { x: any; y: string; }
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{x: 'a', y: 'a'} : { x: string; y: string; }
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var ifaceObj: iface = null;
var ifaceObj: iface = null;
>ifaceObj : iface
>iface : iface
var baseObj = new base();
var baseObj = new base();
>baseObj : base
>new base() : base
>base : typeof base
var base2Obj = new base2();
var base2Obj = new base2();
>base2Obj : base2
>new base2() : base2
>base2 : typeof base2
var b1 = [ baseObj, base2Obj, ifaceObj ];
>b1 : base[]
>[ baseObj, base2Obj, ifaceObj ] : base[]
var b1 = [baseObj, base2Obj, ifaceObj];
>b1 : iface[]
>[baseObj, base2Obj, ifaceObj] : iface[]
>baseObj : base
>base2Obj : base2
>ifaceObj : iface
var b2 = [ base2Obj, baseObj, ifaceObj ];
>b2 : base2[]
>[ base2Obj, baseObj, ifaceObj ] : base2[]
var b2 = [base2Obj, baseObj, ifaceObj];
>b2 : iface[]
>[base2Obj, baseObj, ifaceObj] : iface[]
>base2Obj : base2
>baseObj : base
>ifaceObj : iface
var b3 = [ baseObj, ifaceObj, base2Obj ];
>b3 : base[]
>[ baseObj, ifaceObj, base2Obj ] : base[]
var b3 = [baseObj, ifaceObj, base2Obj];
>b3 : iface[]
>[baseObj, ifaceObj, base2Obj] : iface[]
>baseObj : base
>ifaceObj : iface
>base2Obj : base2
var b4 = [ ifaceObj, baseObj, base2Obj ];
var b4 = [ifaceObj, baseObj, base2Obj];
>b4 : iface[]
>[ ifaceObj, baseObj, base2Obj ] : iface[]
>[ifaceObj, baseObj, base2Obj] : iface[]
>ifaceObj : iface
>baseObj : base
>base2Obj : base2
}
}
}
module NonEmptyTypes {
>NonEmptyTypes : typeof NonEmptyTypes
interface iface { x: string; }
>iface : iface
>x : string
class base implements iface { x: string; y: string; }
>base : base
>iface : iface
>x : string
>y : string
class base2 implements iface { x: string; z: string; }
>base2 : base2
>iface : iface
>x : string
>z : string
class derived extends base { a: string; }
>derived : derived
>base : base
>a : string
class f {
>f : f
public voidIfAny(x: boolean, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : boolean
>y : boolean
public voidIfAny(x: string, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : string
>y : boolean
public voidIfAny(x: number, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : number
>y : boolean
public voidIfAny(x: any, y = false): any { return null; }
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : any
>y : boolean
public x() {
>x : () => void
<number>(this.voidIfAny([4, 2][0]));
><number>(this.voidIfAny([4, 2][0])) : number
>(this.voidIfAny([4, 2][0])) : number
>this.voidIfAny([4, 2][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[4, 2][0] : number
>[4, 2] : number[]
<number>(this.voidIfAny([4, 2, undefined][0]));
><number>(this.voidIfAny([4, 2, undefined][0])) : number
>(this.voidIfAny([4, 2, undefined][0])) : number
>this.voidIfAny([4, 2, undefined][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[4, 2, undefined][0] : number
>[4, 2, undefined] : number[]
>undefined : undefined
<number>(this.voidIfAny([undefined, 2, 4][0]));
><number>(this.voidIfAny([undefined, 2, 4][0])) : number
>(this.voidIfAny([undefined, 2, 4][0])) : number
>this.voidIfAny([undefined, 2, 4][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, 2, 4][0] : number
>[undefined, 2, 4] : number[]
>undefined : undefined
<number>(this.voidIfAny([null, 2, 4][0]));
><number>(this.voidIfAny([null, 2, 4][0])) : number
>(this.voidIfAny([null, 2, 4][0])) : number
>this.voidIfAny([null, 2, 4][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[null, 2, 4][0] : number
>[null, 2, 4] : number[]
<number>(this.voidIfAny([2, 4, null][0]));
><number>(this.voidIfAny([2, 4, null][0])) : number
>(this.voidIfAny([2, 4, null][0])) : number
>this.voidIfAny([2, 4, null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[2, 4, null][0] : number
>[2, 4, null] : number[]
<number>(this.voidIfAny([undefined, 4, null][0]));
><number>(this.voidIfAny([undefined, 4, null][0])) : number
>(this.voidIfAny([undefined, 4, null][0])) : number
>this.voidIfAny([undefined, 4, null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, 4, null][0] : number
>[undefined, 4, null] : number[]
>undefined : undefined
<number>(this.voidIfAny(['', "q"][0]));
><number>(this.voidIfAny(['', "q"][0])) : number
>(this.voidIfAny(['', "q"][0])) : number
>this.voidIfAny(['', "q"][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>['', "q"][0] : string
>['', "q"] : string[]
<number>(this.voidIfAny(['', "q", undefined][0]));
><number>(this.voidIfAny(['', "q", undefined][0])) : number
>(this.voidIfAny(['', "q", undefined][0])) : number
>this.voidIfAny(['', "q", undefined][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>['', "q", undefined][0] : string
>['', "q", undefined] : string[]
>undefined : undefined
<number>(this.voidIfAny([undefined, "q", ''][0]));
><number>(this.voidIfAny([undefined, "q", ''][0])) : number
>(this.voidIfAny([undefined, "q", ''][0])) : number
>this.voidIfAny([undefined, "q", ''][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, "q", ''][0] : string
>[undefined, "q", ''] : string[]
>undefined : undefined
<number>(this.voidIfAny([null, "q", ''][0]));
><number>(this.voidIfAny([null, "q", ''][0])) : number
>(this.voidIfAny([null, "q", ''][0])) : number
>this.voidIfAny([null, "q", ''][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[null, "q", ''][0] : string
>[null, "q", ''] : string[]
<number>(this.voidIfAny(["q", '', null][0]));
><number>(this.voidIfAny(["q", '', null][0])) : number
>(this.voidIfAny(["q", '', null][0])) : number
>this.voidIfAny(["q", '', null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>["q", '', null][0] : string
>["q", '', null] : string[]
<number>(this.voidIfAny([undefined, '', null][0]));
><number>(this.voidIfAny([undefined, '', null][0])) : number
>(this.voidIfAny([undefined, '', null][0])) : number
>this.voidIfAny([undefined, '', null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, '', null][0] : string
>[undefined, '', null] : string[]
>undefined : undefined
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
><number>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>this.voidIfAny([[3, 4], [null]][0][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[[3, 4], [null]][0][0] : number
>[[3, 4], [null]][0] : number[]
>[[3, 4], [null]] : number[][]
>[3, 4] : number[]
>[null] : null[]
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
>t1 : { x: number; y: base; }[]
>x : number
>y : base
>base : base
>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: base; }[]
>{ x: 7, y: new derived() } : { x: number; y: derived; }
>x : number
>y : derived
>new derived() : derived
>derived : typeof derived
>{ x: 5, y: new base() } : { x: number; y: base; }
>x : number
>y : base
>new base() : base
>base : typeof base
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
>t2 : { x: boolean; y: base; }[]
>x : boolean
>y : base
>base : base
>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: base; }[]
>{ x: true, y: new derived() } : { x: boolean; y: derived; }
>x : boolean
>y : derived
>new derived() : derived
>derived : typeof derived
>{ x: false, y: new base() } : { x: boolean; y: base; }
>x : boolean
>y : base
>new base() : base
>base : typeof base
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
>t3 : { x: string; y: base; }[]
>x : string
>y : base
>base : base
>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : ({ x: undefined; y: base; } | { x: string; y: derived; })[]
>{ x: undefined, y: new base() } : { x: undefined; y: base; }
>x : undefined
>undefined : undefined
>y : base
>new base() : base
>base : typeof base
>{ x: '', y: new derived() } : { x: string; y: derived; }
>x : string
>y : derived
>new derived() : derived
>derived : typeof derived
var anyObj: any = null;
>anyObj : any
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
>a1 : { x: any; y: string; }[]
>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
>a2 : { x: any; y: string; }[]
>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
>a3 : { x: any; y: string; }[]
>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var ifaceObj: iface = null;
>ifaceObj : iface
>iface : iface
var baseObj = new base();
>baseObj : base
>new base() : base
>base : typeof base
var base2Obj = new base2();
>base2Obj : base2
>new base2() : base2
>base2 : typeof base2
var b1 = [baseObj, base2Obj, ifaceObj];
>b1 : iface[]
>[baseObj, base2Obj, ifaceObj] : iface[]
>baseObj : base
>base2Obj : base2
>ifaceObj : iface
var b2 = [base2Obj, baseObj, ifaceObj];
>b2 : iface[]
>[base2Obj, baseObj, ifaceObj] : iface[]
>base2Obj : base2
>baseObj : base
>ifaceObj : iface
var b3 = [baseObj, ifaceObj, base2Obj];
>b3 : iface[]
>[baseObj, ifaceObj, base2Obj] : iface[]
>baseObj : base
>ifaceObj : iface
>base2Obj : base2
var b4 = [ifaceObj, baseObj, base2Obj];
>b4 : iface[]
>[ifaceObj, baseObj, base2Obj] : iface[]
>ifaceObj : iface
>baseObj : base
>base2Obj : base2
}
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
=== tests/cases/compiler/arrayConcat2.ts ===
var a: string[] = [];
>a : string[]
>[] : string[]
>[] : undefined[]
a.concat("hello", 'world');
>a.concat("hello", 'world') : string[]
+1 -1
View File
@@ -25,7 +25,7 @@ var y = new Array<number>();
var x2: number[] = [];
>x2 : number[]
>[] : number[]
>[] : undefined[]
var x2: number[] = new Array(1);
>x2 : number[]
@@ -1,40 +0,0 @@
tests/cases/compiler/arrayLiteralContextualType.ts(28,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'.
Type '{}' is not assignable to type 'IAnimal'.
tests/cases/compiler/arrayLiteralContextualType.ts(29,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'.
==== tests/cases/compiler/arrayLiteralContextualType.ts (2 errors) ====
interface IAnimal {
name: string;
}
class Giraffe {
name = "Giraffe";
neckLength = "3m";
}
class Elephant {
name = "Elephant";
trunkDiameter = "20cm";
}
function foo(animals: IAnimal[]) { }
function bar(animals: { [n: number]: IAnimal }) { }
foo([
new Giraffe(),
new Elephant()
]); // Legal because of the contextual type IAnimal provided by the parameter
bar([
new Giraffe(),
new Elephant()
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'.
!!! error TS2345: Type '{}' is not assignable to type 'IAnimal'.
bar(arr); // Error because of no contextual type
~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'.
@@ -26,8 +26,8 @@ bar([
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
bar(arr); // Error because of no contextual type
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
//// [arrayLiteralContextualType.js]
var Giraffe = (function () {
@@ -57,5 +57,5 @@ bar([
new Elephant()
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
bar(arr); // Error because of no contextual type
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
@@ -0,0 +1,86 @@
=== tests/cases/compiler/arrayLiteralContextualType.ts ===
interface IAnimal {
>IAnimal : IAnimal
name: string;
>name : string
}
class Giraffe {
>Giraffe : Giraffe
name = "Giraffe";
>name : string
neckLength = "3m";
>neckLength : string
}
class Elephant {
>Elephant : Elephant
name = "Elephant";
>name : string
trunkDiameter = "20cm";
>trunkDiameter : string
}
function foo(animals: IAnimal[]) { }
>foo : (animals: IAnimal[]) => void
>animals : IAnimal[]
>IAnimal : IAnimal
function bar(animals: { [n: number]: IAnimal }) { }
>bar : (animals: { [x: number]: IAnimal; }) => void
>animals : { [x: number]: IAnimal; }
>n : number
>IAnimal : IAnimal
foo([
>foo([ new Giraffe(), new Elephant()]) : void
>foo : (animals: IAnimal[]) => void
>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
new Giraffe(),
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe
new Elephant()
>new Elephant() : Elephant
>Elephant : typeof Elephant
]); // Legal because of the contextual type IAnimal provided by the parameter
bar([
>bar([ new Giraffe(), new Elephant()]) : void
>bar : (animals: { [x: number]: IAnimal; }) => void
>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
new Giraffe(),
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe
new Elephant()
>new Elephant() : Elephant
>Elephant : typeof Elephant
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
>arr : (Giraffe | Elephant)[]
>[new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe
>new Elephant() : Elephant
>Elephant : typeof Elephant
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
>foo(arr) : void
>foo : (animals: IAnimal[]) => void
>arr : (Giraffe | Elephant)[]
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
>bar(arr) : void
>bar : (animals: { [x: number]: IAnimal; }) => void
>arr : (Giraffe | Elephant)[]
@@ -7,5 +7,5 @@ function panic(val: string[], ...opt: string[]) { }
panic([], 'one', 'two');
>panic([], 'one', 'two') : void
>panic : (val: string[], ...opt: string[]) => void
>[] : string[]
>[] : undefined[]
@@ -25,7 +25,7 @@ class ActionB extends Action {
var x1: Action[] = [
>x1 : Action[]
>Action : Action
>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Action[]
>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : ({ id: number; trueness: boolean; } | { id: number; name: string; })[]
{ id: 2, trueness: false },
>{ id: 2, trueness: false } : { id: number; trueness: boolean; }
@@ -42,7 +42,7 @@ var x1: Action[] = [
var x2: Action[] = [
>x2 : Action[]
>Action : Action
>[ new ActionA(), new ActionB()] : Action[]
>[ new ActionA(), new ActionB()] : (ActionA | ActionB)[]
new ActionA(),
>new ActionA() : ActionA
@@ -78,7 +78,7 @@ var z1: { id: number }[] =
>id : number
[
>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : { id: number; }[]
>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : ({ id: number; trueness: boolean; } | { id: number; name: string; })[]
{ id: 2, trueness: false },
>{ id: 2, trueness: false } : { id: number; trueness: boolean; }
@@ -97,7 +97,7 @@ var z2: { id: number }[] =
>id : number
[
>[ new ActionA(), new ActionB() ] : { id: number; }[]
>[ new ActionA(), new ActionB() ] : (ActionA | ActionB)[]
new ActionA(),
>new ActionA() : ActionA
@@ -114,7 +114,7 @@ var z3: { id: number }[] =
>id : number
[
>[ new Action(), new ActionA(), new ActionB() ] : { id: number; }[]
>[ new Action(), new ActionA(), new ActionB() ] : Action[]
new Action(),
>new Action() : Action
@@ -17,27 +17,27 @@ var c: { x: number; a?: number };
>a : number
var as = [a, b]; // { x: number; y?: number };[]
>as : { x: number; y?: number; }[]
>[a, b] : { x: number; y?: number; }[]
>as : ({ x: number; y?: number; } | { x: number; z?: number; })[]
>[a, b] : ({ x: number; y?: number; } | { x: number; z?: number; })[]
>a : { x: number; y?: number; }
>b : { x: number; z?: number; }
var bs = [b, a]; // { x: number; z?: number };[]
>bs : { x: number; z?: number; }[]
>[b, a] : { x: number; z?: number; }[]
>bs : ({ x: number; y?: number; } | { x: number; z?: number; })[]
>[b, a] : ({ x: number; y?: number; } | { x: number; z?: number; })[]
>b : { x: number; z?: number; }
>a : { x: number; y?: number; }
var cs = [a, b, c]; // { x: number; y?: number };[]
>cs : { x: number; y?: number; }[]
>[a, b, c] : { x: number; y?: number; }[]
>cs : ({ x: number; y?: number; } | { x: number; z?: number; } | { x: number; a?: number; })[]
>[a, b, c] : ({ x: number; y?: number; } | { x: number; z?: number; } | { x: number; a?: number; })[]
>a : { x: number; y?: number; }
>b : { x: number; z?: number; }
>c : { x: number; a?: number; }
var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[]
>ds : { (x: Object): number; }[]
>[(x: Object) => 1, (x: string) => 2] : { (x: Object): number; }[]
>ds : ((x: Object) => number)[]
>[(x: Object) => 1, (x: string) => 2] : ((x: Object) => number)[]
>(x: Object) => 1 : (x: Object) => number
>x : Object
>Object : Object
@@ -45,8 +45,8 @@ var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[]
>x : string
var es = [(x: string) => 2, (x: Object) => 1]; // { (x:string) => number }[]
>es : { (x: string): number; }[]
>[(x: string) => 2, (x: Object) => 1] : { (x: string): number; }[]
>es : ((x: string) => number)[]
>[(x: string) => 2, (x: Object) => 1] : ((x: string) => number)[]
>(x: string) => 2 : (x: string) => number
>x : string
>(x: Object) => 1 : (x: Object) => number
@@ -54,8 +54,8 @@ var es = [(x: string) => 2, (x: Object) => 1]; // { (x:string) => number }[]
>Object : Object
var fs = [(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2]; // (a: { x: number; y?: number }) => number[]
>fs : { (a: { x: number; y?: number; }): number; }[]
>[(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2] : { (a: { x: number; y?: number; }): number; }[]
>fs : (((a: { x: number; y?: number; }) => number) | ((b: { x: number; z?: number; }) => number))[]
>[(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2] : (((a: { x: number; y?: number; }) => number) | ((b: { x: number; z?: number; }) => number))[]
>(a: { x: number; y?: number }) => 1 : (a: { x: number; y?: number; }) => number
>a : { x: number; y?: number; }
>x : number
@@ -66,8 +66,8 @@ var fs = [(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) =>
>z : number
var gs = [(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1]; // (b: { x: number; z?: number }) => number[]
>gs : { (b: { x: number; z?: number; }): number; }[]
>[(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1] : { (b: { x: number; z?: number; }): number; }[]
>gs : (((b: { x: number; z?: number; }) => number) | ((a: { x: number; y?: number; }) => number))[]
>[(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1] : (((b: { x: number; z?: number; }) => number) | ((a: { x: number; y?: number; }) => number))[]
>(b: { x: number; z?: number }) => 2 : (b: { x: number; z?: number; }) => number
>b : { x: number; z?: number; }
>x : number
@@ -2,28 +2,21 @@
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
var arr2 = [[null], [1], ['']];
var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
var stringArrArr: string[][];
var stringArr = ['', ""];
var stringArr: string[];
var numberArr = [0, 0.0, 0x00, 1e1];
var numberArr: number[];
var boolArr = [false, true, false, true];
var boolArr: boolean[];
class C { private p; }
var classArr = [new C(), new C()];
var classArr: C[]; // Should be OK
var classTypeArray = [C, C, C];
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
@@ -31,7 +24,6 @@ var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2: Array<{}>; // Should be OK
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
@@ -53,31 +45,23 @@ var __extends = this.__extends || function (d, b) {
d.prototype = new __();
};
var arr1 = [[], [1], ['']];
var arr1; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
var arr2 = [[null], [1], ['']];
var arr2; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
var stringArrArr;
var stringArr = ['', ""];
var stringArr;
var numberArr = [0, 0.0, 0x00, 1e1];
var numberArr;
var boolArr = [false, true, false, true];
var boolArr;
var C = (function () {
function C() {
}
return C;
})();
var classArr = [new C(), new C()];
var classArr; // Should be OK
var classTypeArray = [C, C, C];
var classTypeArray; // Should OK, not be a parse error
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
var context1 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2; // Should be OK
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
var Base = (function () {
function Base() {
+9 -35
View File
@@ -2,25 +2,19 @@
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
>arr1 : {}[]
>[[], [1], ['']] : {}[]
>arr1 : (string[] | number[])[]
>[[], [1], ['']] : (string[] | number[])[]
>[] : undefined[]
>[1] : number[]
>[''] : string[]
var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
>arr1 : {}[]
var arr2 = [[null], [1], ['']];
>arr2 : {}[]
>[[null], [1], ['']] : {}[]
>arr2 : (string[] | number[])[]
>[[null], [1], ['']] : (string[] | number[])[]
>[null] : null[]
>[1] : number[]
>[''] : string[]
var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
>arr2 : {}[]
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
@@ -29,30 +23,18 @@ var stringArrArr = [[''], [""]];
>[''] : string[]
>[""] : string[]
var stringArrArr: string[][];
>stringArrArr : string[][]
var stringArr = ['', ""];
>stringArr : string[]
>['', ""] : string[]
var stringArr: string[];
>stringArr : string[]
var numberArr = [0, 0.0, 0x00, 1e1];
>numberArr : number[]
>[0, 0.0, 0x00, 1e1] : number[]
var numberArr: number[];
>numberArr : number[]
var boolArr = [false, true, false, true];
>boolArr : boolean[]
>[false, true, false, true] : boolean[]
var boolArr: boolean[];
>boolArr : boolean[]
class C { private p; }
>C : C
>p : any
@@ -65,10 +47,6 @@ var classArr = [new C(), new C()];
>new C() : C
>C : typeof C
var classArr: C[]; // Should be OK
>classArr : C[]
>C : C
var classTypeArray = [C, C, C];
>classTypeArray : typeof C[]
>[C, C, C] : typeof C[]
@@ -87,7 +65,7 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '
>n : number
>a : string
>b : number
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : { a: string; b: number; }[]
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
>a : string
>b : number
@@ -98,8 +76,8 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '
>c : number
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
>context2 : {}[]
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : {}[]
>context2 : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]
>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
>a : string
>b : number
@@ -109,10 +87,6 @@ var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
>b : number
>c : number
var context2: Array<{}>; // Should be OK
>context2 : {}[]
>Array : T[]
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
>Base : Base
@@ -131,7 +105,7 @@ class Derived2 extends Base { private n };
var context3: Base[] = [new Derived1(), new Derived2()];
>context3 : Base[]
>Base : Base
>[new Derived1(), new Derived2()] : Base[]
>[new Derived1(), new Derived2()] : (Derived1 | Derived2)[]
>new Derived1() : Derived1
>Derived1 : typeof Derived1
>new Derived2() : Derived2
@@ -141,7 +115,7 @@ var context3: Base[] = [new Derived1(), new Derived2()];
var context4: Base[] = [new Derived1(), new Derived1()];
>context4 : Base[]
>Base : Base
>[new Derived1(), new Derived1()] : Base[]
>[new Derived1(), new Derived1()] : Derived1[]
>new Derived1() : Derived1
>Derived1 : typeof Derived1
>new Derived1() : Derived1
@@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[]
>myList : MyList<number>
var ys = [list, list2]; // {}[]
>ys : {}[]
>[list, list2] : {}[]
>ys : (List<number> | List<string>)[]
>[list, list2] : (List<number> | List<string>)[]
>list : List<number>
>list2 : List<string>
@@ -2,8 +2,8 @@
// valid uses of arrays of function types
var x = [() => 1, () => { }];
>x : { (): void; }[]
>[() => 1, () => { }] : { (): void; }[]
>x : (() => void)[]
>[() => 1, () => { }] : (() => void)[]
>() => 1 : () => number
>() => { } : () => void
@@ -11,7 +11,7 @@ var r2 = x[0]();
>r2 : void
>x[0]() : void
>x[0] : () => void
>x : { (): void; }[]
>x : (() => void)[]
class C {
>C : C
@@ -1,36 +1,38 @@
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]':
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => number':
Type '{}' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]':
Property '0' is missing in type '{}[]'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ====
var numStrTuple: [number, string];
var numNumTuple: [number, number];
var numEmptyObjTuple: [number, {}];
var emptyObjTuple: [{}];
var numArray: number[];
var emptyObjArray: {}[];
// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;
// error
numArray = numStrTuple;
~~~~~~~~
!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => {}' is not assignable to type '() => number':
!!! error TS2322: Type '{}' is not assignable to type 'number'.
emptyObjTuple = emptyObjArray;
~~~~~~~~~~~~~
!!! error TS2322: Type '{}[]' is not assignable to type '[{}]':
!!! error TS2322: Property '0' is missing in type '{}[]'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]':
Types of property 'pop' are incompatible:
Type '() => string | number' is not assignable to type '() => number':
Type 'string | number' is not assignable to type 'number':
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]':
Property '0' is missing in type '{}[]'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ====
var numStrTuple: [number, string];
var numNumTuple: [number, number];
var numEmptyObjTuple: [number, {}];
var emptyObjTuple: [{}];
var numArray: number[];
var emptyObjArray: {}[];
// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;
// error
numArray = numStrTuple;
~~~~~~~~
!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => string | number' is not assignable to type '() => number':
!!! error TS2322: Type 'string | number' is not assignable to type 'number':
!!! error TS2322: Type 'string' is not assignable to type 'number'.
emptyObjTuple = emptyObjArray;
~~~~~~~~~~~~~
!!! error TS2322: Type '{}[]' is not assignable to type '[{}]':
!!! error TS2322: Property '0' is missing in type '{}[]'.
@@ -1,4 +1,4 @@
//// [assignmentCompatBetweenTupleAndArray.ts]
//// [assignmentCompatBetweenTupleAndArray.ts]
var numStrTuple: [number, string];
var numNumTuple: [number, number];
var numEmptyObjTuple: [number, {}];
@@ -17,21 +17,21 @@ emptyObjArray = numEmptyObjTuple;
// error
numArray = numStrTuple;
emptyObjTuple = emptyObjArray;
//// [assignmentCompatBetweenTupleAndArray.js]
var numStrTuple;
var numNumTuple;
var numEmptyObjTuple;
var emptyObjTuple;
var numArray;
var emptyObjArray;
// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;
// error
numArray = numStrTuple;
emptyObjTuple = emptyObjArray;
//// [assignmentCompatBetweenTupleAndArray.js]
var numStrTuple;
var numNumTuple;
var numEmptyObjTuple;
var emptyObjTuple;
var numArray;
var emptyObjArray;
// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;
// error
numArray = numStrTuple;
emptyObjTuple = emptyObjArray;
@@ -6,6 +6,6 @@ function method() {
>dictionary : { [x: string]: string; }
><{ [index: string]: string; }>{} : { [x: string]: string; }
>index : string
>{} : { [x: string]: string; }
>{} : { [x: string]: undefined; }
}
@@ -48,14 +48,14 @@ var r3 = true ? 1 : {};
>{} : {}
var r4 = true ? a : b; // typeof a
>r4 : { x: number; y?: number; }
>true ? a : b : { x: number; y?: number; }
>r4 : { x: number; y?: number; } | { x: number; z?: number; }
>true ? a : b : { x: number; y?: number; } | { x: number; z?: number; }
>a : { x: number; y?: number; }
>b : { x: number; z?: number; }
var r5 = true ? b : a; // typeof b
>r5 : { x: number; z?: number; }
>true ? b : a : { x: number; z?: number; }
>r5 : { x: number; y?: number; } | { x: number; z?: number; }
>true ? b : a : { x: number; y?: number; } | { x: number; z?: number; }
>b : { x: number; z?: number; }
>a : { x: number; y?: number; }
@@ -72,7 +72,7 @@ var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { };
>r7 : (x: Object) => void
>x : Object
>Object : Object
>true ? (x: number) => { } : (x: Object) => { } : (x: Object) => void
>true ? (x: number) => { } : (x: Object) => { } : (x: number) => void
>(x: number) => { } : (x: number) => void
>x : number
>(x: Object) => { } : (x: Object) => void
@@ -91,7 +91,7 @@ var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => vo
var r10: Base = true ? derived : derived2; // no error since we use the contextual type in BCT
>r10 : Base
>Base : Base
>true ? derived : derived2 : Base
>true ? derived : derived2 : Derived | Derived2
>derived : Derived
>derived2 : Derived2
@@ -112,7 +112,7 @@ function foo5<T, U>(t: T, u: U): Object {
>Object : Object
return true ? t : u; // BCT is Object
>true ? t : u : Object
>true ? t : u : T | U
>t : T
>u : U
}
@@ -1,14 +1,9 @@
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(11,10): error TS2367: No best common type exists between 'number' and 'string'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(12,10): error TS2367: No best common type exists between 'Derived' and 'Derived2'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(15,12): error TS2367: No best common type exists between 'T' and 'U'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(18,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(19,12): error TS2367: No best common type exists between 'T' and 'U'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,28): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(23,12): error TS2367: No best common type exists between 'T' and 'U'.
==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (8 errors) ====
==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (3 errors) ====
// conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
// these are errors
@@ -20,24 +15,16 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC
var derived2: Derived2;
var r2 = true ? 1 : '';
~~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'number' and 'string'.
var r9 = true ? derived : derived2;
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'Derived' and 'Derived2'.
function foo<T, U>(t: T, u: U) {
return true ? t : u;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'T' and 'U'.
}
function foo2<T extends U, U>(t: T, u: U) { // Error for referencing own type parameter
~~~~~~~~~~~
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
return true ? t : u; // Ok because BCT(T, U) = U
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'T' and 'U'.
}
function foo3<T extends U, U extends V, V>(t: T, u: U) {
@@ -46,6 +33,4 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC
~~~~~~~~~~~
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
return true ? t : u;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'T' and 'U'.
}
@@ -1,4 +1,4 @@
//// [bestCommonTypeOfTuple.ts]
//// [bestCommonTypeOfTuple.ts]
function f1(x: number): string { return "foo"; }
function f2(x: number): number { return 10; }
@@ -23,36 +23,36 @@ t4 = [E1.one, E2.two, 20];
var e1 = t1[2]; // {}
var e2 = t2[2]; // {}
var e3 = t3[2]; // any
var e4 = t4[3]; // number
//// [bestCommonTypeOfTuple.js]
function f1(x) {
return "foo";
}
function f2(x) {
return 10;
}
function f3(x) {
return true;
}
var E1;
(function (E1) {
E1[E1["one"] = 0] = "one";
})(E1 || (E1 = {}));
var E2;
(function (E2) {
E2[E2["two"] = 0] = "two";
})(E2 || (E2 = {}));
var t1;
var t2;
var t3;
var t4;
// no error
t1 = [f1, f2];
t2 = [0 /* one */, 0 /* two */];
t3 = [5, undefined];
t4 = [0 /* one */, 0 /* two */, 20];
var e1 = t1[2]; // {}
var e2 = t2[2]; // {}
var e3 = t3[2]; // any
var e4 = t4[3]; // number
var e4 = t4[3]; // number
//// [bestCommonTypeOfTuple.js]
function f1(x) {
return "foo";
}
function f2(x) {
return 10;
}
function f3(x) {
return true;
}
var E1;
(function (E1) {
E1[E1["one"] = 0] = "one";
})(E1 || (E1 = {}));
var E2;
(function (E2) {
E2[E2["two"] = 0] = "two";
})(E2 || (E2 = {}));
var t1;
var t2;
var t3;
var t4;
// no error
t1 = [f1, f2];
t2 = [0 /* one */, 0 /* two */];
t3 = [5, undefined];
t4 = [0 /* one */, 0 /* two */, 20];
var e1 = t1[2]; // {}
var e2 = t2[2]; // {}
var e3 = t3[2]; // any
var e4 = t4[3]; // number
@@ -1,96 +1,96 @@
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts ===
function f1(x: number): string { return "foo"; }
>f1 : (x: number) => string
>x : number
function f2(x: number): number { return 10; }
>f2 : (x: number) => number
>x : number
function f3(x: number): boolean { return true; }
>f3 : (x: number) => boolean
>x : number
enum E1 { one }
>E1 : E1
>one : E1
enum E2 { two }
>E2 : E2
>two : E2
var t1: [(x: number) => string, (x: number) => number];
>t1 : [(x: number) => string, (x: number) => number]
>x : number
>x : number
var t2: [E1, E2];
>t2 : [E1, E2]
>E1 : E1
>E2 : E2
var t3: [number, any];
>t3 : [number, any]
var t4: [E1, E2, number];
>t4 : [E1, E2, number]
>E1 : E1
>E2 : E2
// no error
t1 = [f1, f2];
>t1 = [f1, f2] : [(x: number) => string, (x: number) => number]
>t1 : [(x: number) => string, (x: number) => number]
>[f1, f2] : [(x: number) => string, (x: number) => number]
>f1 : (x: number) => string
>f2 : (x: number) => number
t2 = [E1.one, E2.two];
>t2 = [E1.one, E2.two] : [E1, E2]
>t2 : [E1, E2]
>[E1.one, E2.two] : [E1, E2]
>E1.one : E1
>E1 : typeof E1
>one : E1
>E2.two : E2
>E2 : typeof E2
>two : E2
t3 = [5, undefined];
>t3 = [5, undefined] : [number, undefined]
>t3 : [number, any]
>[5, undefined] : [number, undefined]
>undefined : undefined
t4 = [E1.one, E2.two, 20];
>t4 = [E1.one, E2.two, 20] : [E1, E2, number]
>t4 : [E1, E2, number]
>[E1.one, E2.two, 20] : [E1, E2, number]
>E1.one : E1
>E1 : typeof E1
>one : E1
>E2.two : E2
>E2 : typeof E2
>two : E2
var e1 = t1[2]; // {}
>e1 : {}
>t1[2] : {}
>t1 : [(x: number) => string, (x: number) => number]
var e2 = t2[2]; // {}
>e2 : {}
>t2[2] : {}
>t2 : [E1, E2]
var e3 = t3[2]; // any
>e3 : any
>t3[2] : any
>t3 : [number, any]
var e4 = t4[3]; // number
>e4 : number
>t4[3] : number
>t4 : [E1, E2, number]
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts ===
function f1(x: number): string { return "foo"; }
>f1 : (x: number) => string
>x : number
function f2(x: number): number { return 10; }
>f2 : (x: number) => number
>x : number
function f3(x: number): boolean { return true; }
>f3 : (x: number) => boolean
>x : number
enum E1 { one }
>E1 : E1
>one : E1
enum E2 { two }
>E2 : E2
>two : E2
var t1: [(x: number) => string, (x: number) => number];
>t1 : [(x: number) => string, (x: number) => number]
>x : number
>x : number
var t2: [E1, E2];
>t2 : [E1, E2]
>E1 : E1
>E2 : E2
var t3: [number, any];
>t3 : [number, any]
var t4: [E1, E2, number];
>t4 : [E1, E2, number]
>E1 : E1
>E2 : E2
// no error
t1 = [f1, f2];
>t1 = [f1, f2] : [(x: number) => string, (x: number) => number]
>t1 : [(x: number) => string, (x: number) => number]
>[f1, f2] : [(x: number) => string, (x: number) => number]
>f1 : (x: number) => string
>f2 : (x: number) => number
t2 = [E1.one, E2.two];
>t2 = [E1.one, E2.two] : [E1, E2]
>t2 : [E1, E2]
>[E1.one, E2.two] : [E1, E2]
>E1.one : E1
>E1 : typeof E1
>one : E1
>E2.two : E2
>E2 : typeof E2
>two : E2
t3 = [5, undefined];
>t3 = [5, undefined] : [number, undefined]
>t3 : [number, any]
>[5, undefined] : [number, undefined]
>undefined : undefined
t4 = [E1.one, E2.two, 20];
>t4 = [E1.one, E2.two, 20] : [E1, E2, number]
>t4 : [E1, E2, number]
>[E1.one, E2.two, 20] : [E1, E2, number]
>E1.one : E1
>E1 : typeof E1
>one : E1
>E2.two : E2
>E2 : typeof E2
>two : E2
var e1 = t1[2]; // {}
>e1 : ((x: number) => string) | ((x: number) => number)
>t1[2] : ((x: number) => string) | ((x: number) => number)
>t1 : [(x: number) => string, (x: number) => number]
var e2 = t2[2]; // {}
>e2 : E1 | E2
>t2[2] : E1 | E2
>t2 : [E1, E2]
var e3 = t3[2]; // any
>e3 : any
>t3[2] : any
>t3 : [number, any]
var e4 = t4[3]; // number
>e4 : number
>t4[3] : number
>t4 : [E1, E2, number]
@@ -1,4 +1,4 @@
//// [bestCommonTypeOfTuple2.ts]
//// [bestCommonTypeOfTuple2.ts]
interface base { }
interface base1 { i }
class C implements base { c }
@@ -20,58 +20,58 @@ var e21 = t2[4]; // {}
var e31 = t3[4]; // C1
var e41 = t4[2]; // base1
var e51 = t5[2]; // {}
//// [bestCommonTypeOfTuple2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C = (function () {
function C() {
}
return C;
})();
var D = (function () {
function D() {
}
return D;
})();
var E = (function () {
function E() {
}
return E;
})();
var F = (function (_super) {
__extends(F, _super);
function F() {
_super.apply(this, arguments);
}
return F;
})(C);
var C1 = (function () {
function C1() {
this.i = "foo";
}
return C1;
})();
var D1 = (function (_super) {
__extends(D1, _super);
function D1() {
_super.apply(this, arguments);
this.i = "bar";
}
return D1;
})(C1);
var t1;
var t2;
var t3;
var t4;
var t5;
var e11 = t1[4]; // base
var e21 = t2[4]; // {}
var e31 = t3[4]; // C1
var e41 = t4[2]; // base1
var e51 = t5[2]; // {}
//// [bestCommonTypeOfTuple2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C = (function () {
function C() {
}
return C;
})();
var D = (function () {
function D() {
}
return D;
})();
var E = (function () {
function E() {
}
return E;
})();
var F = (function (_super) {
__extends(F, _super);
function F() {
_super.apply(this, arguments);
}
return F;
})(C);
var C1 = (function () {
function C1() {
this.i = "foo";
}
return C1;
})();
var D1 = (function (_super) {
__extends(D1, _super);
function D1() {
_super.apply(this, arguments);
this.i = "bar";
}
return D1;
})(C1);
var t1;
var t2;
var t3;
var t4;
var t5;
var e11 = t1[4]; // base
var e21 = t2[4]; // {}
var e31 = t3[4]; // C1
var e41 = t4[2]; // base1
var e51 = t5[2]; // {}
@@ -1,90 +1,90 @@
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2.ts ===
interface base { }
>base : base
interface base1 { i }
>base1 : base1
>i : any
class C implements base { c }
>C : C
>base : base
>c : any
class D implements base { d }
>D : D
>base : base
>d : any
class E implements base { e }
>E : E
>base : base
>e : any
class F extends C { f }
>F : F
>C : C
>f : any
class C1 implements base1 { i = "foo"; c }
>C1 : C1
>base1 : base1
>i : string
>c : any
class D1 extends C1 { i = "bar"; d }
>D1 : D1
>C1 : C1
>i : string
>d : any
var t1: [C, base];
>t1 : [C, base]
>C : C
>base : base
var t2: [C, D];
>t2 : [C, D]
>C : C
>D : D
var t3: [C1, D1];
>t3 : [C1, D1]
>C1 : C1
>D1 : D1
var t4: [base1, C1];
>t4 : [base1, C1]
>base1 : base1
>C1 : C1
var t5: [C1, F]
>t5 : [C1, F]
>C1 : C1
>F : F
var e11 = t1[4]; // base
>e11 : base
>t1[4] : base
>t1 : [C, base]
var e21 = t2[4]; // {}
>e21 : {}
>t2[4] : {}
>t2 : [C, D]
var e31 = t3[4]; // C1
>e31 : C1
>t3[4] : C1
>t3 : [C1, D1]
var e41 = t4[2]; // base1
>e41 : base1
>t4[2] : base1
>t4 : [base1, C1]
var e51 = t5[2]; // {}
>e51 : {}
>t5[2] : {}
>t5 : [C1, F]
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2.ts ===
interface base { }
>base : base
interface base1 { i }
>base1 : base1
>i : any
class C implements base { c }
>C : C
>base : base
>c : any
class D implements base { d }
>D : D
>base : base
>d : any
class E implements base { e }
>E : E
>base : base
>e : any
class F extends C { f }
>F : F
>C : C
>f : any
class C1 implements base1 { i = "foo"; c }
>C1 : C1
>base1 : base1
>i : string
>c : any
class D1 extends C1 { i = "bar"; d }
>D1 : D1
>C1 : C1
>i : string
>d : any
var t1: [C, base];
>t1 : [C, base]
>C : C
>base : base
var t2: [C, D];
>t2 : [C, D]
>C : C
>D : D
var t3: [C1, D1];
>t3 : [C1, D1]
>C1 : C1
>D1 : D1
var t4: [base1, C1];
>t4 : [base1, C1]
>base1 : base1
>C1 : C1
var t5: [C1, F]
>t5 : [C1, F]
>C1 : C1
>F : F
var e11 = t1[4]; // base
>e11 : base
>t1[4] : base
>t1 : [C, base]
var e21 = t2[4]; // {}
>e21 : C | D
>t2[4] : C | D
>t2 : [C, D]
var e31 = t3[4]; // C1
>e31 : C1
>t3[4] : C1
>t3 : [C1, D1]
var e41 = t4[2]; // base1
>e41 : base1
>t4[2] : base1
>t4 : [base1, C1]
var e51 = t5[2]; // {}
>e51 : F | C1
>t5[2] : F | C1
>t5 : [C1, F]
@@ -1,59 +1,59 @@
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(3,1): error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(9,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(14,1): error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(20,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(24,1): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(28,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
==== tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts (8 errors) ====
var a = true;
var b = 1;
a ^= a;
~~~~~~
!!! error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead.
a = true;
b ^= b;
b = 1;
a ^= b;
~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
a = true;
b ^= a;
~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
b = 1;
var c = false;
var d = 2;
c &= c;
~~~~~~
!!! error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead.
c = false;
d &= d;
d = 2;
c &= d;
~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
c = false;
d &= c;
~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
var e = true;
var f = 0;
e |= e;
~~~~~~
!!! error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead.
e = true;
f |= f;
f = 0;
e |= f;
~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
e = true;
f |= f;
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(3,1): error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(9,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(14,1): error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(20,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(24,1): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead.
tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(28,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
==== tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts (8 errors) ====
var a = true;
var b = 1;
a ^= a;
~~~~~~
!!! error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead.
a = true;
b ^= b;
b = 1;
a ^= b;
~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
a = true;
b ^= a;
~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
b = 1;
var c = false;
var d = 2;
c &= c;
~~~~~~
!!! error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead.
c = false;
d &= d;
d = 2;
c &= d;
~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
c = false;
d &= c;
~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
var e = true;
var f = 0;
e |= e;
~~~~~~
!!! error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead.
e = true;
f |= f;
f = 0;
e |= f;
~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
e = true;
f |= f;
@@ -1,4 +1,4 @@
//// [bitwiseCompoundAssignmentOperators.ts]
//// [bitwiseCompoundAssignmentOperators.ts]
var a = true;
var b = 1;
a ^= a;
@@ -30,34 +30,34 @@ e |= f;
e = true;
f |= f;
//// [bitwiseCompoundAssignmentOperators.js]
var a = true;
var b = 1;
a ^= a;
a = true;
b ^= b;
b = 1;
a ^= b;
a = true;
b ^= a;
b = 1;
var c = false;
var d = 2;
c &= c;
c = false;
d &= d;
d = 2;
c &= d;
c = false;
d &= c;
var e = true;
var f = 0;
e |= e;
e = true;
f |= f;
f = 0;
e |= f;
e = true;
f |= f;
//// [bitwiseCompoundAssignmentOperators.js]
var a = true;
var b = 1;
a ^= a;
a = true;
b ^= b;
b = 1;
a ^= b;
a = true;
b ^= a;
b = 1;
var c = false;
var d = 2;
c &= c;
c = false;
d &= d;
d = 2;
c &= d;
c = false;
d &= c;
var e = true;
var f = 0;
e |= e;
e = true;
f |= f;
f = 0;
e |= f;
e = true;
f |= f;
@@ -1,40 +1,40 @@
//// [bitwiseNotOperatorWithEnumType.ts]
// ~ operator on enum type
enum ENUM1 { 1, 2, "" };
enum ENUM1 { A, B, "" };
// enum type var
var ResultIsNumber1 = ~ENUM1;
// enum type expressions
var ResultIsNumber2 = ~ENUM1[1];
var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]);
var ResultIsNumber2 = ~ENUM1["A"];
var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]);
// multiple ~ operators
var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]);
var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B);
// miss assignment operators
~ENUM1;
~ENUM1[1];
~ENUM1[1], ~ENUM1[2];
~ENUM1["A"];
~ENUM1.A, ~ENUM1["B"];
//// [bitwiseNotOperatorWithEnumType.js]
// ~ operator on enum type
var ENUM1;
(function (ENUM1) {
ENUM1[ENUM1["1"] = 0] = "1";
ENUM1[ENUM1["2"] = 1] = "2";
ENUM1[ENUM1["A"] = 0] = "A";
ENUM1[ENUM1["B"] = 1] = "B";
ENUM1[ENUM1[""] = 2] = "";
})(ENUM1 || (ENUM1 = {}));
;
// enum type var
var ResultIsNumber1 = ~ENUM1;
// enum type expressions
var ResultIsNumber2 = ~ENUM1[1];
var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]);
var ResultIsNumber2 = ~ENUM1["A"];
var ResultIsNumber3 = ~(0 /* A */ + ENUM1["B"]);
// multiple ~ operators
var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]);
var ResultIsNumber4 = ~~~(ENUM1["A"] + 1 /* B */);
// miss assignment operators
~ENUM1;
~ENUM1[1];
~ENUM1[1], ~ENUM1[2];
~ENUM1["A"];
~0 /* A */, ~ENUM1["B"];
@@ -1,8 +1,10 @@
=== tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithEnumType.ts ===
// ~ operator on enum type
enum ENUM1 { 1, 2, "" };
enum ENUM1 { A, B, "" };
>ENUM1 : ENUM1
>A : ENUM1
>B : ENUM1
// enum type var
var ResultIsNumber1 = ~ENUM1;
@@ -11,51 +13,54 @@ var ResultIsNumber1 = ~ENUM1;
>ENUM1 : typeof ENUM1
// enum type expressions
var ResultIsNumber2 = ~ENUM1[1];
var ResultIsNumber2 = ~ENUM1["A"];
>ResultIsNumber2 : number
>~ENUM1[1] : number
>ENUM1[1] : ENUM1
>~ENUM1["A"] : number
>ENUM1["A"] : ENUM1
>ENUM1 : typeof ENUM1
var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]);
var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]);
>ResultIsNumber3 : number
>~(ENUM1[1] + ENUM1[2]) : number
>(ENUM1[1] + ENUM1[2]) : number
>ENUM1[1] + ENUM1[2] : number
>ENUM1[1] : ENUM1
>~(ENUM1.A + ENUM1["B"]) : number
>(ENUM1.A + ENUM1["B"]) : number
>ENUM1.A + ENUM1["B"] : number
>ENUM1.A : ENUM1
>ENUM1 : typeof ENUM1
>ENUM1[2] : ENUM1
>A : ENUM1
>ENUM1["B"] : ENUM1
>ENUM1 : typeof ENUM1
// multiple ~ operators
var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]);
var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B);
>ResultIsNumber4 : number
>~~~(ENUM1[1] + ENUM1[2]) : number
>~~(ENUM1[1] + ENUM1[2]) : number
>~(ENUM1[1] + ENUM1[2]) : number
>(ENUM1[1] + ENUM1[2]) : number
>ENUM1[1] + ENUM1[2] : number
>ENUM1[1] : ENUM1
>~~~(ENUM1["A"] + ENUM1.B) : number
>~~(ENUM1["A"] + ENUM1.B) : number
>~(ENUM1["A"] + ENUM1.B) : number
>(ENUM1["A"] + ENUM1.B) : number
>ENUM1["A"] + ENUM1.B : number
>ENUM1["A"] : ENUM1
>ENUM1 : typeof ENUM1
>ENUM1[2] : ENUM1
>ENUM1.B : ENUM1
>ENUM1 : typeof ENUM1
>B : ENUM1
// miss assignment operators
~ENUM1;
>~ENUM1 : number
>ENUM1 : typeof ENUM1
~ENUM1[1];
>~ENUM1[1] : number
>ENUM1[1] : ENUM1
~ENUM1["A"];
>~ENUM1["A"] : number
>ENUM1["A"] : ENUM1
>ENUM1 : typeof ENUM1
~ENUM1[1], ~ENUM1[2];
>~ENUM1[1], ~ENUM1[2] : number
>~ENUM1[1] : number
>ENUM1[1] : ENUM1
~ENUM1.A, ~ENUM1["B"];
>~ENUM1.A, ~ENUM1["B"] : number
>~ENUM1.A : number
>ENUM1.A : ENUM1
>ENUM1 : typeof ENUM1
>~ENUM1[2] : number
>ENUM1[2] : ENUM1
>A : ENUM1
>~ENUM1["B"] : number
>ENUM1["B"] : ENUM1
>ENUM1 : typeof ENUM1
@@ -1,61 +1,73 @@
tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other:
Types of property '1' are incompatible:
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other:
Types of property '0' are incompatible:
Type 'C' is not assignable to type 'A':
Property 'a' is missing in type 'C'.
tests/cases/conformance/types/tuple/castingTuple.ts(26,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'.
tests/cases/conformance/types/tuple/castingTuple.ts(26,14): error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other:
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => number':
Type '{}' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'.
==== tests/cases/conformance/types/tuple/castingTuple.ts (5 errors) ====
interface I { }
class A { a = 10; }
class C implements I { c };
class D implements I { d };
class E extends A { e };
class F extends A { f };
enum E1 { one }
enum E2 { one }
// no error
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // {}
var t10: [E1, E2] = [E1.one, E2.one];
var t11 = <[number, number]>t10;
var array1 = <{}[]>emptyObjTuple;
// error
var t3 = <[number, number]>numStrTuple;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other:
!!! error TS2353: Types of property '1' are incompatible:
!!! error TS2353: Type 'string' is not assignable to type 'number'.
var t9 = <[A, I]>classCDTuple;
~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other:
!!! error TS2353: Types of property '0' are incompatible:
!!! error TS2353: Type 'C' is not assignable to type 'A':
!!! error TS2353: Property 'a' is missing in type 'C'.
var array1 = <number[]>numStrTuple;
~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other:
!!! error TS2353: Types of property 'pop' are incompatible:
!!! error TS2353: Type '() => {}' is not assignable to type '() => number':
!!! error TS2353: Type '{}' is not assignable to type 'number'.
t4[2] = 10;
~~
tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other:
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/castingTuple.ts(16,21): error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other:
Property '2' is missing in type '[C, D]'.
tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other:
Types of property '1' are incompatible:
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other:
Types of property '0' are incompatible:
Type 'C' is not assignable to type 'A':
Property 'a' is missing in type 'C'.
tests/cases/conformance/types/tuple/castingTuple.ts(26,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'.
tests/cases/conformance/types/tuple/castingTuple.ts(26,14): error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other:
Types of property 'pop' are incompatible:
Type '() => string | number' is not assignable to type '() => number':
Type 'string | number' is not assignable to type 'number':
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'.
==== tests/cases/conformance/types/tuple/castingTuple.ts (7 errors) ====
interface I { }
class A { a = 10; }
class C implements I { c };
class D implements I { d };
class E extends A { e };
class F extends A { f };
enum E1 { one }
enum E2 { one }
// no error
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other:
!!! error TS2353: Property '2' is missing in type '[number, string]'.
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other:
!!! error TS2353: Property '2' is missing in type '[C, D]'.
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // {}
var t10: [E1, E2] = [E1.one, E2.one];
var t11 = <[number, number]>t10;
var array1 = <{}[]>emptyObjTuple;
// error
var t3 = <[number, number]>numStrTuple;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other:
!!! error TS2353: Types of property '1' are incompatible:
!!! error TS2353: Type 'string' is not assignable to type 'number'.
var t9 = <[A, I]>classCDTuple;
~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other:
!!! error TS2353: Types of property '0' are incompatible:
!!! error TS2353: Type 'C' is not assignable to type 'A':
!!! error TS2353: Property 'a' is missing in type 'C'.
var array1 = <number[]>numStrTuple;
~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other:
!!! error TS2353: Types of property 'pop' are incompatible:
!!! error TS2353: Type '() => string | number' is not assignable to type '() => number':
!!! error TS2353: Type 'string | number' is not assignable to type 'number':
!!! error TS2353: Type 'string' is not assignable to type 'number'.
t4[2] = 10;
~~
!!! error TS2304: Cannot find name 't4'.
+69 -69
View File
@@ -1,4 +1,4 @@
//// [castingTuple.ts]
//// [castingTuple.ts]
interface I { }
class A { a = 10; }
class C implements I { c };
@@ -25,71 +25,71 @@ var array1 = <{}[]>emptyObjTuple;
var t3 = <[number, number]>numStrTuple;
var t9 = <[A, I]>classCDTuple;
var array1 = <number[]>numStrTuple;
t4[2] = 10;
//// [castingTuple.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var A = (function () {
function A() {
this.a = 10;
}
return A;
})();
var C = (function () {
function C() {
}
return C;
})();
;
var D = (function () {
function D() {
}
return D;
})();
;
var E = (function (_super) {
__extends(E, _super);
function E() {
_super.apply(this, arguments);
}
return E;
})(A);
;
var F = (function (_super) {
__extends(F, _super);
function F() {
_super.apply(this, arguments);
}
return F;
})(A);
;
var E1;
(function (E1) {
E1[E1["one"] = 0] = "one";
})(E1 || (E1 = {}));
var E2;
(function (E2) {
E2[E2["one"] = 0] = "one";
})(E2 || (E2 = {}));
// no error
var numStrTuple = [5, "foo"];
var emptyObjTuple = numStrTuple;
var numStrBoolTuple = numStrTuple;
var classCDTuple = [new C(), new D()];
var interfaceIITuple = classCDTuple;
var classCDATuple = classCDTuple;
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // {}
var t10 = [0 /* one */, 0 /* one */];
var t11 = t10;
var array1 = emptyObjTuple;
// error
var t3 = numStrTuple;
var t9 = classCDTuple;
var array1 = numStrTuple;
t4[2] = 10;
t4[2] = 10;
//// [castingTuple.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var A = (function () {
function A() {
this.a = 10;
}
return A;
})();
var C = (function () {
function C() {
}
return C;
})();
;
var D = (function () {
function D() {
}
return D;
})();
;
var E = (function (_super) {
__extends(E, _super);
function E() {
_super.apply(this, arguments);
}
return E;
})(A);
;
var F = (function (_super) {
__extends(F, _super);
function F() {
_super.apply(this, arguments);
}
return F;
})(A);
;
var E1;
(function (E1) {
E1[E1["one"] = 0] = "one";
})(E1 || (E1 = {}));
var E2;
(function (E2) {
E2[E2["one"] = 0] = "one";
})(E2 || (E2 = {}));
// no error
var numStrTuple = [5, "foo"];
var emptyObjTuple = numStrTuple;
var numStrBoolTuple = numStrTuple;
var classCDTuple = [new C(), new D()];
var interfaceIITuple = classCDTuple;
var classCDATuple = classCDTuple;
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // {}
var t10 = [0 /* one */, 0 /* one */];
var t11 = t10;
var array1 = emptyObjTuple;
// error
var t3 = numStrTuple;
var t9 = classCDTuple;
var array1 = numStrTuple;
t4[2] = 10;
@@ -1,215 +0,0 @@
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(40,12): error TS2365: Operator '<' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(49,12): error TS2365: Operator '>' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(57,12): error TS2365: Operator '>' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(66,12): error TS2365: Operator '<=' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(74,12): error TS2365: Operator '<=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(83,12): error TS2365: Operator '>=' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(91,12): error TS2365: Operator '>=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(100,12): error TS2365: Operator '==' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(108,12): error TS2365: Operator '==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(117,12): error TS2365: Operator '!=' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(125,12): error TS2365: Operator '!=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(134,12): error TS2365: Operator '===' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(142,12): error TS2365: Operator '===' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(151,12): error TS2365: Operator '!==' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(159,12): error TS2365: Operator '!==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts (16 errors) ====
class Base {
public a: string;
}
class Derived extends Base {
public b: string;
}
var a1: { fn<T>(x: T): T };
var b1: { fn(x: string): string };
var a2: { fn<T>(x: T): T };
var b2: { fn(x: string, y: number): string };
var a3: { fn<T, U>(x: T, y: U): T };
var b3: { fn(x: string, y: number): string };
var a4: { fn<T>(x?: T): T };
var b4: { fn(x?: string): string };
var a5: { fn<T>(...x: T[]): T };
var b5: { fn(...x: string[]): string };
var a6: { fn<T>(x: T, y: T): T };
var b6: { fn(x: string, y: number): {} };
//var a7: { fn<T, U extends T>(x: T, y: U): T };
var b7: { fn(x: Base, y: Derived): Base };
// operator <
var r1a1 = a1 < b1;
var r1a2 = a2 < b2;
~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r1a3 = a3 < b3;
var r1a4 = a4 < b4;
var r1a5 = a5 < b5;
var r1a6 = a6 < b6;
//var r1a7 = a7 < b7;
var r1b1 = b1 < a1;
var r1b2 = b2 < a2;
~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r1b3 = b3 < a3;
var r1b4 = b4 < a4;
var r1b5 = b5 < a5;
var r1b6 = b6 < a6;
//var r1b7 = b7 < a7;
// operator >
var r2a1 = a1 > b1;
var r2a2 = a2 > b2;
~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r2a3 = a3 > b3;
var r2a4 = a4 > b4;
var r2a5 = a5 > b5;
var r2a6 = a6 > b6;
//var r2a7 = a7 > b7;
var r2b1 = b1 > a1;
var r2b2 = b2 > a2;
~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r2b3 = b3 > a3;
var r2b4 = b4 > a4;
var r2b5 = b5 > a5;
var r2b6 = b6 > a6;
//var r2b7 = b7 > a7;
// operator <=
var r3a1 = a1 <= b1;
var r3a2 = a2 <= b2;
~~~~~~~~
!!! error TS2365: Operator '<=' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r3a3 = a3 <= b3;
var r3a4 = a4 <= b4;
var r3a5 = a5 <= b5;
var r3a6 = a6 <= b6;
//var r3a7 = a7 <= b7;
var r3b1 = b1 <= a1;
var r3b2 = b2 <= a2;
~~~~~~~~
!!! error TS2365: Operator '<=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r3b3 = b3 <= a3;
var r3b4 = b4 <= a4;
var r3b5 = b5 <= a5;
var r3b6 = b6 <= a6;
//var r3b7 = b7 <= a7;
// operator >=
var r4a1 = a1 >= b1;
var r4a2 = a2 >= b2;
~~~~~~~~
!!! error TS2365: Operator '>=' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r4a3 = a3 >= b3;
var r4a4 = a4 >= b4;
var r4a5 = a5 >= b5;
var r4a6 = a6 >= b6;
//var r4a7 = a7 >= b7;
var r4b1 = b1 >= a1;
var r4b2 = b2 >= a2;
~~~~~~~~
!!! error TS2365: Operator '>=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r4b3 = b3 >= a3;
var r4b4 = b4 >= a4;
var r4b5 = b5 >= a5;
var r4b6 = b6 >= a6;
//var r4b7 = b7 >= a7;
// operator ==
var r5a1 = a1 == b1;
var r5a2 = a2 == b2;
~~~~~~~~
!!! error TS2365: Operator '==' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r5a3 = a3 == b3;
var r5a4 = a4 == b4;
var r5a5 = a5 == b5;
var r5a6 = a6 == b6;
//var r5a7 = a7 == b7;
var r5b1 = b1 == a1;
var r5b2 = b2 == a2;
~~~~~~~~
!!! error TS2365: Operator '==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r5b3 = b3 == a3;
var r5b4 = b4 == a4;
var r5b5 = b5 == a5;
var r5b6 = b6 == a6;
//var r5b7 = b7 == a7;
// operator !=
var r6a1 = a1 != b1;
var r6a2 = a2 != b2;
~~~~~~~~
!!! error TS2365: Operator '!=' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r6a3 = a3 != b3;
var r6a4 = a4 != b4;
var r6a5 = a5 != b5;
var r6a6 = a6 != b6;
//var r6a7 = a7 != b7;
var r6b1 = b1 != a1;
var r6b2 = b2 != a2;
~~~~~~~~
!!! error TS2365: Operator '!=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r6b3 = b3 != a3;
var r6b4 = b4 != a4;
var r6b5 = b5 != a5;
var r6b6 = b6 != a6;
//var r6b7 = b7 != a7;
// operator ===
var r7a1 = a1 === b1;
var r7a2 = a2 === b2;
~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r7a3 = a3 === b3;
var r7a4 = a4 === b4;
var r7a5 = a5 === b5;
var r7a6 = a6 === b6;
//var r7a7 = a7 === b7;
var r7b1 = b1 === a1;
var r7b2 = b2 === a2;
~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r7b3 = b3 === a3;
var r7b4 = b4 === a4;
var r7b5 = b5 === a5;
var r7b6 = b6 === a6;
//var r7b7 = b7 === a7;
// operator !==
var r8a1 = a1 !== b1;
var r8a2 = a2 !== b2;
~~~~~~~~~
!!! error TS2365: Operator '!==' cannot be applied to types '{ fn<T>(x: T): T; }' and '{ fn(x: string, y: number): string; }'.
var r8a3 = a3 !== b3;
var r8a4 = a4 !== b4;
var r8a5 = a5 !== b5;
var r8a6 = a6 !== b6;
//var r8a7 = a7 !== b7;
var r8b1 = b1 !== a1;
var r8b2 = b2 !== a2;
~~~~~~~~~
!!! error TS2365: Operator '!==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn<T>(x: T): T; }'.
var r8b3 = b3 !== a3;
var r8b4 = b4 !== a4;
var r8b5 = b5 !== a5;
var r8b6 = b6 !== a6;
//var r8b7 = b7 !== a7;
@@ -0,0 +1,727 @@
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts ===
class Base {
>Base : Base
public a: string;
>a : string
}
class Derived extends Base {
>Derived : Derived
>Base : Base
public b: string;
>b : string
}
var a1: { fn<T>(x: T): T };
>a1 : { fn<T>(x: T): T; }
>fn : <T>(x: T) => T
>T : T
>x : T
>T : T
>T : T
var b1: { fn(x: string): string };
>b1 : { fn(x: string): string; }
>fn : (x: string) => string
>x : string
var a2: { fn<T>(x: T): T };
>a2 : { fn<T>(x: T): T; }
>fn : <T>(x: T) => T
>T : T
>x : T
>T : T
>T : T
var b2: { fn(x: string, y: number): string };
>b2 : { fn(x: string, y: number): string; }
>fn : (x: string, y: number) => string
>x : string
>y : number
var a3: { fn<T, U>(x: T, y: U): T };
>a3 : { fn<T, U>(x: T, y: U): T; }
>fn : <T, U>(x: T, y: U) => T
>T : T
>U : U
>x : T
>T : T
>y : U
>U : U
>T : T
var b3: { fn(x: string, y: number): string };
>b3 : { fn(x: string, y: number): string; }
>fn : (x: string, y: number) => string
>x : string
>y : number
var a4: { fn<T>(x?: T): T };
>a4 : { fn<T>(x?: T): T; }
>fn : <T>(x?: T) => T
>T : T
>x : T
>T : T
>T : T
var b4: { fn(x?: string): string };
>b4 : { fn(x?: string): string; }
>fn : (x?: string) => string
>x : string
var a5: { fn<T>(...x: T[]): T };
>a5 : { fn<T>(...x: T[]): T; }
>fn : <T>(...x: T[]) => T
>T : T
>x : T[]
>T : T
>T : T
var b5: { fn(...x: string[]): string };
>b5 : { fn(...x: string[]): string; }
>fn : (...x: string[]) => string
>x : string[]
var a6: { fn<T>(x: T, y: T): T };
>a6 : { fn<T>(x: T, y: T): T; }
>fn : <T>(x: T, y: T) => T
>T : T
>x : T
>T : T
>y : T
>T : T
>T : T
var b6: { fn(x: string, y: number): {} };
>b6 : { fn(x: string, y: number): {}; }
>fn : (x: string, y: number) => {}
>x : string
>y : number
//var a7: { fn<T, U extends T>(x: T, y: U): T };
var b7: { fn(x: Base, y: Derived): Base };
>b7 : { fn(x: Base, y: Derived): Base; }
>fn : (x: Base, y: Derived) => Base
>x : Base
>Base : Base
>y : Derived
>Derived : Derived
>Base : Base
// operator <
var r1a1 = a1 < b1;
>r1a1 : boolean
>a1 < b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r1a2 = a2 < b2;
>r1a2 : boolean
>a2 < b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r1a3 = a3 < b3;
>r1a3 : boolean
>a3 < b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r1a4 = a4 < b4;
>r1a4 : boolean
>a4 < b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r1a5 = a5 < b5;
>r1a5 : boolean
>a5 < b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r1a6 = a6 < b6;
>r1a6 : boolean
>a6 < b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r1a7 = a7 < b7;
var r1b1 = b1 < a1;
>r1b1 : boolean
>b1 < a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r1b2 = b2 < a2;
>r1b2 : boolean
>b2 < a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r1b3 = b3 < a3;
>r1b3 : boolean
>b3 < a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r1b4 = b4 < a4;
>r1b4 : boolean
>b4 < a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r1b5 = b5 < a5;
>r1b5 : boolean
>b5 < a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r1b6 = b6 < a6;
>r1b6 : boolean
>b6 < a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r1b7 = b7 < a7;
// operator >
var r2a1 = a1 > b1;
>r2a1 : boolean
>a1 > b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r2a2 = a2 > b2;
>r2a2 : boolean
>a2 > b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r2a3 = a3 > b3;
>r2a3 : boolean
>a3 > b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r2a4 = a4 > b4;
>r2a4 : boolean
>a4 > b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r2a5 = a5 > b5;
>r2a5 : boolean
>a5 > b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r2a6 = a6 > b6;
>r2a6 : boolean
>a6 > b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r2a7 = a7 > b7;
var r2b1 = b1 > a1;
>r2b1 : boolean
>b1 > a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r2b2 = b2 > a2;
>r2b2 : boolean
>b2 > a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r2b3 = b3 > a3;
>r2b3 : boolean
>b3 > a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r2b4 = b4 > a4;
>r2b4 : boolean
>b4 > a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r2b5 = b5 > a5;
>r2b5 : boolean
>b5 > a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r2b6 = b6 > a6;
>r2b6 : boolean
>b6 > a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r2b7 = b7 > a7;
// operator <=
var r3a1 = a1 <= b1;
>r3a1 : boolean
>a1 <= b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r3a2 = a2 <= b2;
>r3a2 : boolean
>a2 <= b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r3a3 = a3 <= b3;
>r3a3 : boolean
>a3 <= b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r3a4 = a4 <= b4;
>r3a4 : boolean
>a4 <= b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r3a5 = a5 <= b5;
>r3a5 : boolean
>a5 <= b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r3a6 = a6 <= b6;
>r3a6 : boolean
>a6 <= b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r3a7 = a7 <= b7;
var r3b1 = b1 <= a1;
>r3b1 : boolean
>b1 <= a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r3b2 = b2 <= a2;
>r3b2 : boolean
>b2 <= a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r3b3 = b3 <= a3;
>r3b3 : boolean
>b3 <= a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r3b4 = b4 <= a4;
>r3b4 : boolean
>b4 <= a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r3b5 = b5 <= a5;
>r3b5 : boolean
>b5 <= a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r3b6 = b6 <= a6;
>r3b6 : boolean
>b6 <= a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r3b7 = b7 <= a7;
// operator >=
var r4a1 = a1 >= b1;
>r4a1 : boolean
>a1 >= b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r4a2 = a2 >= b2;
>r4a2 : boolean
>a2 >= b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r4a3 = a3 >= b3;
>r4a3 : boolean
>a3 >= b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r4a4 = a4 >= b4;
>r4a4 : boolean
>a4 >= b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r4a5 = a5 >= b5;
>r4a5 : boolean
>a5 >= b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r4a6 = a6 >= b6;
>r4a6 : boolean
>a6 >= b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r4a7 = a7 >= b7;
var r4b1 = b1 >= a1;
>r4b1 : boolean
>b1 >= a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r4b2 = b2 >= a2;
>r4b2 : boolean
>b2 >= a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r4b3 = b3 >= a3;
>r4b3 : boolean
>b3 >= a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r4b4 = b4 >= a4;
>r4b4 : boolean
>b4 >= a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r4b5 = b5 >= a5;
>r4b5 : boolean
>b5 >= a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r4b6 = b6 >= a6;
>r4b6 : boolean
>b6 >= a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r4b7 = b7 >= a7;
// operator ==
var r5a1 = a1 == b1;
>r5a1 : boolean
>a1 == b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r5a2 = a2 == b2;
>r5a2 : boolean
>a2 == b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r5a3 = a3 == b3;
>r5a3 : boolean
>a3 == b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r5a4 = a4 == b4;
>r5a4 : boolean
>a4 == b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r5a5 = a5 == b5;
>r5a5 : boolean
>a5 == b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r5a6 = a6 == b6;
>r5a6 : boolean
>a6 == b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r5a7 = a7 == b7;
var r5b1 = b1 == a1;
>r5b1 : boolean
>b1 == a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r5b2 = b2 == a2;
>r5b2 : boolean
>b2 == a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r5b3 = b3 == a3;
>r5b3 : boolean
>b3 == a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r5b4 = b4 == a4;
>r5b4 : boolean
>b4 == a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r5b5 = b5 == a5;
>r5b5 : boolean
>b5 == a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r5b6 = b6 == a6;
>r5b6 : boolean
>b6 == a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r5b7 = b7 == a7;
// operator !=
var r6a1 = a1 != b1;
>r6a1 : boolean
>a1 != b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r6a2 = a2 != b2;
>r6a2 : boolean
>a2 != b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r6a3 = a3 != b3;
>r6a3 : boolean
>a3 != b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r6a4 = a4 != b4;
>r6a4 : boolean
>a4 != b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r6a5 = a5 != b5;
>r6a5 : boolean
>a5 != b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r6a6 = a6 != b6;
>r6a6 : boolean
>a6 != b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r6a7 = a7 != b7;
var r6b1 = b1 != a1;
>r6b1 : boolean
>b1 != a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r6b2 = b2 != a2;
>r6b2 : boolean
>b2 != a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r6b3 = b3 != a3;
>r6b3 : boolean
>b3 != a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r6b4 = b4 != a4;
>r6b4 : boolean
>b4 != a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r6b5 = b5 != a5;
>r6b5 : boolean
>b5 != a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r6b6 = b6 != a6;
>r6b6 : boolean
>b6 != a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r6b7 = b7 != a7;
// operator ===
var r7a1 = a1 === b1;
>r7a1 : boolean
>a1 === b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r7a2 = a2 === b2;
>r7a2 : boolean
>a2 === b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r7a3 = a3 === b3;
>r7a3 : boolean
>a3 === b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r7a4 = a4 === b4;
>r7a4 : boolean
>a4 === b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r7a5 = a5 === b5;
>r7a5 : boolean
>a5 === b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r7a6 = a6 === b6;
>r7a6 : boolean
>a6 === b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r7a7 = a7 === b7;
var r7b1 = b1 === a1;
>r7b1 : boolean
>b1 === a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r7b2 = b2 === a2;
>r7b2 : boolean
>b2 === a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r7b3 = b3 === a3;
>r7b3 : boolean
>b3 === a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r7b4 = b4 === a4;
>r7b4 : boolean
>b4 === a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r7b5 = b5 === a5;
>r7b5 : boolean
>b5 === a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r7b6 = b6 === a6;
>r7b6 : boolean
>b6 === a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r7b7 = b7 === a7;
// operator !==
var r8a1 = a1 !== b1;
>r8a1 : boolean
>a1 !== b1 : boolean
>a1 : { fn<T>(x: T): T; }
>b1 : { fn(x: string): string; }
var r8a2 = a2 !== b2;
>r8a2 : boolean
>a2 !== b2 : boolean
>a2 : { fn<T>(x: T): T; }
>b2 : { fn(x: string, y: number): string; }
var r8a3 = a3 !== b3;
>r8a3 : boolean
>a3 !== b3 : boolean
>a3 : { fn<T, U>(x: T, y: U): T; }
>b3 : { fn(x: string, y: number): string; }
var r8a4 = a4 !== b4;
>r8a4 : boolean
>a4 !== b4 : boolean
>a4 : { fn<T>(x?: T): T; }
>b4 : { fn(x?: string): string; }
var r8a5 = a5 !== b5;
>r8a5 : boolean
>a5 !== b5 : boolean
>a5 : { fn<T>(...x: T[]): T; }
>b5 : { fn(...x: string[]): string; }
var r8a6 = a6 !== b6;
>r8a6 : boolean
>a6 !== b6 : boolean
>a6 : { fn<T>(x: T, y: T): T; }
>b6 : { fn(x: string, y: number): {}; }
//var r8a7 = a7 !== b7;
var r8b1 = b1 !== a1;
>r8b1 : boolean
>b1 !== a1 : boolean
>b1 : { fn(x: string): string; }
>a1 : { fn<T>(x: T): T; }
var r8b2 = b2 !== a2;
>r8b2 : boolean
>b2 !== a2 : boolean
>b2 : { fn(x: string, y: number): string; }
>a2 : { fn<T>(x: T): T; }
var r8b3 = b3 !== a3;
>r8b3 : boolean
>b3 !== a3 : boolean
>b3 : { fn(x: string, y: number): string; }
>a3 : { fn<T, U>(x: T, y: U): T; }
var r8b4 = b4 !== a4;
>r8b4 : boolean
>b4 !== a4 : boolean
>b4 : { fn(x?: string): string; }
>a4 : { fn<T>(x?: T): T; }
var r8b5 = b5 !== a5;
>r8b5 : boolean
>b5 !== a5 : boolean
>b5 : { fn(...x: string[]): string; }
>a5 : { fn<T>(...x: T[]): T; }
var r8b6 = b6 !== a6;
>r8b6 : boolean
>b6 !== a6 : boolean
>b6 : { fn(x: string, y: number): {}; }
>a6 : { fn<T>(x: T, y: T): T; }
//var r8b7 = b7 !== a7;
@@ -1,215 +0,0 @@
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(40,12): error TS2365: Operator '<' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(49,12): error TS2365: Operator '>' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(57,12): error TS2365: Operator '>' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(66,12): error TS2365: Operator '<=' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(74,12): error TS2365: Operator '<=' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(83,12): error TS2365: Operator '>=' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(91,12): error TS2365: Operator '>=' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(100,12): error TS2365: Operator '==' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(108,12): error TS2365: Operator '==' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(117,12): error TS2365: Operator '!=' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(125,12): error TS2365: Operator '!=' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(134,12): error TS2365: Operator '===' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(142,12): error TS2365: Operator '===' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(151,12): error TS2365: Operator '!==' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(159,12): error TS2365: Operator '!==' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts (16 errors) ====
class Base {
public a: string;
}
class Derived extends Base {
public b: string;
}
var a1: { new <T>(x: T): T };
var b1: { new (x: string): string };
var a2: { new <T>(x: T): T };
var b2: { new (x: string, y: number): string };
var a3: { new <T, U>(x: T, y: U): T };
var b3: { new (x: string, y: number): string };
var a4: { new <T>(x?: T): T };
var b4: { new (x?: string): string };
var a5: { new <T>(...x: T[]): T };
var b5: { new (...x: string[]): string };
var a6: { new <T>(x: T, y: T): T };
var b6: { new (x: string, y: number): {} };
//var a7: { new <T, U extends T>(x: T, y: U): T };
var b7: { new (x: Base, y: Derived): Base };
// operator <
var r1a1 = a1 < b1;
var r1a2 = a2 < b2;
~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r1a3 = a3 < b3;
var r1a4 = a4 < b4;
var r1a5 = a5 < b5;
var r1a6 = a6 < b6;
//var r1a7 = a7 < b7;
var r1b1 = b1 < a1;
var r1b2 = b2 < a2;
~~~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r1b3 = b3 < a3;
var r1b4 = b4 < a4;
var r1b5 = b5 < a5;
var r1b6 = b6 < a6;
//var r1b7 = b7 < a7;
// operator >
var r2a1 = a1 > b1;
var r2a2 = a2 > b2;
~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r2a3 = a3 > b3;
var r2a4 = a4 > b4;
var r2a5 = a5 > b5;
var r2a6 = a6 > b6;
//var r2a7 = a7 > b7;
var r2b1 = b1 > a1;
var r2b2 = b2 > a2;
~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r2b3 = b3 > a3;
var r2b4 = b4 > a4;
var r2b5 = b5 > a5;
var r2b6 = b6 > a6;
//var r2b7 = b7 > a7;
// operator <=
var r3a1 = a1 <= b1;
var r3a2 = a2 <= b2;
~~~~~~~~
!!! error TS2365: Operator '<=' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r3a3 = a3 <= b3;
var r3a4 = a4 <= b4;
var r3a5 = a5 <= b5;
var r3a6 = a6 <= b6;
//var r3a7 = a7 <= b7;
var r3b1 = b1 <= a1;
var r3b2 = b2 <= a2;
~~~~~~~~
!!! error TS2365: Operator '<=' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r3b3 = b3 <= a3;
var r3b4 = b4 <= a4;
var r3b5 = b5 <= a5;
var r3b6 = b6 <= a6;
//var r3b7 = b7 <= a7;
// operator >=
var r4a1 = a1 >= b1;
var r4a2 = a2 >= b2;
~~~~~~~~
!!! error TS2365: Operator '>=' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r4a3 = a3 >= b3;
var r4a4 = a4 >= b4;
var r4a5 = a5 >= b5;
var r4a6 = a6 >= b6;
//var r4a7 = a7 >= b7;
var r4b1 = b1 >= a1;
var r4b2 = b2 >= a2;
~~~~~~~~
!!! error TS2365: Operator '>=' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r4b3 = b3 >= a3;
var r4b4 = b4 >= a4;
var r4b5 = b5 >= a5;
var r4b6 = b6 >= a6;
//var r4b7 = b7 >= a7;
// operator ==
var r5a1 = a1 == b1;
var r5a2 = a2 == b2;
~~~~~~~~
!!! error TS2365: Operator '==' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r5a3 = a3 == b3;
var r5a4 = a4 == b4;
var r5a5 = a5 == b5;
var r5a6 = a6 == b6;
//var r5a7 = a7 == b7;
var r5b1 = b1 == a1;
var r5b2 = b2 == a2;
~~~~~~~~
!!! error TS2365: Operator '==' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r5b3 = b3 == a3;
var r5b4 = b4 == a4;
var r5b5 = b5 == a5;
var r5b6 = b6 == a6;
//var r5b7 = b7 == a7;
// operator !=
var r6a1 = a1 != b1;
var r6a2 = a2 != b2;
~~~~~~~~
!!! error TS2365: Operator '!=' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r6a3 = a3 != b3;
var r6a4 = a4 != b4;
var r6a5 = a5 != b5;
var r6a6 = a6 != b6;
//var r6a7 = a7 != b7;
var r6b1 = b1 != a1;
var r6b2 = b2 != a2;
~~~~~~~~
!!! error TS2365: Operator '!=' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r6b3 = b3 != a3;
var r6b4 = b4 != a4;
var r6b5 = b5 != a5;
var r6b6 = b6 != a6;
//var r6b7 = b7 != a7;
// operator ===
var r7a1 = a1 === b1;
var r7a2 = a2 === b2;
~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r7a3 = a3 === b3;
var r7a4 = a4 === b4;
var r7a5 = a5 === b5;
var r7a6 = a6 === b6;
//var r7a7 = a7 === b7;
var r7b1 = b1 === a1;
var r7b2 = b2 === a2;
~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r7b3 = b3 === a3;
var r7b4 = b4 === a4;
var r7b5 = b5 === a5;
var r7b6 = b6 === a6;
//var r7b7 = b7 === a7;
// operator !==
var r8a1 = a1 !== b1;
var r8a2 = a2 !== b2;
~~~~~~~~~
!!! error TS2365: Operator '!==' cannot be applied to types 'new <T>(x: T) => T' and 'new (x: string, y: number) => string'.
var r8a3 = a3 !== b3;
var r8a4 = a4 !== b4;
var r8a5 = a5 !== b5;
var r8a6 = a6 !== b6;
//var r8a7 = a7 !== b7;
var r8b1 = b1 !== a1;
var r8b2 = b2 !== a2;
~~~~~~~~~
!!! error TS2365: Operator '!==' cannot be applied to types 'new (x: string, y: number) => string' and 'new <T>(x: T) => T'.
var r8b3 = b3 !== a3;
var r8b4 = b4 !== a4;
var r8b5 = b5 !== a5;
var r8b6 = b6 !== a6;
//var r8b7 = b7 !== a7;
@@ -0,0 +1,714 @@
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts ===
class Base {
>Base : Base
public a: string;
>a : string
}
class Derived extends Base {
>Derived : Derived
>Base : Base
public b: string;
>b : string
}
var a1: { new <T>(x: T): T };
>a1 : new <T>(x: T) => T
>T : T
>x : T
>T : T
>T : T
var b1: { new (x: string): string };
>b1 : new (x: string) => string
>x : string
var a2: { new <T>(x: T): T };
>a2 : new <T>(x: T) => T
>T : T
>x : T
>T : T
>T : T
var b2: { new (x: string, y: number): string };
>b2 : new (x: string, y: number) => string
>x : string
>y : number
var a3: { new <T, U>(x: T, y: U): T };
>a3 : new <T, U>(x: T, y: U) => T
>T : T
>U : U
>x : T
>T : T
>y : U
>U : U
>T : T
var b3: { new (x: string, y: number): string };
>b3 : new (x: string, y: number) => string
>x : string
>y : number
var a4: { new <T>(x?: T): T };
>a4 : new <T>(x?: T) => T
>T : T
>x : T
>T : T
>T : T
var b4: { new (x?: string): string };
>b4 : new (x?: string) => string
>x : string
var a5: { new <T>(...x: T[]): T };
>a5 : new <T>(...x: T[]) => T
>T : T
>x : T[]
>T : T
>T : T
var b5: { new (...x: string[]): string };
>b5 : new (...x: string[]) => string
>x : string[]
var a6: { new <T>(x: T, y: T): T };
>a6 : new <T>(x: T, y: T) => T
>T : T
>x : T
>T : T
>y : T
>T : T
>T : T
var b6: { new (x: string, y: number): {} };
>b6 : new (x: string, y: number) => {}
>x : string
>y : number
//var a7: { new <T, U extends T>(x: T, y: U): T };
var b7: { new (x: Base, y: Derived): Base };
>b7 : new (x: Base, y: Derived) => Base
>x : Base
>Base : Base
>y : Derived
>Derived : Derived
>Base : Base
// operator <
var r1a1 = a1 < b1;
>r1a1 : boolean
>a1 < b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r1a2 = a2 < b2;
>r1a2 : boolean
>a2 < b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r1a3 = a3 < b3;
>r1a3 : boolean
>a3 < b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r1a4 = a4 < b4;
>r1a4 : boolean
>a4 < b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r1a5 = a5 < b5;
>r1a5 : boolean
>a5 < b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r1a6 = a6 < b6;
>r1a6 : boolean
>a6 < b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r1a7 = a7 < b7;
var r1b1 = b1 < a1;
>r1b1 : boolean
>b1 < a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r1b2 = b2 < a2;
>r1b2 : boolean
>b2 < a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r1b3 = b3 < a3;
>r1b3 : boolean
>b3 < a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r1b4 = b4 < a4;
>r1b4 : boolean
>b4 < a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r1b5 = b5 < a5;
>r1b5 : boolean
>b5 < a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r1b6 = b6 < a6;
>r1b6 : boolean
>b6 < a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r1b7 = b7 < a7;
// operator >
var r2a1 = a1 > b1;
>r2a1 : boolean
>a1 > b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r2a2 = a2 > b2;
>r2a2 : boolean
>a2 > b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r2a3 = a3 > b3;
>r2a3 : boolean
>a3 > b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r2a4 = a4 > b4;
>r2a4 : boolean
>a4 > b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r2a5 = a5 > b5;
>r2a5 : boolean
>a5 > b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r2a6 = a6 > b6;
>r2a6 : boolean
>a6 > b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r2a7 = a7 > b7;
var r2b1 = b1 > a1;
>r2b1 : boolean
>b1 > a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r2b2 = b2 > a2;
>r2b2 : boolean
>b2 > a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r2b3 = b3 > a3;
>r2b3 : boolean
>b3 > a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r2b4 = b4 > a4;
>r2b4 : boolean
>b4 > a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r2b5 = b5 > a5;
>r2b5 : boolean
>b5 > a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r2b6 = b6 > a6;
>r2b6 : boolean
>b6 > a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r2b7 = b7 > a7;
// operator <=
var r3a1 = a1 <= b1;
>r3a1 : boolean
>a1 <= b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r3a2 = a2 <= b2;
>r3a2 : boolean
>a2 <= b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r3a3 = a3 <= b3;
>r3a3 : boolean
>a3 <= b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r3a4 = a4 <= b4;
>r3a4 : boolean
>a4 <= b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r3a5 = a5 <= b5;
>r3a5 : boolean
>a5 <= b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r3a6 = a6 <= b6;
>r3a6 : boolean
>a6 <= b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r3a7 = a7 <= b7;
var r3b1 = b1 <= a1;
>r3b1 : boolean
>b1 <= a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r3b2 = b2 <= a2;
>r3b2 : boolean
>b2 <= a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r3b3 = b3 <= a3;
>r3b3 : boolean
>b3 <= a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r3b4 = b4 <= a4;
>r3b4 : boolean
>b4 <= a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r3b5 = b5 <= a5;
>r3b5 : boolean
>b5 <= a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r3b6 = b6 <= a6;
>r3b6 : boolean
>b6 <= a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r3b7 = b7 <= a7;
// operator >=
var r4a1 = a1 >= b1;
>r4a1 : boolean
>a1 >= b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r4a2 = a2 >= b2;
>r4a2 : boolean
>a2 >= b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r4a3 = a3 >= b3;
>r4a3 : boolean
>a3 >= b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r4a4 = a4 >= b4;
>r4a4 : boolean
>a4 >= b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r4a5 = a5 >= b5;
>r4a5 : boolean
>a5 >= b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r4a6 = a6 >= b6;
>r4a6 : boolean
>a6 >= b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r4a7 = a7 >= b7;
var r4b1 = b1 >= a1;
>r4b1 : boolean
>b1 >= a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r4b2 = b2 >= a2;
>r4b2 : boolean
>b2 >= a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r4b3 = b3 >= a3;
>r4b3 : boolean
>b3 >= a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r4b4 = b4 >= a4;
>r4b4 : boolean
>b4 >= a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r4b5 = b5 >= a5;
>r4b5 : boolean
>b5 >= a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r4b6 = b6 >= a6;
>r4b6 : boolean
>b6 >= a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r4b7 = b7 >= a7;
// operator ==
var r5a1 = a1 == b1;
>r5a1 : boolean
>a1 == b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r5a2 = a2 == b2;
>r5a2 : boolean
>a2 == b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r5a3 = a3 == b3;
>r5a3 : boolean
>a3 == b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r5a4 = a4 == b4;
>r5a4 : boolean
>a4 == b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r5a5 = a5 == b5;
>r5a5 : boolean
>a5 == b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r5a6 = a6 == b6;
>r5a6 : boolean
>a6 == b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r5a7 = a7 == b7;
var r5b1 = b1 == a1;
>r5b1 : boolean
>b1 == a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r5b2 = b2 == a2;
>r5b2 : boolean
>b2 == a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r5b3 = b3 == a3;
>r5b3 : boolean
>b3 == a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r5b4 = b4 == a4;
>r5b4 : boolean
>b4 == a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r5b5 = b5 == a5;
>r5b5 : boolean
>b5 == a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r5b6 = b6 == a6;
>r5b6 : boolean
>b6 == a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r5b7 = b7 == a7;
// operator !=
var r6a1 = a1 != b1;
>r6a1 : boolean
>a1 != b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r6a2 = a2 != b2;
>r6a2 : boolean
>a2 != b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r6a3 = a3 != b3;
>r6a3 : boolean
>a3 != b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r6a4 = a4 != b4;
>r6a4 : boolean
>a4 != b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r6a5 = a5 != b5;
>r6a5 : boolean
>a5 != b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r6a6 = a6 != b6;
>r6a6 : boolean
>a6 != b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r6a7 = a7 != b7;
var r6b1 = b1 != a1;
>r6b1 : boolean
>b1 != a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r6b2 = b2 != a2;
>r6b2 : boolean
>b2 != a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r6b3 = b3 != a3;
>r6b3 : boolean
>b3 != a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r6b4 = b4 != a4;
>r6b4 : boolean
>b4 != a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r6b5 = b5 != a5;
>r6b5 : boolean
>b5 != a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r6b6 = b6 != a6;
>r6b6 : boolean
>b6 != a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r6b7 = b7 != a7;
// operator ===
var r7a1 = a1 === b1;
>r7a1 : boolean
>a1 === b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r7a2 = a2 === b2;
>r7a2 : boolean
>a2 === b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r7a3 = a3 === b3;
>r7a3 : boolean
>a3 === b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r7a4 = a4 === b4;
>r7a4 : boolean
>a4 === b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r7a5 = a5 === b5;
>r7a5 : boolean
>a5 === b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r7a6 = a6 === b6;
>r7a6 : boolean
>a6 === b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r7a7 = a7 === b7;
var r7b1 = b1 === a1;
>r7b1 : boolean
>b1 === a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r7b2 = b2 === a2;
>r7b2 : boolean
>b2 === a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r7b3 = b3 === a3;
>r7b3 : boolean
>b3 === a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r7b4 = b4 === a4;
>r7b4 : boolean
>b4 === a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r7b5 = b5 === a5;
>r7b5 : boolean
>b5 === a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r7b6 = b6 === a6;
>r7b6 : boolean
>b6 === a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r7b7 = b7 === a7;
// operator !==
var r8a1 = a1 !== b1;
>r8a1 : boolean
>a1 !== b1 : boolean
>a1 : new <T>(x: T) => T
>b1 : new (x: string) => string
var r8a2 = a2 !== b2;
>r8a2 : boolean
>a2 !== b2 : boolean
>a2 : new <T>(x: T) => T
>b2 : new (x: string, y: number) => string
var r8a3 = a3 !== b3;
>r8a3 : boolean
>a3 !== b3 : boolean
>a3 : new <T, U>(x: T, y: U) => T
>b3 : new (x: string, y: number) => string
var r8a4 = a4 !== b4;
>r8a4 : boolean
>a4 !== b4 : boolean
>a4 : new <T>(x?: T) => T
>b4 : new (x?: string) => string
var r8a5 = a5 !== b5;
>r8a5 : boolean
>a5 !== b5 : boolean
>a5 : new <T>(...x: T[]) => T
>b5 : new (...x: string[]) => string
var r8a6 = a6 !== b6;
>r8a6 : boolean
>a6 !== b6 : boolean
>a6 : new <T>(x: T, y: T) => T
>b6 : new (x: string, y: number) => {}
//var r8a7 = a7 !== b7;
var r8b1 = b1 !== a1;
>r8b1 : boolean
>b1 !== a1 : boolean
>b1 : new (x: string) => string
>a1 : new <T>(x: T) => T
var r8b2 = b2 !== a2;
>r8b2 : boolean
>b2 !== a2 : boolean
>b2 : new (x: string, y: number) => string
>a2 : new <T>(x: T) => T
var r8b3 = b3 !== a3;
>r8b3 : boolean
>b3 !== a3 : boolean
>b3 : new (x: string, y: number) => string
>a3 : new <T, U>(x: T, y: U) => T
var r8b4 = b4 !== a4;
>r8b4 : boolean
>b4 !== a4 : boolean
>b4 : new (x?: string) => string
>a4 : new <T>(x?: T) => T
var r8b5 = b5 !== a5;
>r8b5 : boolean
>b5 !== a5 : boolean
>b5 : new (...x: string[]) => string
>a5 : new <T>(...x: T[]) => T
var r8b6 = b6 !== a6;
>r8b6 : boolean
>b6 !== a6 : boolean
>b6 : new (x: string, y: number) => {}
>a6 : new <T>(x: T, y: T) => T
//var r8b7 = b7 !== a7;
@@ -1,10 +1,9 @@
tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2323: Type '{}' is not assignable to type 'boolean'.
tests/cases/compiler/conditionalExpression1.ts(1,19): error TS2367: No best common type exists between 'number' and 'string'.
tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type 'string | number' is not assignable to type 'boolean':
Type 'string' is not assignable to type 'boolean'.
==== tests/cases/compiler/conditionalExpression1.ts (2 errors) ====
==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ====
var x: boolean = (true ? 1 : ""); // should be an error
~
!!! error TS2323: Type '{}' is not assignable to type 'boolean'.
~~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'number' and 'string'.
!!! error TS2322: Type 'string | number' is not assignable to type 'boolean':
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
@@ -80,7 +80,7 @@ var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA;
>result4 : (t: A) => any
>t : A
>A : A
>true ? (m) => m.propertyX : (n) => n.propertyA : (t: A) => any
>true ? (m) => m.propertyX : (n) => n.propertyA : (m: A) => any
>(m) => m.propertyX : (m: A) => any
>m : A
>m.propertyX : any
@@ -144,7 +144,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX;
>result8 : (t: A) => any
>t : A
>A : A
>true ? (m) => m.propertyA : (n) => n.propertyX : (t: A) => any
>true ? (m) => m.propertyA : (n) => n.propertyX : (n: A) => any
>(m) => m.propertyA : (m: A) => number
>m : A
>m.propertyA : number
@@ -161,7 +161,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX;
var resultIsX3: X = true ? a : b;
>resultIsX3 : X
>X : X
>true ? a : b : X
>true ? a : b : A | B
>a : A
>b : B
@@ -169,7 +169,7 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
>result10 : (t: X) => any
>t : X
>X : X
>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : (t: X) => any
>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : ((m: X) => number) | ((n: X) => string)
>(m) => m.propertyX1 : (m: X) => number
>m : X
>m.propertyX1 : number
@@ -184,5 +184,5 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
//Expr1 and Expr2 are literals
var result11: any = true ? 1 : 'string';
>result11 : any
>true ? 1 : 'string' : any
>true ? 1 : 'string' : string | number
@@ -1,20 +1,21 @@
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(12,1): error TS2367: No best common type exists between 'A' and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(13,15): error TS2367: No best common type exists between 'A' and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type '{}' is not assignable to type 'A':
Property 'propertyA' is missing in type '{}'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,18): error TS2366: No best common type exists between 'A', 'A', and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,5): error TS2322: Type '{}' is not assignable to type 'B':
Property 'propertyB' is missing in type '{}'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,18): error TS2366: No best common type exists between 'B', 'A', and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2323: Type '{}' is not assignable to type '(t: X) => number'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,33): error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2323: Type '{}' is not assignable to type '(t: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,33): error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,5): error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,34): error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(15,5): error TS2322: Type 'A | B' is not assignable to type 'A':
Type 'B' is not assignable to type 'A':
Property 'propertyA' is missing in type 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'B':
Type 'A' is not assignable to type 'B':
Property 'propertyB' is missing in type 'A'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(18,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => number':
Type '(n: X) => string' is not assignable to type '(t: X) => number':
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => string':
Type '(m: X) => number' is not assignable to type '(t: X) => string':
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => boolean':
Type '(m: X) => number' is not assignable to type '(t: X) => boolean':
Type 'number' is not assignable to type 'boolean'.
==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (12 errors) ====
==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (5 errors) ====
//Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type
class X { propertyX: any; propertyX1: number; propertyX2: string };
class A extends X { propertyA: number };
@@ -24,41 +25,34 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou
var a: A;
var b: B;
//Expect to have compiler errors
//Be not contextually typed
// No errors anymore, uses union types
true ? a : b;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'A' and 'B'.
var result1 = true ? a : b;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'A' and 'B'.
//Be contextually typed and and bct is not identical
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2: A = true ? a : b;
~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'A':
!!! error TS2322: Property 'propertyA' is missing in type '{}'.
~~~~~~~~~~~~
!!! error TS2366: No best common type exists between 'A', 'A', and 'B'.
!!! error TS2322: Type 'A | B' is not assignable to type 'A':
!!! error TS2322: Type 'B' is not assignable to type 'A':
!!! error TS2322: Property 'propertyA' is missing in type 'B'.
var result3: B = true ? a : b;
~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'B':
!!! error TS2322: Property 'propertyB' is missing in type '{}'.
~~~~~~~~~~~~
!!! error TS2366: No best common type exists between 'B', 'A', and 'B'.
!!! error TS2322: Type 'A | B' is not assignable to type 'B':
!!! error TS2322: Type 'A' is not assignable to type 'B':
!!! error TS2322: Property 'propertyB' is missing in type 'A'.
var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
~~~~~~~
!!! error TS2323: Type '{}' is not assignable to type '(t: X) => number'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'.
!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => number':
!!! error TS2322: Type '(n: X) => string' is not assignable to type '(t: X) => number':
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
~~~~~~~
!!! error TS2323: Type '{}' is not assignable to type '(t: X) => string'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'.
!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => string':
!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => string':
!!! error TS2322: Type 'number' is not assignable to type 'string'.
var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
~~~~~~~
!!! error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'.
!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => boolean':
!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => boolean':
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.
@@ -8,12 +8,11 @@ var x: X;
var a: A;
var b: B;
//Expect to have compiler errors
//Be not contextually typed
// No errors anymore, uses union types
true ? a : b;
var result1 = true ? a : b;
//Be contextually typed and and bct is not identical
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2: A = true ? a : b;
var result3: B = true ? a : b;
@@ -54,11 +53,10 @@ var B = (function (_super) {
var x;
var a;
var b;
//Expect to have compiler errors
//Be not contextually typed
// No errors anymore, uses union types
true ? a : b;
var result1 = true ? a : b;
//Be contextually typed and and bct is not identical
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2 = true ? a : b;
var result3 = true ? a : b;
var result4 = true ? function (m) { return m.propertyX1; } : function (n) { return n.propertyX2; };
@@ -0,0 +1,50 @@
//// [contextualSignatureInstantiation.ts]
// TypeScript Spec, section 4.12.2:
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5).
declare function foo<T>(cb: (x: number, y: string) => T): T;
declare function bar<T, U, V>(x: T, y: U, cb: (x: T, y: U) => V): V;
declare function baz<T, U>(x: T, y: T, cb: (x: T, y: T) => U): U;
declare function g<T>(x: T, y: T): T;
declare function h<T, U>(x: T, y: U): T[] | U[];
var a: number;
var a = bar(1, 1, g); // Should be number
var a = baz(1, 1, g); // Should be number
var b: number | string;
var b = foo(g); // Should be number | string
var b = bar(1, "one", g); // Should be number | string
var b = bar("one", 1, g); // Should be number | string
var b = baz(b, b, g); // Should be number | string
var d: number[] | string[];
var d = foo(h); // Should be number[] | string[]
var d = bar(1, "one", h); // Should be number[] | string[]
var d = bar("one", 1, h); // Should be number[] | string[]
var d = baz(d, d, g); // Should be number[] | string[]
//// [contextualSignatureInstantiation.js]
// TypeScript Spec, section 4.12.2:
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5).
var a;
var a = bar(1, 1, g); // Should be number
var a = baz(1, 1, g); // Should be number
var b;
var b = foo(g); // Should be number | string
var b = bar(1, "one", g); // Should be number | string
var b = bar("one", 1, g); // Should be number | string
var b = baz(b, b, g); // Should be number | string
var d;
var d = foo(h); // Should be number[] | string[]
var d = bar(1, "one", h); // Should be number[] | string[]
var d = bar("one", 1, h); // Should be number[] | string[]
var d = baz(d, d, g); // Should be number[] | string[]
@@ -0,0 +1,142 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts ===
// TypeScript Spec, section 4.12.2:
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5).
declare function foo<T>(cb: (x: number, y: string) => T): T;
>foo : <T>(cb: (x: number, y: string) => T) => T
>T : T
>cb : (x: number, y: string) => T
>x : number
>y : string
>T : T
>T : T
declare function bar<T, U, V>(x: T, y: U, cb: (x: T, y: U) => V): V;
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>T : T
>U : U
>V : V
>x : T
>T : T
>y : U
>U : U
>cb : (x: T, y: U) => V
>x : T
>T : T
>y : U
>U : U
>V : V
>V : V
declare function baz<T, U>(x: T, y: T, cb: (x: T, y: T) => U): U;
>baz : <T, U>(x: T, y: T, cb: (x: T, y: T) => U) => U
>T : T
>U : U
>x : T
>T : T
>y : T
>T : T
>cb : (x: T, y: T) => U
>x : T
>T : T
>y : T
>T : T
>U : U
>U : U
declare function g<T>(x: T, y: T): T;
>g : <T>(x: T, y: T) => T
>T : T
>x : T
>T : T
>y : T
>T : T
>T : T
declare function h<T, U>(x: T, y: U): T[] | U[];
>h : <T, U>(x: T, y: U) => T[] | U[]
>T : T
>U : U
>x : T
>T : T
>y : U
>U : U
>T : T
>U : U
var a: number;
>a : number
var a = bar(1, 1, g); // Should be number
>a : number
>bar(1, 1, g) : number
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>g : <T>(x: T, y: T) => T
var a = baz(1, 1, g); // Should be number
>a : number
>baz(1, 1, g) : number
>baz : <T, U>(x: T, y: T, cb: (x: T, y: T) => U) => U
>g : <T>(x: T, y: T) => T
var b: number | string;
>b : string | number
var b = foo(g); // Should be number | string
>b : string | number
>foo(g) : string | number
>foo : <T>(cb: (x: number, y: string) => T) => T
>g : <T>(x: T, y: T) => T
var b = bar(1, "one", g); // Should be number | string
>b : string | number
>bar(1, "one", g) : string | number
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>g : <T>(x: T, y: T) => T
var b = bar("one", 1, g); // Should be number | string
>b : string | number
>bar("one", 1, g) : string | number
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>g : <T>(x: T, y: T) => T
var b = baz(b, b, g); // Should be number | string
>b : string | number
>baz(b, b, g) : string | number
>baz : <T, U>(x: T, y: T, cb: (x: T, y: T) => U) => U
>b : string | number
>b : string | number
>g : <T>(x: T, y: T) => T
var d: number[] | string[];
>d : string[] | number[]
var d = foo(h); // Should be number[] | string[]
>d : string[] | number[]
>foo(h) : string[] | number[]
>foo : <T>(cb: (x: number, y: string) => T) => T
>h : <T, U>(x: T, y: U) => T[] | U[]
var d = bar(1, "one", h); // Should be number[] | string[]
>d : string[] | number[]
>bar(1, "one", h) : string[] | number[]
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>h : <T, U>(x: T, y: U) => T[] | U[]
var d = bar("one", 1, h); // Should be number[] | string[]
>d : string[] | number[]
>bar("one", 1, h) : string[] | number[]
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>h : <T, U>(x: T, y: U) => T[] | U[]
var d = baz(d, d, g); // Should be number[] | string[]
>d : string[] | number[]
>baz(d, d, g) : string[] | number[]
>baz : <T, U>(x: T, y: T, cb: (x: T, y: T) => U) => U
>d : string[] | number[]
>d : string[] | number[]
>g : <T>(x: T, y: T) => T
@@ -26,18 +26,18 @@ interface Transform3D {
var style: IBookStyle = {
>style : IBookStyle
>IBookStyle : IBookStyle
>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => NamedTransform[]; }
>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { [x: string]: any; 'ry': any; }[]; }
initialLeftPageTransforms: (width: number) => {
>initialLeftPageTransforms : (width: number) => NamedTransform[]
>(width: number) => { return [ {'ry': null } ]; } : (width: number) => NamedTransform[]
>initialLeftPageTransforms : (width: number) => { [x: string]: any; 'ry': any; }[]
>(width: number) => { return [ {'ry': null } ]; } : (width: number) => { [x: string]: any; 'ry': any; }[]
>width : number
return [
>[ {'ry': null } ] : NamedTransform[]
>[ {'ry': null } ] : { [x: string]: null; 'ry': null; }[]
{'ry': null }
>{'ry': null } : { [x: string]: Transform3D; 'ry': null; }
>{'ry': null } : { [x: string]: null; 'ry': null; }
];
}
@@ -1,40 +1,58 @@
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]':
Types of property '0' are incompatible:
Type '{}' is not assignable to type '{ a: string; }':
Property 'a' is missing in type '{}'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]':
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]':
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => string':
Type '{}' is not assignable to type 'string'.
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (3 errors) ====
// no error
var numStrTuple: [number, string] = [5, "hello"];
var numStrTuple2: [number, string] = [5, "foo", true];
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
numStrTuple = numStrTuple2;
numStrTuple = numStrBoolTuple;
// error
objNumTuple = [ {}, 5];
~~~~~~~~~~~
!!! error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]':
!!! error TS2322: Types of property '0' are incompatible:
!!! error TS2322: Type '{}' is not assignable to type '{ a: string; }':
!!! error TS2322: Property 'a' is missing in type '{}'.
numStrBoolTuple = numStrTuple;
~~~~~~~~~~~~~~~
!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]':
!!! error TS2322: Property '2' is missing in type '[number, string]'.
var strStrTuple: [string, string] = ["foo", "bar", 5];
~~~~~~~~~~~
!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => {}' is not assignable to type '() => string':
!!! error TS2322: Type '{}' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]':
Types of property 'pop' are incompatible:
Type '() => string | number | boolean' is not assignable to type '() => string | number':
Type 'string | number | boolean' is not assignable to type 'string | number':
Type 'boolean' is not assignable to type 'string | number':
Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(8,1): error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]':
Types of property '0' are incompatible:
Type '{}' is not assignable to type '{ a: string; }':
Property 'a' is missing in type '{}'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]':
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]':
Types of property 'pop' are incompatible:
Type '() => string | number' is not assignable to type '() => string':
Type 'string | number' is not assignable to type 'string':
Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (5 errors) ====
// no error
var numStrTuple: [number, string] = [5, "hello"];
var numStrTuple2: [number, string] = [5, "foo", true];
~~~~~~~~~~~~
!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number':
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number':
!!! error TS2322: Type 'boolean' is not assignable to type 'string | number':
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
numStrTuple = numStrTuple2;
numStrTuple = numStrBoolTuple;
~~~~~~~~~~~
!!! error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
// error
objNumTuple = [ {}, 5];
~~~~~~~~~~~
!!! error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]':
!!! error TS2322: Types of property '0' are incompatible:
!!! error TS2322: Type '{}' is not assignable to type '{ a: string; }':
!!! error TS2322: Property 'a' is missing in type '{}'.
numStrBoolTuple = numStrTuple;
~~~~~~~~~~~~~~~
!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]':
!!! error TS2322: Property '2' is missing in type '[number, string]'.
var strStrTuple: [string, string] = ["foo", "bar", 5];
~~~~~~~~~~~
!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => string | number' is not assignable to type '() => string':
!!! error TS2322: Type 'string | number' is not assignable to type 'string':
!!! error TS2322: Type 'number' is not assignable to type 'string'.
@@ -1,4 +1,4 @@
//// [contextualTypeWithTuple.ts]
//// [contextualTypeWithTuple.ts]
// no error
var numStrTuple: [number, string] = [5, "hello"];
var numStrTuple2: [number, string] = [5, "foo", true];
@@ -12,18 +12,18 @@ numStrTuple = numStrBoolTuple;
objNumTuple = [ {}, 5];
numStrBoolTuple = numStrTuple;
var strStrTuple: [string, string] = ["foo", "bar", 5];
//// [contextualTypeWithTuple.js]
// no error
var numStrTuple = [5, "hello"];
var numStrTuple2 = [5, "foo", true];
var numStrBoolTuple = [5, "foo", true];
var objNumTuple = [{ a: "world" }, 5];
var strTupleTuple = ["bar", [5, { x: 1, y: 1 }]];
numStrTuple = numStrTuple2;
numStrTuple = numStrBoolTuple;
// error
objNumTuple = [{}, 5];
numStrBoolTuple = numStrTuple;
var strStrTuple = ["foo", "bar", 5];
//// [contextualTypeWithTuple.js]
// no error
var numStrTuple = [5, "hello"];
var numStrTuple2 = [5, "foo", true];
var numStrBoolTuple = [5, "foo", true];
var objNumTuple = [{ a: "world" }, 5];
var strTupleTuple = ["bar", [5, { x: 1, y: 1 }]];
numStrTuple = numStrTuple2;
numStrTuple = numStrBoolTuple;
// error
objNumTuple = [{}, 5];
numStrBoolTuple = numStrTuple;
var strStrTuple = ["foo", "bar", 5];
@@ -1,11 +1,13 @@
tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]':
Type '{}' is not assignable to type '{ id: number; }':
Property 'id' is missing in type '{}'.
tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]':
Type 'number | { id: number; }' is not assignable to type '{ id: number; }':
Type 'number' is not assignable to type '{ id: number; }':
Property 'id' is missing in type 'Number'.
==== tests/cases/compiler/contextualTyping21.ts (1 errors) ====
var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1];
~~~
!!! error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]':
!!! error TS2322: Type '{}' is not assignable to type '{ id: number; }':
!!! error TS2322: Property 'id' is missing in type '{}'.
!!! error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]':
!!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }':
!!! error TS2322: Type 'number' is not assignable to type '{ id: number; }':
!!! error TS2322: Property 'id' is missing in type 'Number'.
@@ -1,9 +1,11 @@
tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'.
Type '{}' is not assignable to type 'number'.
tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
Type 'string | number' is not assignable to type 'number':
Type 'string' is not assignable to type 'number'.
==== tests/cases/compiler/contextualTyping30.ts (1 errors) ====
function foo(param:number[]){}; foo([1, "a"]);
~~~~~~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Type '{}' is not assignable to type 'number'.
!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Type 'string | number' is not assignable to type 'number':
!!! error TS2345: Type 'string' is not assignable to type 'number'.
@@ -5,7 +5,7 @@ function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){ret
>i : number
>foo([function(){return 1;}, function(){return 4}]) : void
>foo : (param: { (): number; (i: number): number; }[]) => void
>[function(){return 1;}, function(){return 4}] : { (): number; (i: number): number; }[]
>[function(){return 1;}, function(){return 4}] : (() => number)[]
>function(){return 1;} : () => number
>function(){return 4} : () => number
@@ -1,9 +1,11 @@
tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
Type '{}' is not assignable to type '{ (): number; (i: number): number; }'.
tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '((() => number) | (() => string))[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
Type '(() => number) | (() => string)' is not assignable to type '{ (): number; (i: number): number; }':
Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'.
==== tests/cases/compiler/contextualTyping33.ts (1 errors) ====
function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
!!! error TS2345: Type '{}' is not assignable to type '{ (): number; (i: number): number; }'.
!!! error TS2345: Argument of type '((() => number) | (() => string))[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
!!! error TS2345: Type '(() => number) | (() => string)' is not assignable to type '{ (): number; (i: number): number; }':
!!! error TS2345: Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'.
@@ -23,8 +23,8 @@ class C extends A {
}
var xs = [(x: A) => { }, (x: B) => { }, (x: C) => { }];
>xs : { (x: A): void; }[]
>[(x: A) => { }, (x: B) => { }, (x: C) => { }] : { (x: A): void; }[]
>xs : ((x: A) => void)[]
>[(x: A) => { }, (x: B) => { }, (x: C) => { }] : ((x: A) => void)[]
>(x: A) => { } : (x: A) => void
>x : A
>A : A
@@ -1,7 +1,8 @@
tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '{}[]' is not assignable to type 'I':
tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(number | Date)[]' is not assignable to type 'I':
Index signatures are incompatible:
Type '{}' is not assignable to type 'Date':
Property 'toDateString' is missing in type '{}'.
Type 'number | Date' is not assignable to type 'Date':
Type 'number' is not assignable to type 'Date':
Property 'toDateString' is missing in type 'Number'.
==== tests/cases/compiler/contextualTypingOfArrayLiterals1.ts (1 errors) ====
@@ -11,10 +12,11 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ
var x3: I = [new Date(), 1];
~~
!!! error TS2322: Type '{}[]' is not assignable to type 'I':
!!! error TS2322: Type '(number | Date)[]' is not assignable to type 'I':
!!! error TS2322: Index signatures are incompatible:
!!! error TS2322: Type '{}' is not assignable to type 'Date':
!!! error TS2322: Property 'toDateString' is missing in type '{}'.
!!! error TS2322: Type 'number | Date' is not assignable to type 'Date':
!!! error TS2322: Type 'number' is not assignable to type 'Date':
!!! error TS2322: Property 'toDateString' is missing in type 'Number'.
var r2 = x3[1];
r2.getDate();
@@ -2,7 +2,7 @@
var x: (a: number) => void = true ? (a) => a.toExponential() : (b) => b.toFixed();
>x : (a: number) => void
>a : number
>true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => void
>true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => string
>(a) => a.toExponential() : (a: number) => string
>a : number
>a.toExponential() : string
@@ -41,7 +41,7 @@ var x2: (a: A) => void = true ? (a) => a.foo : (b) => b.foo;
>x2 : (a: A) => void
>a : A
>A : A
>true ? (a) => a.foo : (b) => b.foo : (a: A) => void
>true ? (a) => a.foo : (b) => b.foo : (a: A) => number
>(a) => a.foo : (a: A) => number
>a : A
>a.foo : number
@@ -1,8 +1,11 @@
tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2323: Type '{}' is not assignable to type '(a: A) => void'.
tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'.
tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '((a: C) => number) | ((b: number) => void)' is not assignable to type '(a: A) => void':
Type '(b: number) => void' is not assignable to type '(a: A) => void':
Types of parameters 'b' and 'a' are incompatible:
Type 'number' is not assignable to type 'A':
Property 'foo' is missing in type 'Number'.
==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (2 errors) ====
==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (1 errors) ====
class A {
foo: number;
}
@@ -15,7 +18,9 @@ tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error T
var x2: (a: A) => void = true ? (a: C) => a.foo : (b: number) => { };
~~
!!! error TS2323: Type '{}' is not assignable to type '(a: A) => void'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'.
!!! error TS2322: Type '((a: C) => number) | ((b: number) => void)' is not assignable to type '(a: A) => void':
!!! error TS2322: Type '(b: number) => void' is not assignable to type '(a: A) => void':
!!! error TS2322: Types of parameters 'b' and 'a' are incompatible:
!!! error TS2322: Type 'number' is not assignable to type 'A':
!!! error TS2322: Property 'foo' is missing in type 'Number'.
@@ -1,9 +1,12 @@
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'.
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ====
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ====
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
f10('', () => a => a.foo, ''); // a is string, fixed by first parameter
f10('', () => a => a.foo, ''); // a is string
~~~
!!! error TS2339: Property 'foo' does not exist on type 'string'.
var r9 = f10('', () => (a => a.foo), 1); // now a should be any
var r9 = f10('', () => (a => a.foo), 1); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
@@ -1,9 +1,9 @@
//// [contextualTypingWithFixedTypeParameters1.ts]
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
f10('', () => a => a.foo, ''); // a is string, fixed by first parameter
var r9 = f10('', () => (a => a.foo), 1); // now a should be any
f10('', () => a => a.foo, ''); // a is string
var r9 = f10('', () => (a => a.foo), 1); // error
//// [contextualTypingWithFixedTypeParameters1.js]
var f10;
f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string, fixed by first parameter
var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // now a should be any
f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string
var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // error
@@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>v : { a: (_: string) => number; }
>a : (_: string) => number
>_ : string
>{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; }
>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; }
>{ a: s => s.length } : { a: (s: string) => number; }
>a : (s: string) => number
>s => s.length : (s: string) => number
@@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>s : string
var v2 = (s: string) => s.length || function (s) { s.length };
>v2 : (s: string) => {}
>(s: string) => s.length || function (s) { s.length } : (s: string) => {}
>v2 : (s: string) => number | ((s: any) => void)
>(s: string) => s.length || function (s) { s.length } : (s: string) => number | ((s: any) => void)
>s : string
>s.length || function (s) { s.length } : {}
>s.length || function (s) { s.length } : number | ((s: any) => void)
>s.length : number
>s : string
>length : number
@@ -31,10 +31,10 @@ var v2 = (s: string) => s.length || function (s) { s.length };
>length : any
var v3 = (s: string) => s.length || function (s: number) { return 1 };
>v3 : (s: string) => {}
>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => {}
>v3 : (s: string) => number | ((s: number) => number)
>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | ((s: number) => number)
>s : string
>s.length || function (s: number) { return 1 } : {}
>s.length || function (s: number) { return 1 } : number | ((s: number) => number)
>s.length : number
>s : string
>length : number
@@ -42,10 +42,10 @@ var v3 = (s: string) => s.length || function (s: number) { return 1 };
>s : number
var v4 = (s: number) => 1 || function (s: string) { return s.length };
>v4 : (s: number) => {}
>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => {}
>v4 : (s: number) => number | ((s: string) => number)
>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | ((s: string) => number)
>s : number
>1 || function (s: string) { return s.length } : {}
>1 || function (s: string) { return s.length } : number | ((s: string) => number)
>function (s: string) { return s.length } : (s: string) => number
>s : string
>s.length : number
@@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>v : { a: (_: string) => number; }
>a : (_: string) => number
>_ : string
>{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; }
>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; }
>{ a: s => s.length } : { a: (s: string) => number; }
>a : (s: string) => number
>s => s.length : (s: string) => number
@@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>s : string
var v2 = (s: string) => s.length || function (s) { s.aaa };
>v2 : (s: string) => {}
>(s: string) => s.length || function (s) { s.aaa } : (s: string) => {}
>v2 : (s: string) => number | ((s: any) => void)
>(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | ((s: any) => void)
>s : string
>s.length || function (s) { s.aaa } : {}
>s.length || function (s) { s.aaa } : number | ((s: any) => void)
>s.length : number
>s : string
>length : number
@@ -131,11 +131,11 @@ module templa.dom.mvc.composite {
>super : typeof AbstractElementController
this._controllers = [];
>this._controllers = [] : templa.mvc.IController<templa.mvc.IModel>[]
>this._controllers = [] : undefined[]
>this._controllers : templa.mvc.IController<templa.mvc.IModel>[]
>this : AbstractCompositeElementController<ModelType>
>_controllers : templa.mvc.IController<templa.mvc.IModel>[]
>[] : templa.mvc.IController<templa.mvc.IModel>[]
>[] : undefined[]
}
}
}
@@ -9,7 +9,7 @@ var ANY1;
var ANY2: any[] = ["", ""];
>ANY2 : any[]
>["", ""] : any[]
>["", ""] : string[]
var obj = {x:1,y:null};
>obj : { x: number; y: any; }
@@ -0,0 +1,24 @@
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'.
==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (3 errors) ====
// -- operator on enum type
enum ENUM1 { A, B, "" };
// expression
var ResultIsNumber1 = --ENUM1["A"];
var ResultIsNumber2 = ENUM1.A--;
~~~~~~~
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
// miss assignment operator
--ENUM1["A"];
ENUM1[A]--;
~~~~~~~~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
~
!!! error TS2304: Cannot find name 'A'.
@@ -1,29 +1,29 @@
//// [decrementOperatorWithEnumType.ts]
// -- operator on enum type
enum ENUM1 { 1, 2, "" };
enum ENUM1 { A, B, "" };
// expression
var ResultIsNumber1 = --ENUM1[1];
var ResultIsNumber2 = ENUM1[1]--;
var ResultIsNumber1 = --ENUM1["A"];
var ResultIsNumber2 = ENUM1.A--;
// miss assignment operator
--ENUM1[1];
--ENUM1["A"];
ENUM1[1]--;
ENUM1[A]--;
//// [decrementOperatorWithEnumType.js]
// -- operator on enum type
var ENUM1;
(function (ENUM1) {
ENUM1[ENUM1["1"] = 0] = "1";
ENUM1[ENUM1["2"] = 1] = "2";
ENUM1[ENUM1["A"] = 0] = "A";
ENUM1[ENUM1["B"] = 1] = "B";
ENUM1[ENUM1[""] = 2] = "";
})(ENUM1 || (ENUM1 = {}));
;
// expression
var ResultIsNumber1 = --ENUM1[1];
var ResultIsNumber2 = ENUM1[1]--;
var ResultIsNumber1 = --ENUM1["A"];
var ResultIsNumber2 = 0 /* A */--;
// miss assignment operator
--ENUM1[1];
ENUM1[1]--;
--ENUM1["A"];
ENUM1[A]--;
@@ -1,30 +0,0 @@
=== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts ===
// -- operator on enum type
enum ENUM1 { 1, 2, "" };
>ENUM1 : ENUM1
// expression
var ResultIsNumber1 = --ENUM1[1];
>ResultIsNumber1 : number
>--ENUM1[1] : number
>ENUM1[1] : ENUM1
>ENUM1 : typeof ENUM1
var ResultIsNumber2 = ENUM1[1]--;
>ResultIsNumber2 : number
>ENUM1[1]-- : number
>ENUM1[1] : ENUM1
>ENUM1 : typeof ENUM1
// miss assignment operator
--ENUM1[1];
>--ENUM1[1] : number
>ENUM1[1] : ENUM1
>ENUM1 : typeof ENUM1
ENUM1[1]--;
>ENUM1[1]-- : number
>ENUM1[1] : ENUM1
>ENUM1 : typeof ENUM1
@@ -2,19 +2,21 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,43): error TS2339: Property 'B' does not exist on type 'typeof ENUM'.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,29): error TS2339: Property 'A' does not exist on type 'typeof ENUM'.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts (10 errors) ====
==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts (12 errors) ====
// -- operator on enum type
enum ENUM { };
enum ENUM1 { 1, 2, "" };
enum ENUM1 { A, B, "" };
// enum type var
var ResultIsNumber1 = --ENUM;
@@ -32,12 +34,16 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
// enum type expressions
var ResultIsNumber5 = --(ENUM[1] + ENUM[2]);
~~~~~~~~~~~~~~~~~~~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
var ResultIsNumber6 = (ENUM[1] + ENUM[2])--;
~~~~~~~~~~~~~~~~~~~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
var ResultIsNumber5 = --(ENUM["A"] + ENUM.B);
~~~~~~~~~~~~~~~~~~~~
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
~
!!! error TS2339: Property 'B' does not exist on type 'typeof ENUM'.
var ResultIsNumber6 = (ENUM.A + ENUM["B"])--;
~~~~~~~~~~~~~~~~~~~~
!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer.
~
!!! error TS2339: Property 'A' does not exist on type 'typeof ENUM'.
// miss assignment operator
--ENUM;
@@ -2,7 +2,7 @@
// -- operator on enum type
enum ENUM { };
enum ENUM1 { 1, 2, "" };
enum ENUM1 { A, B, "" };
// enum type var
var ResultIsNumber1 = --ENUM;
@@ -12,8 +12,8 @@ var ResultIsNumber3 = ENUM--;
var ResultIsNumber4 = ENUM1--;
// enum type expressions
var ResultIsNumber5 = --(ENUM[1] + ENUM[2]);
var ResultIsNumber6 = (ENUM[1] + ENUM[2])--;
var ResultIsNumber5 = --(ENUM["A"] + ENUM.B);
var ResultIsNumber6 = (ENUM.A + ENUM["B"])--;
// miss assignment operator
--ENUM;
@@ -30,8 +30,8 @@ var ENUM;
;
var ENUM1;
(function (ENUM1) {
ENUM1[ENUM1["1"] = 0] = "1";
ENUM1[ENUM1["2"] = 1] = "2";
ENUM1[ENUM1["A"] = 0] = "A";
ENUM1[ENUM1["B"] = 1] = "B";
ENUM1[ENUM1[""] = 2] = "";
})(ENUM1 || (ENUM1 = {}));
;
@@ -41,8 +41,8 @@ var ResultIsNumber2 = --ENUM1;
var ResultIsNumber3 = ENUM--;
var ResultIsNumber4 = ENUM1--;
// enum type expressions
var ResultIsNumber5 = --(ENUM[1] + ENUM[2]);
var ResultIsNumber6 = (ENUM[1] + ENUM[2])--;
var ResultIsNumber5 = --(ENUM["A"] + ENUM.B);
var ResultIsNumber6 = (ENUM.A + ENUM["B"])--;
// miss assignment operator
--ENUM;
--ENUM1;
@@ -1,31 +1,27 @@
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(4,6): error TS2339: Property 'length' does not exist on type '{}'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(10,6): error TS2339: Property 'length' does not exist on type 'Object'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(18,27): error TS2339: Property 'length' does not exist on type '{}'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(2,6): error TS2339: Property 'length' does not exist on type '{}'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(5,6): error TS2339: Property 'length' does not exist on type 'Object'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(8,14): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts (3 errors) ====
var obj1: {};
obj1.length;
~~~~~~
!!! error TS2339: Property 'length' does not exist on type '{}'.
var obj2: Object;
obj2.length;
~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'Object'.
function concat<T>(x: T, y: T): T { return null; }
var result = concat(1, ""); // error
~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var elementCount = result.length;
var result = concat(1, "");
function concat2<T, U>(x: T, y: U) { return null; }
var result2 = concat2(1, ""); // result2 will be number|string
var elementCount2 = result.length;
var elementCount = result.length; // would like to get an error by now
~~~~~~
!!! error TS2339: Property 'length' does not exist on type '{}'.

Some files were not shown because too many files have changed in this diff Show More