Merge branch 'master' into disambiguating

This commit is contained in:
Yui T
2015-07-28 15:26:31 -07:00
365 changed files with 6559 additions and 6552 deletions

1
.gitignore vendored
View File

@@ -25,6 +25,7 @@ tests/baselines/reference/projectOutput/*
tests/baselines/local/projectOutput/*
tests/services/baselines/prototyping/local/*
tests/services/browser/typescriptServices.js
scripts/configureNightly.js
scripts/processDiagnosticMessages.d.ts
scripts/processDiagnosticMessages.js
scripts/importDefinitelyTypedTests.js

70
AUTHORS.md Normal file
View File

@@ -0,0 +1,70 @@
TypeScript is authored by:
* Adam Freidin
* Ahmad Farid
* Anders Hejlsberg
* Arnav Singh
* Arthur Ozga
* Basarat Ali Syed
* Ben Duffield
* Bill Ticehurst
* Bryan Forbes
* Caitlin Potter
* Chris Bubernak
* Colby Russell
* Colin Snover
* Cyrus Najmabadi
* Dan Quirk
* Daniel Rosenwasser
* David Li
* Dick van den Brink
* Dirk Bäumer
* Frank Wallis
* Gabriel Isenberg
* Gilad Peleg
* Guillaume Salles
* Harald Niesche
* Ingvar Stepanyan
* Ivo Gabe de Wolff
* James Whitney
* Jason Freeman
* Jason Ramsay
* Jed Mao
* Johannes Rieken
* Jonathan Bond-Caron
* Jonathan Park
* Jonathan Turner
* Josh Kalderimis
* Kagami Sascha Rosylight
* Keith Mashinter
* Kenji Imamula
* Lorant Pinter
* Masahiro Wakame
* Max Deepfield
* Micah Zoltu
* Mohamed Hegazy
* Oleg Mihailik
* Oleksandr Chekhovskyi
* Paul van Brenk
* Pedro Maltez
* Philip Bulley
* piloopin
* Ron Buckton
* Ryan Cavanaugh
* Sheetal Nandi
* Shengping Zhong
* Shyyko Serhiy
* Simon Hürlimann
* Solal Pirelli
* Stan Thomas
* Steve Lucco
* Tien Hoanhtien
* Tingan Ho
* togru
* Tomas Grubliauskas
* TruongSinh Tran-Nguyen
* Vladimir Matveev
* Wesley Wigham
* Yui Tanglertsampan
* Zev Spitz
* Zhengbo Li

View File

@@ -138,6 +138,7 @@ var harnessSources = harnessCoreSources.concat([
"services/documentRegistry.ts",
"services/preProcessFile.ts",
"services/patternMatcher.ts",
"session.ts",
"versionCache.ts",
"convertToBase64.ts",
"transpile.ts"
@@ -313,7 +314,7 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic
var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json");
var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts");
file(processDiagnosticMessagesTs)
file(processDiagnosticMessagesTs);
// processDiagnosticMessages script
compileFile(processDiagnosticMessagesJs,
@@ -338,12 +339,50 @@ file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson],
complete();
});
ex.run();
}, {async: true})
}, {async: true});
desc("Generates a diagnostic file in TypeScript based on an input JSON file");
task("generate-diagnostics", [diagnosticInfoMapTs])
task("generate-diagnostics", [diagnosticInfoMapTs]);
// Publish nightly
var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
var packageJson = "package.json";
var programTs = path.join(compilerDirectory, "program.ts");
file(configureNightlyTs);
compileFile(/*outfile*/configureNightlyJs,
/*sources*/ [configureNightlyTs],
/*prereqs*/ [configureNightlyTs],
/*prefixes*/ [],
/*useBuiltCompiler*/ false,
/*noOutFile*/ false,
/*generateDeclarations*/ false,
/*outDir*/ undefined,
/*preserveConstEnums*/ undefined,
/*keepComments*/ false,
/*noResolve*/ false,
/*stripInternal*/ false);
task("setDebugMode", function() {
useDebugMode = true;
});
task("configure-nightly", [configureNightlyJs], function() {
var cmd = "node " + configureNightlyJs + " " + packageJson + " " + programTs;
console.log(cmd);
exec(cmd);
}, { async: true });
desc("Configure, build, test, and publish the nightly release.");
task("publish-nightly", ["configure-nightly", "LKG", "clean", "setDebugMode", "runtests"], function () {
var cmd = "npm publish --tag next";
console.log(cmd);
exec(cmd);
});
// Local target to build the compiler and services
var tscFile = path.join(builtLocalDirectory, compilerFilename);
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
@@ -440,11 +479,11 @@ file(specMd, [word2mdJs, specWord], function () {
child_process.exec(cmd, function () {
complete();
});
}, {async: true})
}, {async: true});
desc("Generates a Markdown version of the Language Specification");
task("generate-spec", [specMd])
task("generate-spec", [specMd]);
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
@@ -576,7 +615,7 @@ task("runtests", ["tests", builtLocalDirectory], function() {
exec(cmd, deleteTemporaryProjectOutput);
}, {async: true});
desc("Generates code coverage data via instanbul")
desc("Generates code coverage data via instanbul");
task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run;
console.log(cmd);
@@ -619,7 +658,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
function getDiffTool() {
var program = process.env['DIFF']
if (!program) {
fail("Add the 'DIFF' environment variable to the path of the program you want to use.")
fail("Add the 'DIFF' environment variable to the path of the program you want to use.");
}
return program;
}
@@ -628,14 +667,14 @@ function getDiffTool() {
desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable");
task('diff', function () {
var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline;
console.log(cmd)
console.log(cmd);
exec(cmd);
}, {async: true});
desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable");
task('diff-rwc', function () {
var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline;
console.log(cmd)
console.log(cmd);
exec(cmd);
}, {async: true});
@@ -736,9 +775,9 @@ task("lint", [], function() {
function failure(f) { return function() { console.log('FAILURE: Please fix linting errors in ' + f + '\n') }};
var lintTargets = compilerSources.concat(harnessCoreSources);
for(var i in lintTargets) {
for (var i in lintTargets) {
var f = lintTargets[i];
var cmd = 'tslint -f ' + f;
var cmd = 'tslint -c tslint.json ' + f;
exec(cmd, success(f), failure(f));
}
}, { async: true });

View File

@@ -8,6 +8,19 @@
[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).
## Installing
For the latest stable version:
```
npm install -g typescript
```
For our nightly builds:
```
npm install -g typescript@next
```
## Contribute
@@ -63,7 +76,8 @@ jake runtests # Run tests using the built compiler and test infrastructu
# Use host=<hostName> or tests=<testPath>.
jake runtests-browser # Runs the tests using the built run.js file. Syntax is jake runtests. Optional
parameters 'host=', 'tests=[regex], reporter=[list|spec|json|<more>]'.
jake baseline-accept # This replaces the baseline test results with the results obtained from jake runtests.
jake baseline-accept # This replaces the baseline test results with the results obtained from jake runtests.
jake lint # Runs tslint on the TypeScript source.
jake -T # List the above commands.
```

View File

@@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "http://typescriptlang.org/",
"version": "1.5.3",
"version": "1.6.0",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [

View File

@@ -0,0 +1,73 @@
/// <reference path="../src/compiler/sys.ts" />
/**
* A minimal description for a parsed package.json object.
*/
interface PackageJson {
name: string;
version: string;
keywords: string[];
}
function main(): void {
const sys = ts.sys;
if (sys.args.length < 2) {
sys.write("Usage:" + sys.newLine)
sys.write("\tnode configureNightly.js <package.json location> <file containing version>" + sys.newLine);
return;
}
// Acquire the version from the package.json file and modify it appropriately.
const packageJsonFilePath = ts.normalizePath(sys.args[0]);
const packageJsonContents = sys.readFile(packageJsonFilePath);
const packageJsonValue: PackageJson = JSON.parse(packageJsonContents);
const nightlyVersion = getNightlyVersionString(packageJsonValue.version);
// Modify the package.json structure
packageJsonValue.version = nightlyVersion;
// Acquire and modify the source file that exposes the version string.
const tsFilePath = ts.normalizePath(sys.args[1]);
const tsFileContents = sys.readFile(tsFilePath);
const versionAssignmentRegExp = /export\s+const\s+version\s+=\s+".*";/;
const modifiedTsFileContents = tsFileContents.replace(versionAssignmentRegExp, `export const version = "${nightlyVersion}";`);
// Ensure we are actually changing something - the user probably wants to know that the update failed.
if (tsFileContents === modifiedTsFileContents) {
let err = `\n '${tsFilePath}' was not updated while configuring for a nightly publish.\n `;
if (tsFileContents.match(versionAssignmentRegExp)) {
err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`;
}
else {
err += `The file seems to no longer have a string matching '${versionAssignmentRegExp}'.`;
}
throw err + "\n";
}
// Finally write the changes to disk.
sys.writeFile(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4))
sys.writeFile(tsFilePath, modifiedTsFileContents);
}
function getNightlyVersionString(versionString: string): string {
// If the version string already contains "-nightly",
// then get the base string and update based on that.
const dashNightlyPos = versionString.indexOf("-dev");
if (dashNightlyPos >= 0) {
versionString = versionString.slice(0, dashNightlyPos);
}
// We're going to append a representation of the current time at the end of the current version.
// String.prototype.toISOString() returns a 24-character string formatted as 'YYYY-MM-DDTHH:mm:ss.sssZ',
// but we'd prefer to just remove separators and limit ourselves to YYYYMMDD.
// UTC time will always be implicit here.
const now = new Date();
const timeStr = now.toISOString().replace(/:|T|\.|-/g, "").slice(0, 8);
return `${versionString}-dev.${timeStr}`;
}
main();

View File

@@ -518,15 +518,21 @@ namespace ts {
}
else {
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
// if module was already merged with some function, class or non-const enum
// treat is a non-const-enum-only
node.symbol.constEnumOnlyModule = false;
}
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
}
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
}
}
}
}
@@ -1056,4 +1062,4 @@ namespace ts {
: declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
}
}
}
}

View File

@@ -59,17 +59,21 @@ namespace ts {
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
getDiagnostics,
getGlobalDiagnostics,
getTypeOfSymbolAtLocation,
// The language service will always care about the narrowed type of a symbol, because that is
// the type the language says the symbol should have.
getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol,
getPropertiesOfType,
getPropertyOfType,
getSignaturesOfType,
getIndexTypeOfType,
getBaseTypes,
getReturnTypeOfSignature,
getSymbolsInScope,
getSymbolAtLocation,
getShorthandAssignmentValueSymbol,
getTypeAtLocation,
getTypeAtLocation: getTypeOfNode,
typeToString,
getSymbolDisplayBuilder,
symbolToString,
@@ -159,8 +163,9 @@ namespace ts {
let emitAwaiter = false;
let emitGenerator = false;
let resolutionTargets: Object[] = [];
let resolutionTargets: TypeSystemEntity[] = [];
let resolutionResults: boolean[] = [];
let resolutionPropertyNames: TypeSystemPropertyName[] = [];
let mergedSymbols: Symbol[] = [];
let symbolLinks: SymbolLinks[] = [];
@@ -201,6 +206,15 @@ namespace ts {
let assignableRelation: Map<RelationComparisonResult> = {};
let identityRelation: Map<RelationComparisonResult> = {};
type TypeSystemEntity = Symbol | Type | Signature;
const enum TypeSystemPropertyName {
Type,
ResolvedBaseConstructorType,
DeclaredType,
ResolvedReturnType
}
initializeTypeChecker();
return checker;
@@ -1992,15 +2006,12 @@ namespace ts {
}
return _displayBuilder || (_displayBuilder = {
symbolToString: symbolToString,
typeToString: typeToString,
buildSymbolDisplay: buildSymbolDisplay,
buildTypeDisplay: buildTypeDisplay,
buildTypeParameterDisplay: buildTypeParameterDisplay,
buildParameterDisplay: buildParameterDisplay,
buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters,
buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters,
buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters,
buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol,
buildSignatureDisplay: buildSignatureDisplay,
buildReturnTypeDisplay: buildReturnTypeDisplay
@@ -2189,35 +2200,69 @@ namespace ts {
}
}
// Push an entry on the type resolution stack. If an entry with the given target is not already on the stack,
// a new entry with that target and an associated result value of true is pushed on the stack, and the value
// true is returned. Otherwise, a circularity has occurred and the result values of the existing entry and
// all entries pushed after it are changed to false, and the value false is returned. The target object provides
// a unique identity for a particular type resolution result: Symbol instances are used to track resolution of
// SymbolLinks.type, SymbolLinks instances are used to track resolution of SymbolLinks.declaredType, and
// Signature instances are used to track resolution of Signature.resolvedReturnType.
function pushTypeResolution(target: Object): boolean {
let i = 0;
let count = resolutionTargets.length;
while (i < count && resolutionTargets[i] !== target) {
i++;
}
if (i < count) {
do {
resolutionResults[i++] = false;
/**
* Push an entry on the type resolution stack. If an entry with the given target and the given property name
* is already on the stack, and no entries in between already have a type, then a circularity has occurred.
* In this case, the result values of the existing entry and all entries pushed after it are changed to false,
* and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned.
* In order to see if the same query has already been done before, the target object and the propertyName both
* must match the one passed in.
*
* @param target The symbol, type, or signature whose type is being queried
* @param propertyName The property name that should be used to query the target for its type
*/
function pushTypeResolution(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): boolean {
let resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName);
if (resolutionCycleStartIndex >= 0) {
// A cycle was found
let { length } = resolutionTargets;
for (let i = resolutionCycleStartIndex; i < length; i++) {
resolutionResults[i] = false;
}
while (i < count);
return false;
}
resolutionTargets.push(target);
resolutionResults.push(true);
resolutionPropertyNames.push(propertyName);
return true;
}
function findResolutionCycleStartIndex(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): number {
for (let i = resolutionTargets.length - 1; i >= 0; i--) {
if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) {
return -1;
}
if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) {
return i;
}
}
return -1;
}
function hasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): Type {
if (propertyName === TypeSystemPropertyName.Type) {
return getSymbolLinks(<Symbol>target).type;
}
if (propertyName === TypeSystemPropertyName.DeclaredType) {
return getSymbolLinks(<Symbol>target).declaredType;
}
if (propertyName === TypeSystemPropertyName.ResolvedBaseConstructorType) {
Debug.assert(!!((<Type>target).flags & TypeFlags.Class));
return (<InterfaceType>target).resolvedBaseConstructorType;
}
if (propertyName === TypeSystemPropertyName.ResolvedReturnType) {
return (<Signature>target).resolvedReturnType;
}
Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
}
// Pop an entry from the type resolution stack and return its associated result value. The result value will
// be true if no circularities were detected, or false if a circularity was found.
function popTypeResolution(): boolean {
resolutionTargets.pop();
resolutionPropertyNames.pop();
return resolutionResults.pop();
}
@@ -2480,7 +2525,7 @@ namespace ts {
return links.type = checkExpression((<ExportAssignment>declaration).expression);
}
// Handle variable, parameter or property
if (!pushTypeResolution(symbol)) {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
}
let type = getWidenedTypeForVariableLikeDeclaration(<VariableLikeDeclaration>declaration, /*reportErrors*/ true);
@@ -2521,7 +2566,7 @@ namespace ts {
function getTypeOfAccessors(symbol: Symbol): Type {
let links = getSymbolLinks(symbol);
if (!links.type) {
if (!pushTypeResolution(symbol)) {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
}
let getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
@@ -2737,7 +2782,7 @@ namespace ts {
if (!baseTypeNode) {
return type.resolvedBaseConstructorType = undefinedType;
}
if (!pushTypeResolution(type)) {
if (!pushTypeResolution(type, TypeSystemPropertyName.ResolvedBaseConstructorType)) {
return unknownType;
}
let baseConstructorType = checkExpression(baseTypeNode.expression);
@@ -2864,7 +2909,7 @@ namespace ts {
if (!links.declaredType) {
// Note that we use the links object as the target here because the symbol object is used as the unique
// identity for resolution of the 'type' property in SymbolLinks.
if (!pushTypeResolution(links)) {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.DeclaredType)) {
return unknownType;
}
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
@@ -3080,44 +3125,57 @@ namespace ts {
setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
}
function signatureListsIdentical(s: Signature[], t: Signature[]): boolean {
if (s.length !== t.length) {
return false;
}
for (let i = 0; i < s.length; i++) {
if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, compareTypes)) {
return false;
function findMatchingSignature(signature: Signature, signatureList: Signature[]): Signature {
for (let s of signatureList) {
// Only signatures with no type parameters may differ in return types
if (compareSignatures(signature, s, /*compareReturnTypes*/ !!signature.typeParameters, compareTypes)) {
return s;
}
}
return true;
}
// If the lists of call or construct signatures in the given types are all identical except for return types,
// and if none of the signatures are generic, return a list of signatures that has substitutes a union of the
// return types of the corresponding signatures in each resulting signature.
function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] {
let signatureLists = map(types, t => getSignaturesOfType(t, kind));
let signatures = signatureLists[0];
for (let signature of signatures) {
if (signature.typeParameters) {
return emptyArray;
}
}
function findMatchingSignatures(signature: Signature, signatureLists: Signature[][]): Signature[] {
let result: Signature[] = undefined;
for (let i = 1; i < signatureLists.length; i++) {
if (!signatureListsIdentical(signatures, signatureLists[i])) {
return emptyArray;
let match = findMatchingSignature(signature, signatureLists[i]);
if (!match) {
return undefined;
}
if (!result) {
result = [signature];
}
if (match !== signature) {
result.push(match);
}
}
let result = map(signatures, cloneSignature);
for (var i = 0; i < result.length; i++) {
let s = result[i];
// Clear resolved return type we possibly got from cloneSignature
s.resolvedReturnType = undefined;
s.unionSignatures = map(signatureLists, signatures => signatures[i]);
}
return result;
}
// The signatures of a union type are those signatures that are present and identical in each of the
// constituent types, except that non-generic signatures may differ in return types. When signatures
// differ in return types, the resulting return type is the union of the constituent return types.
function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] {
let signatureLists = map(types, t => getSignaturesOfType(t, kind));
let result: Signature[] = undefined;
for (let source of signatureLists[0]) {
let unionSignatures = findMatchingSignatures(source, signatureLists);
if (unionSignatures) {
let signature: Signature = undefined;
if (unionSignatures.length === 1 || source.typeParameters) {
signature = source;
}
else {
signature = cloneSignature(source);
// Clear resolved return type we possibly got from cloneSignature
signature.resolvedReturnType = undefined;
signature.unionSignatures = unionSignatures;
}
(result || (result = [])).push(signature);
}
}
return result || emptyArray;
}
function getUnionIndexType(types: Type[], kind: IndexKind): Type {
let indexTypes: Type[] = [];
for (let type of types) {
@@ -3275,9 +3333,6 @@ namespace ts {
* type itself. Note that the apparent type of a union type is the union type itself.
*/
function getApparentType(type: Type): Type {
if (type.flags & TypeFlags.Union) {
type = getReducedTypeOfUnionType(<UnionType>type);
}
if (type.flags & TypeFlags.TypeParameter) {
do {
type = getConstraintOfTypeParameter(<TypeParameter>type);
@@ -3382,6 +3437,29 @@ namespace ts {
return undefined;
}
// Check if a property with the given name is known anywhere in the given type. In an object
// type, a property is considered known if the object type is empty, if it has any index
// signatures, or if the property is actually declared in the type. In a union or intersection
// type, a property is considered known if it is known in any constituent type.
function isKnownProperty(type: Type, name: string): boolean {
if (type.flags & TypeFlags.ObjectType && type !== globalObjectType) {
var resolved = resolveStructuredTypeMembers(type);
return !!(resolved.properties.length === 0 ||
resolved.stringIndexType ||
resolved.numberIndexType ||
getPropertyOfType(type, name));
}
if (type.flags & TypeFlags.UnionOrIntersection) {
for (let t of (<UnionOrIntersectionType>type).types) {
if (isKnownProperty(t, name)) {
return true;
}
}
return false;
}
return true;
}
function getSignaturesOfStructuredType(type: Type, kind: SignatureKind): Signature[] {
if (type.flags & TypeFlags.StructuredType) {
let resolved = resolveStructuredTypeMembers(<ObjectType>type);
@@ -3551,7 +3629,7 @@ namespace ts {
function getReturnTypeOfSignature(signature: Signature): Type {
if (!signature.resolvedReturnType) {
if (!pushTypeResolution(signature)) {
if (!pushTypeResolution(signature, TypeSystemPropertyName.ResolvedReturnType)) {
return unknownType;
}
let type: Type;
@@ -3991,26 +4069,79 @@ namespace ts {
}
}
function isSubtypeOfAny(candidate: Type, types: Type[]): boolean {
function isObjectLiteralTypeDuplicateOf(source: ObjectType, target: ObjectType): boolean {
let sourceProperties = getPropertiesOfObjectType(source);
let targetProperties = getPropertiesOfObjectType(target);
if (sourceProperties.length !== targetProperties.length) {
return false;
}
for (let sourceProp of sourceProperties) {
let targetProp = getPropertyOfObjectType(target, sourceProp.name);
if (!targetProp ||
getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected) ||
!isTypeDuplicateOf(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp))) {
return false;
}
}
return true;
}
function isTupleTypeDuplicateOf(source: TupleType, target: TupleType): boolean {
let sourceTypes = source.elementTypes;
let targetTypes = target.elementTypes;
if (sourceTypes.length !== targetTypes.length) {
return false;
}
for (var i = 0; i < sourceTypes.length; i++) {
if (!isTypeDuplicateOf(sourceTypes[i], targetTypes[i])) {
return false;
}
}
return true;
}
// Returns true if the source type is a duplicate of the target type. A source type is a duplicate of
// a target type if the the two are identical, with the exception that the source type may have null or
// undefined in places where the target type doesn't. This is by design an asymmetric relationship.
function isTypeDuplicateOf(source: Type, target: Type): boolean {
if (source === target) {
return true;
}
if (source.flags & TypeFlags.Undefined || source.flags & TypeFlags.Null && !(target.flags & TypeFlags.Undefined)) {
return true;
}
if (source.flags & TypeFlags.ObjectLiteral && target.flags & TypeFlags.ObjectType) {
return isObjectLiteralTypeDuplicateOf(<ObjectType>source, <ObjectType>target);
}
if (isArrayType(source) && isArrayType(target)) {
return isTypeDuplicateOf((<TypeReference>source).typeArguments[0], (<TypeReference>target).typeArguments[0]);
}
if (isTupleType(source) && isTupleType(target)) {
return isTupleTypeDuplicateOf(<TupleType>source, <TupleType>target);
}
return isTypeIdenticalTo(source, target);
}
function isTypeDuplicateOfSomeType(candidate: Type, types: Type[]): boolean {
for (let type of types) {
if (candidate !== type && isTypeSubtypeOf(candidate, type)) {
if (candidate !== type && isTypeDuplicateOf(candidate, type)) {
return true;
}
}
return false;
}
function removeSubtypes(types: Type[]) {
function removeDuplicateTypes(types: Type[]) {
let i = types.length;
while (i > 0) {
i--;
if (isSubtypeOfAny(types[i], types)) {
if (isTypeDuplicateOfSomeType(types[i], types)) {
types.splice(i, 1);
}
}
}
function containsTypeAny(types: Type[]) {
function containsTypeAny(types: Type[]): boolean {
for (let type of types) {
if (isTypeAny(type)) {
return true;
@@ -4029,30 +4160,26 @@ namespace ts {
}
}
function compareTypeIds(type1: Type, type2: Type): number {
return type1.id - type2.id;
}
// The noSubtypeReduction flag is there because it isn't possible to always do subtype reduction. The flag
// is true when creating a union type from a type node and when instantiating a union type. In both of those
// cases subtype reduction has to be deferred to properly support recursive union types. For example, a
// type alias of the form "type Item = string | (() => Item)" cannot be reduced during its declaration.
function getUnionType(types: Type[], noSubtypeReduction?: boolean): Type {
// We always deduplicate the constituent type set based on object identity, but we'll also deduplicate
// based on the structure of the types unless the noDeduplication flag is true, which is the case when
// creating a union type from a type node and when instantiating a union type. In both of those cases,
// structural deduplication has to be deferred to properly support recursive union types. For example,
// a type of the form "type Item = string | (() => Item)" cannot be deduplicated during its declaration.
function getUnionType(types: Type[], noDeduplication?: boolean): Type {
if (types.length === 0) {
return emptyObjectType;
}
let typeSet: Type[] = [];
addTypesToSet(typeSet, types, TypeFlags.Union);
typeSet.sort(compareTypeIds);
if (noSubtypeReduction) {
if (containsTypeAny(typeSet)) {
return anyType;
}
if (containsTypeAny(typeSet)) {
return anyType;
}
if (noDeduplication) {
removeAllButLast(typeSet, undefinedType);
removeAllButLast(typeSet, nullType);
}
else {
removeSubtypes(typeSet);
removeDuplicateTypes(typeSet);
}
if (typeSet.length === 1) {
return typeSet[0];
@@ -4062,38 +4189,19 @@ namespace ts {
if (!type) {
type = unionTypes[id] = <UnionType>createObjectType(TypeFlags.Union | getWideningFlagsOfTypes(typeSet));
type.types = typeSet;
type.reducedType = noSubtypeReduction ? undefined : type;
}
return type;
}
// Subtype reduction is basically an optimization we do to avoid excessively large union types, which take longer
// to process and look strange in quick info and error messages. Semantically there is no difference between the
// reduced type and the type itself. So, when we detect a circularity we simply say that the reduced type is the
// type itself.
function getReducedTypeOfUnionType(type: UnionType): Type {
if (!type.reducedType) {
type.reducedType = circularType;
let reducedType = getUnionType(type.types, /*noSubtypeReduction*/ false);
if (type.reducedType === circularType) {
type.reducedType = reducedType;
}
}
else if (type.reducedType === circularType) {
type.reducedType = type;
}
return type.reducedType;
}
function getTypeFromUnionTypeNode(node: UnionTypeNode): Type {
let links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true);
links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noDeduplication*/ true);
}
return links.resolvedType;
}
// We do not perform supertype reduction on intersection types. Intersection types are created only by the &
// We do not perform structural deduplication on intersection types. Intersection types are created only by the &
// type operator and we can't reduce those because we want to support recursive intersection types. For example,
// a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
// Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
@@ -4196,7 +4304,7 @@ namespace ts {
// Callers should first ensure this by calling isTypeNode
case SyntaxKind.Identifier:
case SyntaxKind.QualifiedName:
let symbol = getSymbolInfo(node);
let symbol = getSymbolAtLocation(node);
return symbol && getDeclaredTypeOfSymbol(symbol);
default:
return unknownType;
@@ -4374,7 +4482,7 @@ namespace ts {
return createTupleType(instantiateList((<TupleType>type).elementTypes, mapper, instantiateType));
}
if (type.flags & TypeFlags.Union) {
return getUnionType(instantiateList((<UnionType>type).types, mapper, instantiateType), /*noSubtypeReduction*/ true);
return getUnionType(instantiateList((<UnionType>type).types, mapper, instantiateType), /*noDeduplication*/ true);
}
if (type.flags & TypeFlags.Intersection) {
return getIntersectionType(instantiateList((<IntersectionType>type).types, mapper, instantiateType));
@@ -4519,6 +4627,16 @@ namespace ts {
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
}
function reportRelationError(message: DiagnosticMessage, source: Type, target: Type) {
let sourceType = typeToString(source);
let targetType = typeToString(target);
if (sourceType === targetType) {
sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
}
reportError(message || Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType);
}
// Compare two types and return
// Ternary.True if they are related with no assumptions,
// Ternary.Maybe if they are related with assumptions of other relationships, or
@@ -4538,7 +4656,23 @@ namespace ts {
if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True;
}
}
if (relation !== identityRelation && source.flags & TypeFlags.FreshObjectLiteral) {
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
if (reportErrors) {
reportRelationError(headMessage, source, target);
}
return Ternary.False;
}
// Above we check for excess properties with respect to the entire target type. When union
// and intersection types are further deconstructed on the target side, we don't want to
// make the check again (as it might fail for a partial target type). Therefore we obtain
// the regular source type and proceed with that.
source = getRegularTypeOfObjectLiteral(source);
}
let saveErrorInfo = errorInfo;
if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to same target type, see if relationship holds for all type arguments
if (result = typesRelatedTo((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, reportErrors)) {
@@ -4615,18 +4749,22 @@ namespace ts {
}
if (reportErrors) {
headMessage = headMessage || Diagnostics.Type_0_is_not_assignable_to_type_1;
let sourceType = typeToString(source);
let targetType = typeToString(target);
if (sourceType === targetType) {
sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
}
reportError(headMessage, sourceType, targetType);
reportRelationError(headMessage, source, target);
}
return Ternary.False;
}
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
for (let prop of getPropertiesOfObjectType(source)) {
if (!isKnownProperty(target, prop.name)) {
if (reportErrors) {
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
}
return true;
}
}
}
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {
let result = Ternary.True;
let sourceTypes = source.types;
@@ -5323,6 +5461,24 @@ namespace ts {
return !!(type.flags & TypeFlags.Tuple);
}
function getRegularTypeOfObjectLiteral(type: Type): Type {
if (type.flags & TypeFlags.FreshObjectLiteral) {
let regularType = (<FreshObjectLiteralType>type).regularType;
if (!regularType) {
regularType = <ResolvedType>createType((<ResolvedType>type).flags & ~TypeFlags.FreshObjectLiteral);
regularType.symbol = (<ResolvedType>type).symbol;
regularType.members = (<ResolvedType>type).members;
regularType.properties = (<ResolvedType>type).properties;
regularType.callSignatures = (<ResolvedType>type).callSignatures;
regularType.constructSignatures = (<ResolvedType>type).constructSignatures;
regularType.stringIndexType = (<ResolvedType>type).stringIndexType;
regularType.numberIndexType = (<ResolvedType>type).numberIndexType;
}
return regularType;
}
return type;
}
function getWidenedTypeOfObjectLiteral(type: Type): Type {
let properties = getPropertiesOfObjectType(type);
let members: SymbolTable = {};
@@ -5853,47 +6009,6 @@ namespace ts {
}
}
function resolveLocation(node: Node) {
// Resolve location from top down towards node if it is a context sensitive expression
// That helps in making sure not assigning types as any when resolved out of order
let containerNodes: Node[] = [];
for (let parent = node.parent; parent; parent = parent.parent) {
if ((isExpression(parent) || isObjectLiteralMethod(node)) &&
isContextSensitive(<Expression>parent)) {
containerNodes.unshift(parent);
}
}
ts.forEach(containerNodes, node => { getTypeOfNode(node); });
}
function getSymbolAtLocation(node: Node): Symbol {
resolveLocation(node);
return getSymbolInfo(node);
}
function getTypeAtLocation(node: Node): Type {
resolveLocation(node);
return getTypeOfNode(node);
}
function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type {
resolveLocation(node);
// Get the narrowed type of symbol at given location instead of just getting
// the type of the symbol.
// eg.
// function foo(a: string | number) {
// if (typeof a === "string") {
// a/**/
// }
// }
// getTypeOfSymbol for a would return type of parameter symbol string | number
// Unless we provide location /**/, checker wouldn't know how to narrow the type
// By using getNarrowedTypeOfSymbol would return string since it would be able to narrow
// it by typeguard in the if true condition
return getNarrowedTypeOfSymbol(symbol, node);
}
// Get the narrowed type of a given symbol at a given location
function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) {
let type = getTypeOfSymbol(symbol);
@@ -6990,7 +7105,7 @@ namespace ts {
let stringIndexType = getIndexType(IndexKind.String);
let numberIndexType = getIndexType(IndexKind.Number);
let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsUndefinedOrNull);
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.FreshObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsUndefinedOrNull);
return result;
function getIndexType(kind: IndexKind) {
@@ -7221,10 +7336,9 @@ namespace ts {
* For example, in the element <MyClass>, the element instance type is `MyClass` (not `typeof MyClass`).
*/
function getJsxElementInstanceType(node: JsxOpeningLikeElement) {
if (!(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement)) {
// There is no such thing as an instance type for a non-class element
return undefined;
}
// There is no such thing as an instance type for a non-class element. This
// line shouldn't be hit.
Debug.assert(!!(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement), 'Should not call getJsxElementInstanceType on non-class Element');
let classSymbol = getJsxElementTagSymbol(node);
if (classSymbol === unknownSymbol) {
@@ -7247,16 +7361,11 @@ namespace ts {
if (signatures.length === 0) {
// We found no signatures at all, which is an error
error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName));
return undefined;
return unknownType;
}
}
// Check that the constructor/factory returns an object type
let returnType = getUnionType(signatures.map(s => getReturnTypeOfSignature(s)));
if (!isTypeAny(returnType) && !(returnType.flags & TypeFlags.ObjectType)) {
error(node.tagName, Diagnostics.The_return_type_of_a_JSX_element_constructor_must_return_an_object_type);
return undefined;
}
let returnType = getUnionType(signatures.map(getReturnTypeOfSignature));
// Issue an error if this return type isn't assignable to JSX.ElementClass
let elemClassType = getJsxGlobalElementClassType();
@@ -7317,7 +7426,7 @@ namespace ts {
let elemInstanceType = getJsxElementInstanceType(node);
if (isTypeAny(elemInstanceType)) {
return links.resolvedJsxType = anyType;
return links.resolvedJsxType = elemInstanceType;
}
let propsName = getJsxElementPropertiesName();
@@ -8522,6 +8631,9 @@ namespace ts {
if (!produceDiagnostics) {
for (let candidate of candidates) {
if (hasCorrectArity(node, args, candidate)) {
if (candidate.typeParameters && typeArguments) {
candidate = getSignatureInstantiation(candidate, map(typeArguments, getTypeFromTypeNode));
}
return candidate;
}
}
@@ -8870,7 +8982,7 @@ namespace ts {
}
function checkAssertion(node: AssertionExpression) {
let exprType = checkExpression(node.expression);
let exprType = getRegularTypeOfObjectLiteral(checkExpression(node.expression));
let targetType = getTypeFromTypeNode(node.type);
if (produceDiagnostics && targetType !== unknownType) {
let widenedType = getWidenedType(exprType);
@@ -9695,7 +9807,7 @@ namespace ts {
return getUnionType([leftType, rightType]);
case SyntaxKind.EqualsToken:
checkAssignmentOperator(rightType);
return rightType;
return getRegularTypeOfObjectLiteral(rightType);
case SyntaxKind.CommaToken:
return rightType;
}
@@ -10120,7 +10232,7 @@ namespace ts {
}
else {
checkTypeAssignableTo(typePredicate.type,
getTypeAtLocation(node.parameters[typePredicate.parameterIndex]),
getTypeOfNode(node.parameters[typePredicate.parameterIndex]),
typePredicateNode.type);
}
}
@@ -10331,10 +10443,19 @@ namespace ts {
// TS 1.0 spec (April 2014): 8.3.2
// Constructors of classes with no extends clause may not contain super calls, whereas
// constructors of derived classes must contain at least one super call somewhere in their function body.
if (getClassExtendsHeritageClauseElement(<ClassDeclaration>node.parent)) {
let containingClassDecl = <ClassDeclaration>node.parent;
if (getClassExtendsHeritageClauseElement(containingClassDecl)) {
let containingClassSymbol = getSymbolOfNode(containingClassDecl);
let containingClassInstanceType = <InterfaceType>getDeclaredTypeOfSymbol(containingClassSymbol);
let baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType);
if (containsSuperCall(node.body)) {
// The first statement in the body of a constructor must be a super call if both of the following are true:
if (baseConstructorType === nullType) {
error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
}
// The first statement in the body of a constructor (excluding prologue directives) must be a super call
// if both of the following are true:
// - The containing class is a derived class.
// - The constructor declares parameter properties
// or the containing class declares instance member variables with initializers.
@@ -10342,18 +10463,30 @@ namespace ts {
forEach((<ClassDeclaration>node.parent).members, isInstancePropertyWithInitializer) ||
forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected));
// Skip past any prologue directives to find the first statement
// to ensure that it was a super call.
if (superCallShouldBeFirst) {
let statements = (<Block>node.body).statements;
if (!statements.length || statements[0].kind !== SyntaxKind.ExpressionStatement || !isSuperCallExpression((<ExpressionStatement>statements[0]).expression)) {
error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
let superCallStatement: ExpressionStatement;
for (let statement of statements) {
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((<ExpressionStatement>statement).expression)) {
superCallStatement = <ExpressionStatement>statement;
break;
}
if (!isPrologueDirective(statement)) {
break;
}
}
if (!superCallStatement) {
error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
}
else {
// In such a required super call, it is a compile-time error for argument expressions to reference this.
markThisReferencesAsErrors((<ExpressionStatement>statements[0]).expression);
markThisReferencesAsErrors(superCallStatement.expression);
}
}
}
else {
else if (baseConstructorType !== nullType) {
error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call);
}
}
@@ -10744,9 +10877,6 @@ namespace ts {
return;
}
// Exports should be checked only if enclosing module contains both exported and non exported declarations.
// In case if all declarations are non-exported check is unnecessary.
// if localSymbol is defined on node then node itself is exported - check is required
let symbol = node.localSymbol;
if (!symbol) {
@@ -10766,27 +10896,45 @@ namespace ts {
// we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
// to denote disjoint declarationSpaces (without making new enum type).
let exportedDeclarationSpaces: SymbolFlags = 0;
let nonExportedDeclarationSpaces: SymbolFlags = 0;
forEach(symbol.declarations, d => {
let exportedDeclarationSpaces = SymbolFlags.None;
let nonExportedDeclarationSpaces = SymbolFlags.None;
let defaultExportedDeclarationSpaces = SymbolFlags.None;
for (let d of symbol.declarations) {
let declarationSpaces = getDeclarationSpaces(d);
if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) {
exportedDeclarationSpaces |= declarationSpaces;
let effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, NodeFlags.Export | NodeFlags.Default);
if (effectiveDeclarationFlags & NodeFlags.Export) {
if (effectiveDeclarationFlags & NodeFlags.Default) {
defaultExportedDeclarationSpaces |= declarationSpaces;
}
else {
exportedDeclarationSpaces |= declarationSpaces;
}
}
else {
nonExportedDeclarationSpaces |= declarationSpaces;
}
});
}
let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
// Spaces for anyting not declared a 'default export'.
let nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces;
let commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
let commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces;
if (commonDeclarationSpace) {
if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) {
// declaration spaces for exported and non-exported declarations intersect
forEach(symbol.declarations, d => {
if (getDeclarationSpaces(d) & commonDeclarationSpace) {
for (let d of symbol.declarations) {
let declarationSpaces = getDeclarationSpaces(d);
// Only error on the declarations that conributed to the intersecting spaces.
if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) {
error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, declarationNameToString(d.name));
}
else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) {
error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name));
}
});
}
}
function getDeclarationSpaces(d: Declaration): SymbolFlags {
@@ -12631,28 +12779,7 @@ namespace ts {
}
let initializer = member.initializer;
if (initializer) {
autoValue = getConstantValueForEnumMemberInitializer(initializer);
if (autoValue === undefined) {
if (enumIsConst) {
error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
}
else if (!ambient) {
// Only here do we need to check that the initializer is assignable to the enum type.
// If it is a constant value (not undefined), it is syntactically constrained to be a number.
// Also, we do not need to check this for ambients because there is already
// a syntax error if it is not a constant.
checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined);
}
}
else if (enumIsConst) {
if (isNaN(autoValue)) {
error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
}
else if (!isFinite(autoValue)) {
error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
}
}
autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient);
}
else if (ambient && !enumIsConst) {
autoValue = undefined;
@@ -12666,8 +12793,36 @@ namespace ts {
nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed;
}
function getConstantValueForEnumMemberInitializer(initializer: Expression): number {
return evalConstant(initializer);
function computeConstantValueForEnumMemberInitializer(initializer: Expression, enumType: Type, enumIsConst: boolean, ambient: boolean): number {
// Controls if error should be reported after evaluation of constant value is completed
// Can be false if another more precise error was already reported during evaluation.
let reportError = true;
let value = evalConstant(initializer);
if (reportError) {
if (value === undefined) {
if (enumIsConst) {
error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
}
else if (!ambient) {
// Only here do we need to check that the initializer is assignable to the enum type.
// If it is a constant value (not undefined), it is syntactically constrained to be a number.
// Also, we do not need to check this for ambients because there is already
// a syntax error if it is not a constant.
checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined);
}
}
else if (enumIsConst) {
if (isNaN(value)) {
error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
}
else if (!isFinite(value)) {
error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
}
}
}
return value;
function evalConstant(e: Node): number {
switch (e.kind) {
@@ -12776,6 +12931,8 @@ namespace ts {
// illegal case: forward reference
if (!isDefinedBefore(propertyDecl, member)) {
reportError = false;
error(e, Diagnostics.A_member_initializer_in_a_const_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_const_enums);
return undefined;
}
@@ -13742,7 +13899,7 @@ namespace ts {
return undefined;
}
function getSymbolInfo(node: Node) {
function getSymbolAtLocation(node: Node) {
if (isInsideWithStatementBody(node)) {
// We cannot answer semantic questions within a with block, do not proceed any further
return undefined;
@@ -13762,7 +13919,7 @@ namespace ts {
else if (node.parent.kind === SyntaxKind.BindingElement &&
node.parent.parent.kind === SyntaxKind.ObjectBindingPattern &&
node === (<BindingElement>node.parent).propertyName) {
let typeOfPattern = getTypeAtLocation(node.parent.parent);
let typeOfPattern = getTypeOfNode(node.parent.parent);
let propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, (<Identifier>node).text);
if (propertyDeclaration) {
@@ -13845,24 +14002,24 @@ namespace ts {
}
if (isTypeDeclaration(node)) {
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
let symbol = getSymbolOfNode(node);
return getDeclaredTypeOfSymbol(symbol);
}
if (isTypeDeclarationName(node)) {
let symbol = getSymbolInfo(node);
let symbol = getSymbolAtLocation(node);
return symbol && getDeclaredTypeOfSymbol(symbol);
}
if (isDeclaration(node)) {
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
let symbol = getSymbolOfNode(node);
return getTypeOfSymbol(symbol);
}
if (isDeclarationName(node)) {
let symbol = getSymbolInfo(node);
let symbol = getSymbolAtLocation(node);
return symbol && getTypeOfSymbol(symbol);
}
@@ -13871,7 +14028,7 @@ namespace ts {
}
if (isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
let symbol = getSymbolInfo(node);
let symbol = getSymbolAtLocation(node);
let declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
}
@@ -14040,7 +14197,11 @@ namespace ts {
return true;
}
// const enums and modules that contain only const enums are not considered values from the emit perespective
return target !== unknownSymbol && target && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target);
// unless 'preserveConstEnums' option is set to true
return target !== unknownSymbol &&
target &&
target.flags & SymbolFlags.Value &&
(compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
}
function isConstEnumOrConstEnumOnlyModule(s: Symbol): boolean {

View File

@@ -254,6 +254,7 @@ namespace ts {
Only_a_void_function_can_be_called_with_the_new_keyword: { code: 2350, category: DiagnosticCategory.Error, key: "Only a void function can be called with the 'new' keyword." },
Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature: { code: 2351, category: DiagnosticCategory.Error, key: "Cannot use 'new' with an expression whose type lacks a call or construct signature." },
Neither_type_0_nor_type_1_is_assignable_to_the_other: { code: 2352, category: DiagnosticCategory.Error, key: "Neither type '{0}' nor type '{1}' is assignable to the other." },
Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1: { code: 2353, category: DiagnosticCategory.Error, key: "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'." },
No_best_common_type_exists_among_return_expressions: { code: 2354, category: DiagnosticCategory.Error, key: "No best common type exists among return expressions." },
A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2355, category: DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement." },
An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type: { code: 2356, category: DiagnosticCategory.Error, key: "An arithmetic operand must be of type 'any', 'number' or an enum type." },
@@ -293,7 +294,7 @@ namespace ts {
Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
Duplicate_function_implementation: { code: 2393, category: DiagnosticCategory.Error, key: "Duplicate function implementation." },
Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." },
Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration '{0}' must be all exported or all local." },
Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." },
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." },
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." },
@@ -424,6 +425,8 @@ namespace ts {
JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" },
The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" },
Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
A_member_initializer_in_a_const_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_const_enums: { code: 2651, category: DiagnosticCategory.Error, key: "A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums." },
Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
@@ -508,7 +511,6 @@ namespace ts {
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." },
Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." },
Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." },
Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." },
@@ -613,5 +615,6 @@ namespace ts {
Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." },
JSX_attribute_expected: { code: 17003, category: DiagnosticCategory.Error, key: "JSX attribute expected." },
Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." },
A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" },
};
}

View File

@@ -1,4 +1,4 @@
{
{
"Unterminated string literal.": {
"category": "Error",
"code": 1002
@@ -1005,6 +1005,10 @@
"category": "Error",
"code": 2352
},
"Object literal may only specify known properties, and '{0}' does not exist in type '{1}'.": {
"category": "Error",
"code": 2353
},
"No best common type exists among return expressions.": {
"category": "Error",
"code": 2354
@@ -1161,7 +1165,7 @@
"category": "Error",
"code": 2394
},
"Individual declarations in merged declaration {0} must be all exported or all local.": {
"Individual declarations in merged declaration '{0}' must be all exported or all local.": {
"category": "Error",
"code": 2395
},
@@ -1685,6 +1689,14 @@
"category": "Error",
"code": 2650
},
"A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums.": {
"category": "Error",
"code": 2651
},
"Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead.": {
"category": "Error",
"code": 2652
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
@@ -2021,10 +2033,6 @@
"category": "Error",
"code": 5042
},
"Option 'sourceMap' cannot be specified with option 'isolatedModules'.": {
"category": "Error",
"code": 5043
},
"Option 'declaration' cannot be specified with option 'isolatedModules'.": {
"category": "Error",
"code": 5044
@@ -2445,5 +2453,9 @@
"Cannot use JSX unless the '--jsx' flag is provided.": {
"category": "Error",
"code": 17004
},
"A constructor cannot contain a 'super' call when its class extends 'null'": {
"category": "Error",
"code": 17005
}
}

View File

@@ -1425,6 +1425,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
case SyntaxKind.IfStatement:
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.JsxOpeningElement:
case SyntaxKind.JsxExpression:
case SyntaxKind.NewExpression:
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.PostfixUnaryExpression:
@@ -3012,6 +3013,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
return result;
}
function emitEs6ExportDefaultCompat(node: Node) {
if (node.parent.kind === SyntaxKind.SourceFile) {
Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment);
// only allow export default at a source file level
if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) {
if (!currentSourceFile.symbol.exports["___esModule"]) {
if (languageVersion === ScriptTarget.ES5) {
// default value of configurable, enumerable, writable are `false`.
write("Object.defineProperty(exports, \"__esModule\", { value: true });");
writeLine();
}
else if (languageVersion === ScriptTarget.ES3) {
write("exports.__esModule = true;");
writeLine();
}
}
}
}
}
function emitExportMemberAssignment(node: FunctionLikeDeclaration | ClassDeclaration) {
if (node.flags & NodeFlags.Export) {
writeLine();
@@ -3034,9 +3055,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
else {
if (node.flags & NodeFlags.Default) {
emitEs6ExportDefaultCompat(node);
if (languageVersion === ScriptTarget.ES3) {
write("exports[\"default\"]");
} else {
}
else {
write("exports.default");
}
}
@@ -5407,17 +5430,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
(!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) {
emitLeadingComments(node);
emitStart(node);
if (isES6ExportedDeclaration(node)) {
write("export ");
write("var ");
// variable declaration for import-equals declaration can be hoisted in system modules
// in this case 'var' should be omitted and emit should contain only initialization
let variableDeclarationIsHoisted = shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ true);
// is it top level export import v = a.b.c in system module?
// if yes - it needs to be rewritten as exporter('v', v = a.b.c)
let isExported = isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ true);
if (!variableDeclarationIsHoisted) {
Debug.assert(!isExported);
if (isES6ExportedDeclaration(node)) {
write("export ");
write("var ");
}
else if (!(node.flags & NodeFlags.Export)) {
write("var ");
}
}
else if (!(node.flags & NodeFlags.Export)) {
write("var ");
if (isExported) {
write(`${exportFunctionForFile}("`);
emitNodeWithoutSourceMap(node.name);
write(`", `);
}
emitModuleMemberName(node);
write(" = ");
emit(node.moduleReference);
write(";");
if (isExported) {
write(")");
}
write(";");
emitEnd(node);
emitExportImportAssignments(node);
emitTrailingComments(node);
@@ -5538,6 +5587,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(")");
}
else {
emitEs6ExportDefaultCompat(node);
emitContainingModuleName(node);
if (languageVersion === ScriptTarget.ES3) {
write("[\"default\"] = ");
@@ -5756,6 +5806,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(`function ${exportStarFunction}(m) {`);
increaseIndent();
writeLine();
write(`var exports = {};`);
writeLine();
write(`for(var n in m) {`);
increaseIndent();
writeLine();
@@ -5763,10 +5815,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
if (localNames) {
write(`&& !${localNames}.hasOwnProperty(n)`);
}
write(`) ${exportFunctionForFile}(n, m[n]);`);
write(`) exports[n] = m[n];`);
decreaseIndent();
writeLine();
write("}");
writeLine();
write(`${exportFunctionForFile}(exports);`)
decreaseIndent();
writeLine();
write("}");
@@ -5938,6 +5992,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
return;
}
if (isInternalModuleImportEqualsDeclaration(node)) {
if (!hoistedVars) {
hoistedVars = [];
}
hoistedVars.push(node.name);
return;
}
if (isBindingPattern(node)) {
forEach((<BindingPattern>node).elements, visit);
@@ -6099,16 +6162,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
if ((<ExportDeclaration>importNode).exportClause) {
// export {a, b as c} from 'foo'
// emit as:
// exports('a', _foo["a"])
// exports('c', _foo["b"])
// var reexports = {}
// reexports['a'] = _foo["a"];
// reexports['c'] = _foo["b"];
// exports_(reexports);
let reexportsVariableName = makeUniqueName("reexports");
writeLine();
write(`var ${reexportsVariableName} = {};`)
writeLine();
for (let e of (<ExportDeclaration>importNode).exportClause.elements) {
writeLine();
write(`${exportFunctionForFile}("`);
write(`${reexportsVariableName}["`);
emitNodeWithoutSourceMap(e.name);
write(`", ${parameterName}["`);
write(`"] = ${parameterName}["`);
emitNodeWithoutSourceMap(e.propertyName || e.name);
write(`"]);`);
write(`"];`);
writeLine();
}
write(`${exportFunctionForFile}(${reexportsVariableName});`);
}
else {
writeLine();
@@ -6135,14 +6205,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
writeLine();
for (let i = startIndex; i < node.statements.length; ++i) {
let statement = node.statements[i];
// - imports/exports are not emitted for system modules
// - external module related imports/exports are not emitted for system modules
// - function declarations are not emitted because they were already hoisted
switch (statement.kind) {
case SyntaxKind.ExportDeclaration:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.FunctionDeclaration:
continue;
case SyntaxKind.ImportEqualsDeclaration:
if (!isInternalModuleImportEqualsDeclaration(statement)) {
continue;
}
}
writeLine();
emit(statement);
@@ -6768,6 +6841,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
return leadingComments;
}
/**
* Removes all but the pinned or triple slash comments.
* @param ranges The array to be filtered
* @param onlyPinnedOrTripleSlashComments whether the filtering should be performed.
*/
function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] {
// If we're removing comments, then we want to strip out all but the pinned or
// triple slash comments.

View File

@@ -8,7 +8,7 @@ namespace ts {
/* @internal */ export let ioWriteTime = 0;
/** The version of the TypeScript compiler release */
export const version = "1.5.3";
export const version = "1.6.0";
export function findConfigFile(searchPath: string): string {
let fileName = "tsconfig.json";
@@ -341,7 +341,7 @@ namespace ts {
});
}
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
return runWithCancellationToken(() => {
if (!isDeclarationFile(sourceFile)) {
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
@@ -350,7 +350,7 @@ namespace ts {
return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
}
});
}
}
function getOptionsDiagnostics(): Diagnostic[] {
let allDiagnostics: Diagnostic[] = [];
@@ -602,10 +602,6 @@ namespace ts {
function verifyCompilerOptions() {
if (options.isolatedModules) {
if (options.sourceMap) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules));
}
if (options.declaration) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules));
}

View File

@@ -3,7 +3,7 @@
namespace ts {
export interface SourceFile {
fileWatcher: FileWatcher;
fileWatcher?: FileWatcher;
}
/**

View File

@@ -1404,6 +1404,7 @@ namespace ts {
getPropertyOfType(type: Type, propertyName: string): Symbol;
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
getBaseTypes(type: InterfaceType): ObjectType[];
getReturnTypeOfSignature(signature: Signature): Type;
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
@@ -1762,10 +1763,12 @@ namespace ts {
FromSignature = 0x00040000, // Created for signature assignment check
ObjectLiteral = 0x00080000, // Originates in an object literal
/* @internal */
ContainsUndefinedOrNull = 0x00100000, // Type is or contains Undefined or Null type
FreshObjectLiteral = 0x00100000, // Fresh object literal type
/* @internal */
ContainsObjectLiteral = 0x00200000, // Type is or contains object literal type
ESSymbol = 0x00400000, // Type of symbol primitive introduced in ES6
ContainsUndefinedOrNull = 0x00200000, // Type is or contains Undefined or Null type
/* @internal */
ContainsObjectLiteral = 0x00400000, // Type is or contains object literal type
ESSymbol = 0x00800000, // Type of symbol primitive introduced in ES6
/* @internal */
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
@@ -1774,10 +1777,10 @@ namespace ts {
StringLike = String | StringLiteral,
NumberLike = Number | Enum,
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
UnionOrIntersection = Union | Intersection,
UnionOrIntersection = Union | Intersection,
StructuredType = ObjectType | Union | Intersection,
/* @internal */
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
}
// Properties common to all types
@@ -1806,7 +1809,9 @@ namespace ts {
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none)
localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none)
/* @internal */
resolvedBaseConstructorType?: Type; // Resolved base constructor type of class
/* @internal */
resolvedBaseTypes: ObjectType[]; // Resolved base types
}
@@ -1858,6 +1863,14 @@ namespace ts {
numberIndexType?: Type; // Numeric index type
}
/* @internal */
// Object literals are initially marked fresh. Freshness disappears following an assignment,
// before a type assertion, or when when an object literal's type is widened. The regular
// version of a fresh type is identical except for the TypeFlags.FreshObjectLiteral flag.
export interface FreshObjectLiteralType extends ResolvedType {
regularType: ResolvedType; // Regular version of fresh type
}
// Just a place to cache element types of iterables and iterators
/* @internal */
export interface IterableOrIteratorType extends ObjectType, UnionType {
@@ -2211,6 +2224,7 @@ namespace ts {
export interface CompilerHost {
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getCancellationToken?(): CancellationToken;
getDefaultLibFileName(options: CompilerOptions): string;
writeFile: WriteFileCallback;
getCurrentDirectory(): string;

View File

@@ -965,7 +965,7 @@ namespace ts {
return (<ExternalModuleReference>(<ImportEqualsDeclaration>node).moduleReference).expression;
}
export function isInternalModuleImportEqualsDeclaration(node: Node) {
export function isInternalModuleImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration {
return node.kind === SyntaxKind.ImportEqualsDeclaration && (<ImportEqualsDeclaration>node).moduleReference.kind !== SyntaxKind.ExternalModuleReference;
}

View File

@@ -26,9 +26,8 @@ module FourSlash {
export interface FourSlashFile {
// The contents of the file (with markers, etc stripped out)
content: string;
fileName: string;
version: number;
// File-specific options (name/value pairs)
fileOptions: { [index: string]: string; };
}
@@ -1876,7 +1875,7 @@ module FourSlash {
}
}
private verifyProjectInfo(expected: string[]) {
public verifyProjectInfo(expected: string[]) {
if (this.testType === FourSlashTestType.Server) {
let actual = (<ts.server.SessionClient>this.languageService).getProjectInfo(
this.activeFile.fileName,
@@ -2058,11 +2057,8 @@ module FourSlash {
return result;
}
public verifGetScriptLexicalStructureListContains(
name: string,
kind: string,
markerPosition?: number) {
this.taoInvalidReason = 'verifGetScriptLexicalStructureListContains impossible';
public verifyGetScriptLexicalStructureListContains(name: string, kind: string) {
this.taoInvalidReason = 'verifyGetScriptLexicalStructureListContains impossible';
let items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
@@ -2264,7 +2260,7 @@ module FourSlash {
return 'line ' + (pos.line + 1) + ', col ' + pos.character;
}
private getMarkerByName(markerName: string) {
public getMarkerByName(markerName: string) {
let markerPos = this.testData.markerPositions[markerName];
if (markerPos === undefined) {
let markerNames: string[] = [];
@@ -2739,4 +2735,4 @@ module FourSlash {
fileName: fileName
};
}
}
}

View File

@@ -29,6 +29,7 @@ var Buffer: BufferConstructor = require('buffer').Buffer;
// this will work in the browser via browserify
var _chai: typeof chai = require('chai');
var assert: typeof _chai.assert = _chai.assert;
var expect: typeof _chai.expect = _chai.expect;
declare var __dirname: string; // Node-specific
var global = <any>Function("return this").call(null);

View File

@@ -12,6 +12,7 @@ interface FindFileResult {
}
interface IOLog {
timestamp: string;
arguments: string[];
executingPath: string;
currentDirectory: string;

View File

@@ -1,6 +1,6 @@
/// <reference path="harness.ts" />
class RunnerBase {
abstract class RunnerBase {
constructor() { }
// contains the tests to run
@@ -18,9 +18,7 @@ class RunnerBase {
/** 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 {
throw new Error('method not implemented');
}
public abstract initializeTests(): void;
/** Replaces instances of full paths with fileNames only */
static removeFullPaths(path: string) {

View File

@@ -202,9 +202,7 @@ namespace ts.server {
return {
isMemberCompletion: false,
isNewIdentifierLocation: false,
entries: response.body,
fileName: fileName,
position: position
entries: response.body
};
}

View File

@@ -109,13 +109,13 @@ namespace ts.server {
}
export class Session {
projectService: ProjectService;
pendingOperation = false;
fileHash: ts.Map<number> = {};
nextFileId = 1;
errorTimer: any; /*NodeJS.Timer | number*/
immediateId: any;
changeSeq = 0;
protected projectService: ProjectService;
private pendingOperation = false;
private fileHash: ts.Map<number> = {};
private nextFileId = 1;
private errorTimer: any; /*NodeJS.Timer | number*/
private immediateId: any;
private changeSeq = 0;
constructor(
private host: ServerHost,
@@ -129,7 +129,7 @@ namespace ts.server {
});
}
handleEvent(eventName: string, project: Project, fileName: string) {
private handleEvent(eventName: string, project: Project, fileName: string) {
if (eventName == "context") {
this.projectService.log("got context event, updating diagnostics for" + fileName, "Info");
this.updateErrorCheck([{ fileName, project }], this.changeSeq,
@@ -137,7 +137,7 @@ namespace ts.server {
}
}
logError(err: Error, cmd: string) {
public logError(err: Error, cmd: string) {
var typedErr = <StackTraceError>err;
var msg = "Exception on executing command " + cmd;
if (typedErr.message) {
@@ -149,11 +149,11 @@ namespace ts.server {
this.projectService.log(msg);
}
sendLineToClient(line: string) {
private sendLineToClient(line: string) {
this.host.write(line + this.host.newLine);
}
send(msg: protocol.Message) {
public send(msg: protocol.Message) {
var json = JSON.stringify(msg);
if (this.logger.isVerbose()) {
this.logger.info(msg.type + ": " + json);
@@ -162,7 +162,7 @@ namespace ts.server {
'\r\n\r\n' + json);
}
event(info: any, eventName: string) {
public event(info: any, eventName: string) {
var ev: protocol.Event = {
seq: 0,
type: "event",
@@ -172,7 +172,7 @@ namespace ts.server {
this.send(ev);
}
response(info: any, cmdName: string, reqSeq = 0, errorMsg?: string) {
private response(info: any, cmdName: string, reqSeq = 0, errorMsg?: string) {
var res: protocol.Response = {
seq: 0,
type: "response",
@@ -189,11 +189,11 @@ namespace ts.server {
this.send(res);
}
output(body: any, commandName: string, requestSequence = 0, errorMessage?: string) {
public output(body: any, commandName: string, requestSequence = 0, errorMessage?: string) {
this.response(body, commandName, requestSequence, errorMessage);
}
semanticCheck(file: string, project: Project) {
private semanticCheck(file: string, project: Project) {
try {
var diags = project.compilerService.languageService.getSemanticDiagnostics(file);
@@ -207,7 +207,7 @@ namespace ts.server {
}
}
syntacticCheck(file: string, project: Project) {
private syntacticCheck(file: string, project: Project) {
try {
var diags = project.compilerService.languageService.getSyntacticDiagnostics(file);
if (diags) {
@@ -220,12 +220,12 @@ namespace ts.server {
}
}
errorCheck(file: string, project: Project) {
private errorCheck(file: string, project: Project) {
this.syntacticCheck(file, project);
this.semanticCheck(file, project);
}
updateProjectStructure(seq: number, matchSeq: (seq: number) => boolean, ms = 1500) {
private updateProjectStructure(seq: number, matchSeq: (seq: number) => boolean, ms = 1500) {
setTimeout(() => {
if (matchSeq(seq)) {
this.projectService.updateProjectStructure();
@@ -233,7 +233,7 @@ namespace ts.server {
}, ms);
}
updateErrorCheck(checkList: PendingErrorCheck[], seq: number,
private updateErrorCheck(checkList: PendingErrorCheck[], seq: number,
matchSeq: (seq: number) => boolean, ms = 1500, followMs = 200) {
if (followMs > ms) {
followMs = ms;
@@ -269,7 +269,7 @@ namespace ts.server {
}
}
getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] {
private getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -291,7 +291,7 @@ namespace ts.server {
}));
}
getTypeDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] {
private getTypeDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -313,7 +313,7 @@ namespace ts.server {
}));
}
getOccurrences(line: number, offset: number, fileName: string): protocol.OccurrencesResponseItem[]{
private getOccurrences(line: number, offset: number, fileName: string): protocol.OccurrencesResponseItem[]{
fileName = ts.normalizePath(fileName);
let project = this.projectService.getProjectForFile(fileName);
@@ -343,7 +343,7 @@ namespace ts.server {
});
}
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
private getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
fileName = ts.normalizePath(fileName)
let project = this.projectService.getProjectForFile(fileName)
@@ -358,7 +358,7 @@ namespace ts.server {
return projectInfo;
}
getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody {
private getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -426,7 +426,7 @@ namespace ts.server {
return { info: renameInfo, locs: bakedRenameLocs };
}
getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody {
private getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody {
// TODO: get all projects for this file; report refs for all projects deleting duplicates
// can avoid duplicates by eliminating same ref file from subsequent projects
var file = ts.normalizePath(fileName);
@@ -473,12 +473,12 @@ namespace ts.server {
};
}
openClientFile(fileName: string) {
private openClientFile(fileName: string) {
var file = ts.normalizePath(fileName);
this.projectService.openClientFile(file);
}
getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
private getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -504,7 +504,7 @@ namespace ts.server {
};
}
getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] {
private getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -531,7 +531,7 @@ namespace ts.server {
});
}
getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] {
private getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
@@ -607,7 +607,7 @@ namespace ts.server {
});
}
getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] {
private getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] {
if (!prefix) {
prefix = "";
}
@@ -633,7 +633,7 @@ namespace ts.server {
}, []).sort((a, b) => a.name.localeCompare(b.name));
}
getCompletionEntryDetails(line: number, offset: number,
private getCompletionEntryDetails(line: number, offset: number,
entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
@@ -653,7 +653,7 @@ namespace ts.server {
}, []);
}
getSignatureHelpItems(line: number, offset: number, fileName: string): protocol.SignatureHelpItems {
private getSignatureHelpItems(line: number, offset: number, fileName: string): protocol.SignatureHelpItems {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -682,7 +682,7 @@ namespace ts.server {
return result;
}
getDiagnostics(delay: number, fileNames: string[]) {
private getDiagnostics(delay: number, fileNames: string[]) {
var checkList = fileNames.reduce((accum: PendingErrorCheck[], fileName: string) => {
fileName = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(fileName);
@@ -697,7 +697,7 @@ namespace ts.server {
}
}
change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) {
private change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (project) {
@@ -712,7 +712,7 @@ namespace ts.server {
}
}
reload(fileName: string, tempFileName: string, reqSeq = 0) {
private reload(fileName: string, tempFileName: string, reqSeq = 0) {
var file = ts.normalizePath(fileName);
var tmpfile = ts.normalizePath(tempFileName);
var project = this.projectService.getProjectForFile(file);
@@ -725,7 +725,7 @@ namespace ts.server {
}
}
saveToTmp(fileName: string, tempFileName: string) {
private saveToTmp(fileName: string, tempFileName: string) {
var file = ts.normalizePath(fileName);
var tmpfile = ts.normalizePath(tempFileName);
@@ -735,12 +735,12 @@ namespace ts.server {
}
}
closeClientFile(fileName: string) {
private closeClientFile(fileName: string) {
var file = ts.normalizePath(fileName);
this.projectService.closeClientFile(file);
}
decorateNavigationBarItem(project: Project, fileName: string, items: ts.NavigationBarItem[]): protocol.NavigationBarItem[] {
private decorateNavigationBarItem(project: Project, fileName: string, items: ts.NavigationBarItem[]): protocol.NavigationBarItem[] {
if (!items) {
return undefined;
}
@@ -759,7 +759,7 @@ namespace ts.server {
}));
}
getNavigationBarItems(fileName: string): protocol.NavigationBarItem[] {
private getNavigationBarItems(fileName: string): protocol.NavigationBarItem[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -775,7 +775,7 @@ namespace ts.server {
return this.decorateNavigationBarItem(project, fileName, items);
}
getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] {
private getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
if (!project) {
@@ -814,7 +814,7 @@ namespace ts.server {
});
}
getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] {
private getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] {
var file = ts.normalizePath(fileName);
var project = this.projectService.getProjectForFile(file);
@@ -836,7 +836,7 @@ namespace ts.server {
}));
}
exit() {
public exit() {
}
private handlers : Map<(request: protocol.Request) => {response?: any, responseRequired?: boolean}> = {
@@ -942,14 +942,14 @@ namespace ts.server {
return {response: this.getProjectInfo(file, needFileNameList), responseRequired: true};
},
};
addProtocolHandler(command: string, handler: (request: protocol.Request) => {response?: any, responseRequired: boolean}) {
public addProtocolHandler(command: string, handler: (request: protocol.Request) => {response?: any, responseRequired: boolean}) {
if (this.handlers[command]) {
throw new Error(`Protocol handler already exists for command "${command}"`);
}
this.handlers[command] = handler;
}
executeCommand(request: protocol.Request) : {response?: any, responseRequired?: boolean} {
public executeCommand(request: protocol.Request) : {response?: any, responseRequired?: boolean} {
var handler = this.handlers[request.command];
if (handler) {
return handler(request);
@@ -960,7 +960,7 @@ namespace ts.server {
}
}
onMessage(message: string) {
public onMessage(message: string) {
if (this.logger.isVerbose()) {
this.logger.info("request: " + message);
var start = this.hrtime();

View File

@@ -48,6 +48,7 @@ namespace ts {
getConstructSignatures(): Signature[];
getStringIndexType(): Type;
getNumberIndexType(): Type;
getBaseTypes(): ObjectType[]
}
export interface Signature {
@@ -260,26 +261,25 @@ namespace ts {
}
public getFirstToken(sourceFile?: SourceFile): Node {
let children = this.getChildren();
for (let child of children) {
if (child.kind < SyntaxKind.FirstNode) {
return child;
}
return child.getFirstToken(sourceFile);
let children = this.getChildren(sourceFile);
if (!children.length) {
return undefined;
}
let child = children[0];
return child.kind < SyntaxKind.FirstNode ? child : child.getFirstToken(sourceFile);
}
public getLastToken(sourceFile?: SourceFile): Node {
let children = this.getChildren(sourceFile);
for (let i = children.length - 1; i >= 0; i--) {
let child = children[i];
if (child.kind < SyntaxKind.FirstNode) {
return child;
}
return child.getLastToken(sourceFile);
let child = lastOrUndefined(children);
if (!child) {
return undefined;
}
return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile);
}
}
@@ -682,6 +682,11 @@ namespace ts {
getNumberIndexType(): Type {
return this.checker.getIndexTypeOfType(this, IndexKind.Number);
}
getBaseTypes(): ObjectType[] {
return this.flags & (TypeFlags.Class | TypeFlags.Interface)
? this.checker.getBaseTypes(<TypeObject & InterfaceType>this)
: undefined;
}
}
class SignatureObject implements Signature {
@@ -1105,6 +1110,7 @@ namespace ts {
}
export interface HighlightSpan {
fileName?: string;
textSpan: TextSpan;
kind: string;
}
@@ -1411,7 +1417,9 @@ namespace ts {
* @param fileName The name of the file to be released
* @param compilationSettings The compilation settings used to acquire the file
*/
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void
releaseDocument(fileName: string, compilationSettings: CompilerOptions): void;
reportStats(): string;
}
// TODO: move these to enums
@@ -1751,18 +1759,31 @@ namespace ts {
sourceFile.version = version;
sourceFile.scriptSnapshot = scriptSnapshot;
}
export interface TranspileOptions {
compilerOptions?: CompilerOptions;
fileName?: string;
reportDiagnostics?: boolean;
moduleName?: string;
}
export interface TranspileOutput {
outputText: string;
diagnostics?: Diagnostic[];
sourceMapText?: string;
}
/*
* This function will compile source text from 'input' argument using specified compiler options.
* If not options are provided - it will use a set of default compiler options.
* Extra compiler options that will unconditionally be used bu this function are:
* Extra compiler options that will unconditionally be used by this function are:
* - isolatedModules = true
* - allowNonTsExtensions = true
* - noLib = true
* - noResolve = true
*/
export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string {
let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions();
*/
export function transpileModule(input: string, transpileOptions?: TranspileOptions): TranspileOutput {
let options = transpileOptions.compilerOptions ? clone(transpileOptions.compilerOptions) : getDefaultCompilerOptions();
options.isolatedModules = true;
@@ -1778,23 +1799,30 @@ namespace ts {
options.noResolve = true;
// Parse
let inputFileName = fileName || "module.ts";
let inputFileName = transpileOptions.fileName || "module.ts";
let sourceFile = createSourceFile(inputFileName, input, options.target);
if (moduleName) {
sourceFile.moduleName = moduleName;
if (transpileOptions.moduleName) {
sourceFile.moduleName = transpileOptions.moduleName;
}
let newLine = getNewLineCharacter(options);
// Output
let outputText: string;
let sourceMapText: string;
// Create a compilerHost object to allow the compiler to read and write files
let compilerHost: CompilerHost = {
getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined,
writeFile: (name, text, writeByteOrderMark) => {
Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name);
outputText = text;
if (fileExtensionIs(name, ".map")) {
Debug.assert(sourceMapText === undefined, `Unexpected multiple source map outputs for the file '${name}'`);
sourceMapText = text;
}
else {
Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name);
outputText = text;
}
},
getDefaultLibFileName: () => "lib.d.ts",
useCaseSensitiveFileNames: () => false,
@@ -1804,16 +1832,29 @@ namespace ts {
};
let program = createProgram([inputFileName], options, compilerHost);
addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics());
let diagnostics: Diagnostic[];
if (transpileOptions.reportDiagnostics) {
diagnostics = [];
addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics());
}
// Emit
program.emit();
Debug.assert(outputText !== undefined, "Output generation failed");
return outputText;
return { outputText, diagnostics, sourceMapText };
}
/*
* This is a shortcut function for transpileModule - it accepts transpileOptions as parameters and returns only outputText part of the result.
*/
export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string {
let output = transpileModule(input, { compilerOptions, fileName, reportDiagnostics: !!diagnostics, moduleName });
// addRange correctly handles cases when wither 'from' or 'to' argument is missing
addRange(diagnostics, output.diagnostics);
return output.outputText;
}
export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile {

View File

@@ -454,11 +454,11 @@ namespace ts {
}
}
export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; } []{
export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; code: number; } []{
return diagnostics.map(d => realizeDiagnostic(d, newLine));
}
function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } {
function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; code: number; } {
return {
message: flattenDiagnosticMessageText(diagnostic.messageText, newLine),
start: diagnostic.start,

View File

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

View File

@@ -1,4 +1,4 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'.
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'number | string' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
@@ -7,5 +7,5 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6)
var v: string;
for (v of union) { }
~
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number | string' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.

View File

@@ -3,6 +3,6 @@ var union: string | number[];
>union : string | number[]
for (var v of union) { }
>v : string | number
>v : number | string
>union : string | number[]

View File

@@ -1,8 +1,8 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'number | symbol | string[]' is not an array type.
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'string[] | number | symbol' is not an array type.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts (1 errors) ====
var union: string | string[] | number | symbol;
for (let v of union) { }
~~~~~
!!! error TS2461: Type 'number | symbol | string[]' is not an array type.
!!! error TS2461: Type 'string[] | number | symbol' is not an array type.

View File

@@ -6,14 +6,14 @@ enum Color { R, G, B }
>B : Color
function f1(x: Color | string) {
>f1 : (x: string | Color) => void
>x : string | Color
>f1 : (x: Color | string) => void
>x : Color | string
>Color : Color
if (typeof x === "number") {
>typeof x === "number" : boolean
>typeof x : string
>x : string | Color
>x : Color | string
>"number" : string
var y = x;
@@ -35,14 +35,14 @@ function f1(x: Color | string) {
}
function f2(x: Color | string | string[]) {
>f2 : (x: string | Color | string[]) => void
>x : string | Color | string[]
>f2 : (x: Color | string | string[]) => void
>x : Color | string | string[]
>Color : Color
if (typeof x === "object") {
>typeof x === "object" : boolean
>typeof x : string
>x : string | Color | string[]
>x : Color | string | string[]
>"object" : string
var y = x;
@@ -55,7 +55,7 @@ function f2(x: Color | string | string[]) {
if (typeof x === "number") {
>typeof x === "number" : boolean
>typeof x : string
>x : string | Color | string[]
>x : Color | string | string[]
>"number" : string
var z = x;
@@ -77,7 +77,7 @@ function f2(x: Color | string | string[]) {
if (typeof x === "string") {
>typeof x === "string" : boolean
>typeof x : string
>x : string | Color | string[]
>x : Color | string | string[]
>"string" : string
var a = x;

View File

@@ -34,7 +34,7 @@ var d2: IHasVisualizationModel = i || moduleA;
var d2: IHasVisualizationModel = moduleA || i;
>d2 : IHasVisualizationModel
>IHasVisualizationModel : IHasVisualizationModel
>moduleA || i : IHasVisualizationModel
>moduleA || i : typeof moduleA
>moduleA : typeof moduleA
>i : IHasVisualizationModel

View File

@@ -0,0 +1,22 @@
tests/cases/compiler/aliasesInSystemModule1.ts(2,24): error TS2307: Cannot find module 'foo'.
==== tests/cases/compiler/aliasesInSystemModule1.ts (1 errors) ====
import alias = require('foo');
~~~~~
!!! error TS2307: Cannot find module 'foo'.
import cls = alias.Class;
export import cls2 = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
module M {
export import cls = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
}

View File

@@ -0,0 +1,42 @@
//// [aliasesInSystemModule1.ts]
import alias = require('foo');
import cls = alias.Class;
export import cls2 = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
module M {
export import cls = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
}
//// [aliasesInSystemModule1.js]
System.register(['foo'], function(exports_1) {
var alias;
var cls, cls2, x, y, z, M;
return {
setters:[
function (_alias) {
alias = _alias;
}],
execute: function() {
cls = alias.Class;
exports_1("cls2", cls2 = alias.Class);
x = new alias.Class();
y = new cls();
z = new cls2();
(function (M) {
M.cls = alias.Class;
var x = new alias.Class();
var y = new M.cls();
var z = new cls2();
})(M || (M = {}));
}
}
});

View File

@@ -0,0 +1,21 @@
tests/cases/compiler/aliasesInSystemModule2.ts(2,21): error TS2307: Cannot find module 'foo'.
==== tests/cases/compiler/aliasesInSystemModule2.ts (1 errors) ====
import {alias} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.
import cls = alias.Class;
export import cls2 = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
module M {
export import cls = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
}

View File

@@ -0,0 +1,41 @@
//// [aliasesInSystemModule2.ts]
import {alias} from "foo";
import cls = alias.Class;
export import cls2 = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
module M {
export import cls = alias.Class;
let x = new alias.Class();
let y = new cls();
let z = new cls2();
}
//// [aliasesInSystemModule2.js]
System.register(["foo"], function(exports_1) {
var foo_1;
var cls, cls2, x, y, z, M;
return {
setters:[
function (_foo_1) {
foo_1 = _foo_1;
}],
execute: function() {
cls = foo_1.alias.Class;
exports_1("cls2", cls2 = foo_1.alias.Class);
x = new foo_1.alias.Class();
y = new cls();
z = new cls2();
(function (M) {
M.cls = foo_1.alias.Class;
var x = new foo_1.alias.Class();
var y = new M.cls();
var z = new cls2();
})(M || (M = {}));
}
}
});

View File

@@ -294,8 +294,8 @@ module EmptyTypes {
// 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; }[]
>a1 : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[]
>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>0 : number
@@ -313,8 +313,8 @@ module EmptyTypes {
>'a' : 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; }[]
>a2 : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[]
>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[]
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
@@ -332,8 +332,8 @@ module EmptyTypes {
>'a' : 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; }[]
>a3 : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[]
>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>0 : number
@@ -366,22 +366,22 @@ module EmptyTypes {
>base2 : typeof base2
var b1 = [baseObj, base2Obj, ifaceObj];
>b1 : iface[]
>[baseObj, base2Obj, ifaceObj] : iface[]
>b1 : base[]
>[baseObj, base2Obj, ifaceObj] : base[]
>baseObj : base
>base2Obj : base2
>ifaceObj : iface
var b2 = [base2Obj, baseObj, ifaceObj];
>b2 : iface[]
>[base2Obj, baseObj, ifaceObj] : iface[]
>b2 : base2[]
>[base2Obj, baseObj, ifaceObj] : base2[]
>base2Obj : base2
>baseObj : base
>ifaceObj : iface
var b3 = [baseObj, ifaceObj, base2Obj];
>b3 : iface[]
>[baseObj, ifaceObj, base2Obj] : iface[]
>b3 : base[]
>[baseObj, ifaceObj, base2Obj] : base[]
>baseObj : base
>ifaceObj : iface
>base2Obj : base2
@@ -639,7 +639,7 @@ module NonEmptyTypes {
>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: number; y: base; })[]
>{ x: 7, y: new derived() } : { x: number; y: derived; }
>x : number
>7 : number
@@ -658,7 +658,7 @@ module NonEmptyTypes {
>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: boolean; y: base; })[]
>{ x: true, y: new derived() } : { x: boolean; y: derived; }
>x : boolean
>true : boolean
@@ -697,8 +697,8 @@ module NonEmptyTypes {
// 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; }[]
>a1 : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[]
>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>0 : number
@@ -716,8 +716,8 @@ module NonEmptyTypes {
>'a' : 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; }[]
>a2 : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[]
>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[]
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
@@ -735,8 +735,8 @@ module NonEmptyTypes {
>'a' : 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; }[]
>a3 : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[]
>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>0 : number
@@ -769,29 +769,29 @@ module NonEmptyTypes {
>base2 : typeof base2
var b1 = [baseObj, base2Obj, ifaceObj];
>b1 : iface[]
>[baseObj, base2Obj, ifaceObj] : iface[]
>b1 : (base | base2 | iface)[]
>[baseObj, base2Obj, ifaceObj] : (base | base2 | iface)[]
>baseObj : base
>base2Obj : base2
>ifaceObj : iface
var b2 = [base2Obj, baseObj, ifaceObj];
>b2 : iface[]
>[base2Obj, baseObj, ifaceObj] : iface[]
>b2 : (base2 | base | iface)[]
>[base2Obj, baseObj, ifaceObj] : (base2 | base | iface)[]
>base2Obj : base2
>baseObj : base
>ifaceObj : iface
var b3 = [baseObj, ifaceObj, base2Obj];
>b3 : iface[]
>[baseObj, ifaceObj, base2Obj] : iface[]
>b3 : (base | iface | base2)[]
>[baseObj, ifaceObj, base2Obj] : (base | iface | base2)[]
>baseObj : base
>ifaceObj : iface
>base2Obj : base2
var b4 = [ifaceObj, baseObj, base2Obj];
>b4 : iface[]
>[ifaceObj, baseObj, base2Obj] : iface[]
>b4 : (iface | base | base2)[]
>[ifaceObj, baseObj, base2Obj] : (iface | base | base2)[]
>ifaceObj : iface
>baseObj : base
>base2Obj : base2

View File

@@ -1,6 +1,6 @@
tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
Property 'id' is missing in type '{ foo: string; }'.
Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.
==== tests/cases/compiler/arrayCast.ts (1 errors) ====
@@ -10,7 +10,7 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
!!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
!!! error TS2352: Property 'id' is missing in type '{ foo: string; }'.
!!! error TS2352: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.
// Should succeed, as the {} element causes the type of the array to be {}[]
<{ id: number; }[]>[{ foo: "s" }, {}];

View File

@@ -1,7 +1,7 @@
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, 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 '() => number | string' is not assignable to type '() => number'.
Type 'number | string' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
Property '0' is missing in type 'number[]'.
@@ -19,8 +19,8 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte
~~~~
!!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, 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 '() => number | string' is not assignable to type '() => number'.
!!! error TS2322: Type 'number | string' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
// In a contextually typed array literal expression containing one or more spread elements,

View File

@@ -0,0 +1,72 @@
tests/cases/compiler/arrayLiteralTypeInference.ts(13,5): error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type 'Action[]'.
Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type 'Action'.
Type '{ id: number; trueness: boolean; }' is not assignable to type 'Action'.
Object literal may only specify known properties, and 'trueness' does not exist in type 'Action'.
tests/cases/compiler/arrayLiteralTypeInference.ts(29,5): error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'.
Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'.
Type '{ id: number; trueness: boolean; }' is not assignable to type '{ id: number; }'.
Object literal may only specify known properties, and 'trueness' does not exist in type '{ id: number; }'.
==== tests/cases/compiler/arrayLiteralTypeInference.ts (2 errors) ====
class Action {
id: number;
}
class ActionA extends Action {
value: string;
}
class ActionB extends Action {
trueNess: boolean;
}
var x1: Action[] = [
~~
!!! error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type 'Action[]'.
!!! error TS2322: Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type 'Action'.
!!! error TS2322: Type '{ id: number; trueness: boolean; }' is not assignable to type 'Action'.
!!! error TS2322: Object literal may only specify known properties, and 'trueness' does not exist in type 'Action'.
{ id: 2, trueness: false },
{ id: 3, name: "three" }
]
var x2: Action[] = [
new ActionA(),
new ActionB()
]
var x3: Action[] = [
new Action(),
new ActionA(),
new ActionB()
]
var z1: { id: number }[] =
~~
!!! error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'.
!!! error TS2322: Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'.
!!! error TS2322: Type '{ id: number; trueness: boolean; }' is not assignable to type '{ id: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'trueness' does not exist in type '{ id: number; }'.
[
{ id: 2, trueness: false },
{ id: 3, name: "three" }
]
var z2: { id: number }[] =
[
new ActionA(),
new ActionB()
]
var z3: { id: number }[] =
[
new Action(),
new ActionA(),
new ActionB()
]

View File

@@ -1,113 +0,0 @@
=== tests/cases/compiler/arrayLiteralTypeInference.ts ===
class Action {
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
id: number;
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 0, 14))
}
class ActionA extends Action {
>ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1))
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
value: string;
>value : Symbol(value, Decl(arrayLiteralTypeInference.ts, 4, 30))
}
class ActionB extends Action {
>ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1))
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
trueNess: boolean;
>trueNess : Symbol(trueNess, Decl(arrayLiteralTypeInference.ts, 8, 30))
}
var x1: Action[] = [
>x1 : Symbol(x1, Decl(arrayLiteralTypeInference.ts, 12, 3))
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
{ id: 2, trueness: false },
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 13, 5))
>trueness : Symbol(trueness, Decl(arrayLiteralTypeInference.ts, 13, 12))
{ id: 3, name: "three" }
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 14, 5))
>name : Symbol(name, Decl(arrayLiteralTypeInference.ts, 14, 12))
]
var x2: Action[] = [
>x2 : Symbol(x2, Decl(arrayLiteralTypeInference.ts, 17, 3))
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
new ActionA(),
>ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1))
new ActionB()
>ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1))
]
var x3: Action[] = [
>x3 : Symbol(x3, Decl(arrayLiteralTypeInference.ts, 22, 3))
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
new Action(),
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
new ActionA(),
>ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1))
new ActionB()
>ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1))
]
var z1: { id: number }[] =
>z1 : Symbol(z1, Decl(arrayLiteralTypeInference.ts, 28, 3))
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 28, 9))
[
{ id: 2, trueness: false },
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 30, 9))
>trueness : Symbol(trueness, Decl(arrayLiteralTypeInference.ts, 30, 16))
{ id: 3, name: "three" }
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 31, 9))
>name : Symbol(name, Decl(arrayLiteralTypeInference.ts, 31, 16))
]
var z2: { id: number }[] =
>z2 : Symbol(z2, Decl(arrayLiteralTypeInference.ts, 34, 3))
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 34, 9))
[
new ActionA(),
>ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1))
new ActionB()
>ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1))
]
var z3: { id: number }[] =
>z3 : Symbol(z3, Decl(arrayLiteralTypeInference.ts, 40, 3))
>id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 40, 9))
[
new Action(),
>Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0))
new ActionA(),
>ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1))
new ActionB()
>ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1))
]

View File

@@ -1,144 +0,0 @@
=== tests/cases/compiler/arrayLiteralTypeInference.ts ===
class Action {
>Action : Action
id: number;
>id : number
}
class ActionA extends Action {
>ActionA : ActionA
>Action : Action
value: string;
>value : string
}
class ActionB extends Action {
>ActionB : ActionB
>Action : Action
trueNess: boolean;
>trueNess : boolean
}
var x1: Action[] = [
>x1 : Action[]
>Action : 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; }
>id : number
>2 : number
>trueness : boolean
>false : boolean
{ id: 3, name: "three" }
>{ id: 3, name: "three" } : { id: number; name: string; }
>id : number
>3 : number
>name : string
>"three" : string
]
var x2: Action[] = [
>x2 : Action[]
>Action : Action
>[ new ActionA(), new ActionB()] : (ActionA | ActionB)[]
new ActionA(),
>new ActionA() : ActionA
>ActionA : typeof ActionA
new ActionB()
>new ActionB() : ActionB
>ActionB : typeof ActionB
]
var x3: Action[] = [
>x3 : Action[]
>Action : Action
>[ new Action(), new ActionA(), new ActionB()] : Action[]
new Action(),
>new Action() : Action
>Action : typeof Action
new ActionA(),
>new ActionA() : ActionA
>ActionA : typeof ActionA
new ActionB()
>new ActionB() : ActionB
>ActionB : typeof ActionB
]
var z1: { id: number }[] =
>z1 : { id: number; }[]
>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; }
>id : number
>2 : number
>trueness : boolean
>false : boolean
{ id: 3, name: "three" }
>{ id: 3, name: "three" } : { id: number; name: string; }
>id : number
>3 : number
>name : string
>"three" : string
]
var z2: { id: number }[] =
>z2 : { id: number; }[]
>id : number
[
>[ new ActionA(), new ActionB() ] : (ActionA | ActionB)[]
new ActionA(),
>new ActionA() : ActionA
>ActionA : typeof ActionA
new ActionB()
>new ActionB() : ActionB
>ActionB : typeof ActionB
]
var z3: { id: number }[] =
>z3 : { id: number; }[]
>id : number
[
>[ new Action(), new ActionA(), new ActionB() ] : Action[]
new Action(),
>new Action() : Action
>Action : typeof Action
new ActionA(),
>new ActionA() : ActionA
>ActionA : typeof ActionA
new ActionB()
>new ActionB() : ActionB
>ActionB : typeof ActionB
]

View File

@@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[]
>b : { x: number; z?: number; }
var bs = [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; })[]
>bs : ({ x: number; z?: number; } | { x: number; y?: number; })[]
>[b, a] : ({ x: number; z?: number; } | { x: number; y?: number; })[]
>b : { x: number; z?: number; }
>a : { x: number; y?: number; }
@@ -36,8 +36,8 @@ var cs = [a, b, c]; // { x: number; y?: 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: string) => number))[]
>[(x: Object) => 1, (x: string) => 2] : (((x: Object) => number) | ((x: string) => number))[]
>(x: Object) => 1 : (x: Object) => number
>x : Object
>Object : Object
@@ -47,8 +47,8 @@ var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[]
>2 : number
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: Object) => number))[]
>[(x: string) => 2, (x: Object) => 1] : (((x: string) => number) | ((x: Object) => number))[]
>(x: string) => 2 : (x: string) => number
>x : string
>2 : number

View File

@@ -0,0 +1,50 @@
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(24,5): error TS2322: Type '({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]' is not assignable to type '{ [n: number]: { a: string; b: number; }; }'.
Index signatures are incompatible.
Type '{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'.
Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'.
Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'.
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts (1 errors) ====
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
var arr2 = [[null], [1], ['']];
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
var stringArr = ['', ""];
var numberArr = [0, 0.0, 0x00, 1e1];
var boolArr = [false, true, false, true];
class C { private p; }
var classArr = [new C(), new C()];
var classTypeArray = [C, C, C];
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 }];
~~~~~~~~
!!! error TS2322: Type '({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]' is not assignable to type '{ [n: number]: { a: string; b: number; }; }'.
!!! error TS2322: Index signatures are incompatible.
!!! error TS2322: Type '{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'.
!!! error TS2322: Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'.
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
class Derived1 extends Base { private m };
class Derived2 extends Base { private n };
var context3: Base[] = [new Derived1(), new Derived2()];
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
var context4: Base[] = [new Derived1(), new Derived1()];

View File

@@ -1,94 +0,0 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts ===
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
>arr1 : Symbol(arr1, Decl(arrayLiterals.ts, 2, 3))
var arr2 = [[null], [1], ['']];
>arr2 : Symbol(arr2, Decl(arrayLiterals.ts, 4, 3))
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
>stringArrArr : Symbol(stringArrArr, Decl(arrayLiterals.ts, 8, 3))
var stringArr = ['', ""];
>stringArr : Symbol(stringArr, Decl(arrayLiterals.ts, 10, 3))
var numberArr = [0, 0.0, 0x00, 1e1];
>numberArr : Symbol(numberArr, Decl(arrayLiterals.ts, 12, 3))
var boolArr = [false, true, false, true];
>boolArr : Symbol(boolArr, Decl(arrayLiterals.ts, 14, 3))
class C { private p; }
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
>p : Symbol(p, Decl(arrayLiterals.ts, 16, 9))
var classArr = [new C(), new C()];
>classArr : Symbol(classArr, Decl(arrayLiterals.ts, 17, 3))
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
var classTypeArray = [C, C, C];
>classTypeArray : Symbol(classTypeArray, Decl(arrayLiterals.ts, 19, 3), Decl(arrayLiterals.ts, 20, 3))
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
>classTypeArray : Symbol(classTypeArray, Decl(arrayLiterals.ts, 19, 3), Decl(arrayLiterals.ts, 20, 3))
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
>C : Symbol(C, Decl(arrayLiterals.ts, 14, 41))
// 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 }];
>context1 : Symbol(context1, Decl(arrayLiterals.ts, 23, 3))
>n : Symbol(n, Decl(arrayLiterals.ts, 23, 17))
>a : Symbol(a, Decl(arrayLiterals.ts, 23, 30))
>b : Symbol(b, Decl(arrayLiterals.ts, 23, 41))
>a : Symbol(a, Decl(arrayLiterals.ts, 23, 62))
>b : Symbol(b, Decl(arrayLiterals.ts, 23, 69))
>c : Symbol(c, Decl(arrayLiterals.ts, 23, 75))
>a : Symbol(a, Decl(arrayLiterals.ts, 23, 86))
>b : Symbol(b, Decl(arrayLiterals.ts, 23, 93))
>c : Symbol(c, Decl(arrayLiterals.ts, 23, 99))
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
>context2 : Symbol(context2, Decl(arrayLiterals.ts, 24, 3))
>a : Symbol(a, Decl(arrayLiterals.ts, 24, 17))
>b : Symbol(b, Decl(arrayLiterals.ts, 24, 24))
>c : Symbol(c, Decl(arrayLiterals.ts, 24, 30))
>a : Symbol(a, Decl(arrayLiterals.ts, 24, 41))
>b : Symbol(b, Decl(arrayLiterals.ts, 24, 48))
>c : Symbol(c, Decl(arrayLiterals.ts, 24, 54))
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
>Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
>p : Symbol(p, Decl(arrayLiterals.ts, 27, 12))
class Derived1 extends Base { private m };
>Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
>Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
>m : Symbol(m, Decl(arrayLiterals.ts, 28, 29))
class Derived2 extends Base { private n };
>Derived2 : Symbol(Derived2, Decl(arrayLiterals.ts, 28, 42))
>Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
>n : Symbol(n, Decl(arrayLiterals.ts, 29, 29))
var context3: Base[] = [new Derived1(), new Derived2()];
>context3 : Symbol(context3, Decl(arrayLiterals.ts, 30, 3))
>Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
>Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
>Derived2 : Symbol(Derived2, Decl(arrayLiterals.ts, 28, 42))
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
var context4: Base[] = [new Derived1(), new Derived1()];
>context4 : Symbol(context4, Decl(arrayLiterals.ts, 33, 3))
>Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63))
>Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))
>Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25))

View File

@@ -1,153 +0,0 @@
=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts ===
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
>arr1 : (number[] | string[])[]
>[[], [1], ['']] : (number[] | string[])[]
>[] : undefined[]
>[1] : number[]
>1 : number
>[''] : string[]
>'' : string
var arr2 = [[null], [1], ['']];
>arr2 : (number[] | string[])[]
>[[null], [1], ['']] : (number[] | string[])[]
>[null] : null[]
>null : null
>[1] : number[]
>1 : number
>[''] : string[]
>'' : string
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
>stringArrArr : string[][]
>[[''], [""]] : string[][]
>[''] : string[]
>'' : string
>[""] : string[]
>"" : string
var stringArr = ['', ""];
>stringArr : string[]
>['', ""] : string[]
>'' : string
>"" : string
var numberArr = [0, 0.0, 0x00, 1e1];
>numberArr : number[]
>[0, 0.0, 0x00, 1e1] : number[]
>0 : number
>0.0 : number
>0x00 : number
>1e1 : number
var boolArr = [false, true, false, true];
>boolArr : boolean[]
>[false, true, false, true] : boolean[]
>false : boolean
>true : boolean
>false : boolean
>true : boolean
class C { private p; }
>C : C
>p : any
var classArr = [new C(), new C()];
>classArr : C[]
>[new C(), new C()] : C[]
>new C() : C
>C : typeof C
>new C() : C
>C : typeof C
var classTypeArray = [C, C, C];
>classTypeArray : typeof C[]
>[C, C, C] : typeof C[]
>C : typeof C
>C : typeof C
>C : typeof C
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
>classTypeArray : typeof C[]
>Array : T[]
>C : typeof C
// 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 }];
>context1 : { [n: number]: { a: string; b: number; }; }
>n : number
>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
>'' : string
>b : number
>0 : number
>c : string
>'' : string
>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
>a : string
>"" : string
>b : number
>3 : number
>c : number
>0 : number
var 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
>'' : string
>b : number
>0 : number
>c : string
>'' : string
>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; }
>a : string
>"" : string
>b : number
>3 : number
>c : number
>0 : number
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
>Base : Base
>p : any
class Derived1 extends Base { private m };
>Derived1 : Derived1
>Base : Base
>m : any
class Derived2 extends Base { private n };
>Derived2 : Derived2
>Base : Base
>n : any
var context3: Base[] = [new Derived1(), new Derived2()];
>context3 : Base[]
>Base : Base
>[new Derived1(), new Derived2()] : (Derived1 | Derived2)[]
>new Derived1() : Derived1
>Derived1 : typeof Derived1
>new Derived2() : Derived2
>Derived2 : typeof Derived2
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
var context4: Base[] = [new Derived1(), new Derived1()];
>context4 : Base[]
>Base : Base
>[new Derived1(), new Derived1()] : Derived1[]
>new Derived1() : Derived1
>Derived1 : typeof Derived1
>new Derived1() : Derived1
>Derived1 : typeof Derived1

View File

@@ -24,8 +24,8 @@ var a1 = ["hello", "world"]
>"world" : string
var a2 = [, , , ...a0, "hello"];
>a2 : (string | number)[]
>[, , , ...a0, "hello"] : (string | number)[]
>a2 : (number | string)[]
>[, , , ...a0, "hello"] : (number | string)[]
> : undefined
> : undefined
> : undefined
@@ -151,8 +151,8 @@ interface myArray2 extends Array<Number|String> { }
>String : String
var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[]
>d0 : (string | number | boolean)[]
>[1, true, ...temp,] : (string | number | boolean)[]
>d0 : (number | boolean | string)[]
>[1, true, ...temp,] : (number | boolean | string)[]
>1 : number
>true : boolean
>...temp : string
@@ -214,8 +214,8 @@ var d8: number[][] = [[...temp1]]
>temp1 : number[]
var d9 = [[...temp1], ...["hello"]];
>d9 : (string | number[])[]
>[[...temp1], ...["hello"]] : (string | number[])[]
>d9 : (number[] | string)[]
>[[...temp1], ...["hello"]] : (number[] | string)[]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]

View File

@@ -24,8 +24,8 @@ var a1 = ["hello", "world"]
>"world" : string
var a2 = [, , , ...a0, "hello"];
>a2 : (string | number)[]
>[, , , ...a0, "hello"] : (string | number)[]
>a2 : (number | string)[]
>[, , , ...a0, "hello"] : (number | string)[]
> : undefined
> : undefined
> : undefined
@@ -140,8 +140,8 @@ interface myArray2 extends Array<Number|String> { }
>String : String
var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[]
>d0 : (string | number | boolean)[]
>[1, true, ...temp, ] : (string | number | boolean)[]
>d0 : (number | boolean | string)[]
>[1, true, ...temp, ] : (number | boolean | string)[]
>1 : number
>true : boolean
>...temp : string
@@ -176,10 +176,10 @@ var d4: myArray2 = [...temp, ...temp1];
>temp1 : number[]
var d5 = [...a2];
>d5 : (string | number)[]
>[...a2] : (string | number)[]
>...a2 : string | number
>a2 : (string | number)[]
>d5 : (number | string)[]
>[...a2] : (number | string)[]
>...a2 : number | string
>a2 : (number | string)[]
var d6 = [...a3];
>d6 : number[]
@@ -201,8 +201,8 @@ var d8: number[][] = [[...temp1]]
>temp1 : number[]
var d9 = [[...temp1], ...["hello"]];
>d9 : (string | number[])[]
>[[...temp1], ...["hello"]] : (string | number[])[]
>d9 : (number[] | string)[]
>[[...temp1], ...["hello"]] : (number[] | string)[]
>[...temp1] : number[]
>...temp1 : number
>temp1 : number[]

View File

@@ -5,18 +5,18 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error
Type 'string' is not assignable to type 'boolean'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
Types of property 'pop' are incompatible.
Type '() => string | number | boolean' is not assignable to type '() => number'.
Type 'string | number | boolean' is not assignable to type 'number'.
Type '() => number | string | boolean' is not assignable to type '() => number'.
Type 'number | string | boolean' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(number[] | string[])[]' is not assignable to type 'tup'.
Property '0' is missing in type '(number[] | string[])[]'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
Property '0' is missing in type 'number[]'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(number | string)[]' is not assignable to type 'myArray'.
Types of property 'push' are incompatible.
Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'.
Type '(...items: (number | string)[]) => number' is not assignable to type '(...items: Number[]) => number'.
Types of parameters 'items' and 'items' are incompatible.
Type 'string | number' is not assignable to type 'Number'.
Type 'number | string' is not assignable to type 'Number'.
Type 'string' is not assignable to type 'Number'.
Property 'toFixed' is missing in type 'String'.
@@ -49,8 +49,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
~~~~~~~~
!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'.
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'.
!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number'.
!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
// The resulting type an array literal expression is determined as follows:
@@ -76,11 +76,11 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
!!! error TS2322: Property '0' is missing in type 'number[]'.
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
~~
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
!!! error TS2322: Type '(number | string)[]' is not assignable to type 'myArray'.
!!! error TS2322: Types of property 'push' are incompatible.
!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'.
!!! error TS2322: Type '(...items: (number | string)[]) => number' is not assignable to type '(...items: Number[]) => number'.
!!! error TS2322: Types of parameters 'items' and 'items' are incompatible.
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
!!! error TS2322: Type 'number | string' is not assignable to type 'Number'.
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
!!! error TS2322: Property 'toFixed' is missing in type 'String'.

View File

@@ -77,8 +77,8 @@ var myDerivedList: DerivedList<number>;
>DerivedList : DerivedList<U>
var as = [list, myDerivedList]; // List<number>[]
>as : List<number>[]
>[list, myDerivedList] : List<number>[]
>as : (List<number> | DerivedList<number>)[]
>[list, myDerivedList] : (List<number> | DerivedList<number>)[]
>list : List<number>
>myDerivedList : DerivedList<number>

View File

@@ -0,0 +1,35 @@
tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts(17,13): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts(26,10): error TS2349: Cannot invoke an expression whose type lacks a call signature.
==== tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts (2 errors) ====
// valid uses of arrays of function types
var x = [() => 1, () => { }];
var r2 = x[0]();
class C {
foo: string;
}
var y = [C, C];
var r3 = new y[0]();
var a: { (x: number): number; (x: string): string; };
var b: { (x: number): number; (x: string): string; };
var c: { (x: number): number; (x: any): any; };
var z = [a, b, c];
var r4 = z[0];
var r5 = r4(''); // any not string
~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
var r5b = r4(1);
var a2: { <T>(x: T): number; (x: string): string;};
var b2: { <T>(x: T): number; (x: string): string; };
var c2: { (x: number): number; <T>(x: T): any; };
var z2 = [a2, b2, c2];
var r6 = z2[0];
var r7 = r6(''); // any not string
~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.

View File

@@ -1,93 +0,0 @@
=== tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts ===
// valid uses of arrays of function types
var x = [() => 1, () => { }];
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 2, 3))
var r2 = x[0]();
>r2 : Symbol(r2, Decl(arrayOfFunctionTypes3.ts, 3, 3))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 2, 3))
class C {
>C : Symbol(C, Decl(arrayOfFunctionTypes3.ts, 3, 16))
foo: string;
>foo : Symbol(foo, Decl(arrayOfFunctionTypes3.ts, 5, 9))
}
var y = [C, C];
>y : Symbol(y, Decl(arrayOfFunctionTypes3.ts, 8, 3))
>C : Symbol(C, Decl(arrayOfFunctionTypes3.ts, 3, 16))
>C : Symbol(C, Decl(arrayOfFunctionTypes3.ts, 3, 16))
var r3 = new y[0]();
>r3 : Symbol(r3, Decl(arrayOfFunctionTypes3.ts, 9, 3))
>y : Symbol(y, Decl(arrayOfFunctionTypes3.ts, 8, 3))
var a: { (x: number): number; (x: string): string; };
>a : Symbol(a, Decl(arrayOfFunctionTypes3.ts, 11, 3))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 11, 10))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 11, 31))
var b: { (x: number): number; (x: string): string; };
>b : Symbol(b, Decl(arrayOfFunctionTypes3.ts, 12, 3))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 12, 10))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 12, 31))
var c: { (x: number): number; (x: any): any; };
>c : Symbol(c, Decl(arrayOfFunctionTypes3.ts, 13, 3))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 13, 10))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 13, 31))
var z = [a, b, c];
>z : Symbol(z, Decl(arrayOfFunctionTypes3.ts, 14, 3))
>a : Symbol(a, Decl(arrayOfFunctionTypes3.ts, 11, 3))
>b : Symbol(b, Decl(arrayOfFunctionTypes3.ts, 12, 3))
>c : Symbol(c, Decl(arrayOfFunctionTypes3.ts, 13, 3))
var r4 = z[0];
>r4 : Symbol(r4, Decl(arrayOfFunctionTypes3.ts, 15, 3))
>z : Symbol(z, Decl(arrayOfFunctionTypes3.ts, 14, 3))
var r5 = r4(''); // any not string
>r5 : Symbol(r5, Decl(arrayOfFunctionTypes3.ts, 16, 3))
>r4 : Symbol(r4, Decl(arrayOfFunctionTypes3.ts, 15, 3))
var r5b = r4(1);
>r5b : Symbol(r5b, Decl(arrayOfFunctionTypes3.ts, 17, 3))
>r4 : Symbol(r4, Decl(arrayOfFunctionTypes3.ts, 15, 3))
var a2: { <T>(x: T): number; (x: string): string;};
>a2 : Symbol(a2, Decl(arrayOfFunctionTypes3.ts, 19, 3))
>T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 19, 11))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 19, 14))
>T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 19, 11))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 19, 30))
var b2: { <T>(x: T): number; (x: string): string; };
>b2 : Symbol(b2, Decl(arrayOfFunctionTypes3.ts, 20, 3))
>T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 20, 11))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 20, 14))
>T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 20, 11))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 20, 30))
var c2: { (x: number): number; <T>(x: T): any; };
>c2 : Symbol(c2, Decl(arrayOfFunctionTypes3.ts, 21, 3))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 21, 11))
>T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 21, 32))
>x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 21, 35))
>T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 21, 32))
var z2 = [a2, b2, c2];
>z2 : Symbol(z2, Decl(arrayOfFunctionTypes3.ts, 23, 3))
>a2 : Symbol(a2, Decl(arrayOfFunctionTypes3.ts, 19, 3))
>b2 : Symbol(b2, Decl(arrayOfFunctionTypes3.ts, 20, 3))
>c2 : Symbol(c2, Decl(arrayOfFunctionTypes3.ts, 21, 3))
var r6 = z2[0];
>r6 : Symbol(r6, Decl(arrayOfFunctionTypes3.ts, 24, 3))
>z2 : Symbol(z2, Decl(arrayOfFunctionTypes3.ts, 23, 3))
var r7 = r6(''); // any not string
>r7 : Symbol(r7, Decl(arrayOfFunctionTypes3.ts, 25, 3))
>r6 : Symbol(r6, Decl(arrayOfFunctionTypes3.ts, 24, 3))

View File

@@ -1,116 +0,0 @@
=== tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts ===
// valid uses of arrays of function types
var x = [() => 1, () => { }];
>x : (() => void)[]
>[() => 1, () => { }] : (() => void)[]
>() => 1 : () => number
>1 : number
>() => { } : () => void
var r2 = x[0]();
>r2 : void
>x[0]() : void
>x[0] : () => void
>x : (() => void)[]
>0 : number
class C {
>C : C
foo: string;
>foo : string
}
var y = [C, C];
>y : typeof C[]
>[C, C] : typeof C[]
>C : typeof C
>C : typeof C
var r3 = new y[0]();
>r3 : C
>new y[0]() : C
>y[0] : typeof C
>y : typeof C[]
>0 : number
var a: { (x: number): number; (x: string): string; };
>a : { (x: number): number; (x: string): string; }
>x : number
>x : string
var b: { (x: number): number; (x: string): string; };
>b : { (x: number): number; (x: string): string; }
>x : number
>x : string
var c: { (x: number): number; (x: any): any; };
>c : { (x: number): number; (x: any): any; }
>x : number
>x : any
var z = [a, b, c];
>z : { (x: number): number; (x: any): any; }[]
>[a, b, c] : { (x: number): number; (x: any): any; }[]
>a : { (x: number): number; (x: string): string; }
>b : { (x: number): number; (x: string): string; }
>c : { (x: number): number; (x: any): any; }
var r4 = z[0];
>r4 : { (x: number): number; (x: any): any; }
>z[0] : { (x: number): number; (x: any): any; }
>z : { (x: number): number; (x: any): any; }[]
>0 : number
var r5 = r4(''); // any not string
>r5 : any
>r4('') : any
>r4 : { (x: number): number; (x: any): any; }
>'' : string
var r5b = r4(1);
>r5b : number
>r4(1) : number
>r4 : { (x: number): number; (x: any): any; }
>1 : number
var a2: { <T>(x: T): number; (x: string): string;};
>a2 : { <T>(x: T): number; (x: string): string; }
>T : T
>x : T
>T : T
>x : string
var b2: { <T>(x: T): number; (x: string): string; };
>b2 : { <T>(x: T): number; (x: string): string; }
>T : T
>x : T
>T : T
>x : string
var c2: { (x: number): number; <T>(x: T): any; };
>c2 : { (x: number): number; <T>(x: T): any; }
>x : number
>T : T
>x : T
>T : T
var z2 = [a2, b2, c2];
>z2 : { (x: number): number; <T>(x: T): any; }[]
>[a2, b2, c2] : { (x: number): number; <T>(x: T): any; }[]
>a2 : { <T>(x: T): number; (x: string): string; }
>b2 : { <T>(x: T): number; (x: string): string; }
>c2 : { (x: number): number; <T>(x: T): any; }
var r6 = z2[0];
>r6 : { (x: number): number; <T>(x: T): any; }
>z2[0] : { (x: number): number; <T>(x: T): any; }
>z2 : { (x: number): number; <T>(x: T): any; }[]
>0 : number
var r7 = r6(''); // any not string
>r7 : any
>r6('') : any
>r6 : { (x: number): number; <T>(x: T): any; }
>'' : string

View File

@@ -24,12 +24,12 @@ var z = Date as any as string;
// Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string'
var j = 32 as number|string;
>j : string | number
>32 as number|string : string | number
>j : number | string
>32 as number|string : number | string
>32 : number
j = '';
>j = '' : string
>j : string | number
>j : number | string
>'' : string

View File

@@ -1,7 +1,7 @@
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 '() => number | string' is not assignable to type '() => number'.
Type 'number | string' 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 '{}[]'.
@@ -28,8 +28,8 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
~~~~~~~~
!!! 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 '() => number | string' is not assignable to type '() => number'.
!!! error TS2322: Type 'number | string' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
emptyObjTuple = emptyObjArray;
~~~~~~~~~~~~~

View File

@@ -1,7 +1,9 @@
tests/cases/compiler/assignmentCompatBug2.ts(1,5): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
Property 'b' is missing in type '{ a: number; }'.
Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
tests/cases/compiler/assignmentCompatBug2.ts(3,1): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
Property 'b' is missing in type '{ a: number; }'.
Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
tests/cases/compiler/assignmentCompatBug2.ts(5,1): error TS2322: Type '{ b: number; a: number; }' is not assignable to type '{ b: number; }'.
Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
tests/cases/compiler/assignmentCompatBug2.ts(15,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'.
Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; }'.
tests/cases/compiler/assignmentCompatBug2.ts(20,1): error TS2322: Type '{ f: (n: number) => number; m: number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'.
@@ -10,18 +12,21 @@ tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2322: Type '{ f: (n:
Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n: number; k: (a: any) => any; }'.
==== tests/cases/compiler/assignmentCompatBug2.ts (5 errors) ====
==== tests/cases/compiler/assignmentCompatBug2.ts (6 errors) ====
var b2: { b: number;} = { a: 0 }; // error
~~
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
!!! error TS2322: Property 'b' is missing in type '{ a: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
b2 = { a: 0 }; // error
~~
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
!!! error TS2322: Property 'b' is missing in type '{ a: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
b2 = {b: 0, a: 0 };
~~
!!! error TS2322: Type '{ b: number; a: number; }' is not assignable to type '{ b: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
var b3: { f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; };

View File

@@ -1,5 +1,5 @@
tests/cases/compiler/assignmentCompatBug5.ts(2,6): error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
Property 'a' is missing in type '{ b: number; }'.
Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.
tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/assignmentCompatBug5.ts(8,6): error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'.
@@ -14,7 +14,7 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ
foo1({ b: 5 });
~~~~~~~~
!!! error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
!!! error TS2345: Property 'a' is missing in type '{ b: number; }'.
!!! error TS2345: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.
function foo2(x: number[]) { }
foo2(["s", "t"]);

View File

@@ -1,6 +1,6 @@
=== tests/cases/conformance/async/es6/awaitUnion_es6.ts ===
declare let a: number | string;
>a : string | number
>a : number | string
declare let b: PromiseLike<number> | PromiseLike<string>;
>b : PromiseLike<number> | PromiseLike<string>
@@ -8,7 +8,7 @@ declare let b: PromiseLike<number> | PromiseLike<string>;
>PromiseLike : PromiseLike<T>
declare let c: PromiseLike<number | string>;
>c : PromiseLike<string | number>
>c : PromiseLike<number | string>
>PromiseLike : PromiseLike<T>
declare let d: number | PromiseLike<string>;
@@ -16,29 +16,29 @@ declare let d: number | PromiseLike<string>;
>PromiseLike : PromiseLike<T>
declare let e: number | PromiseLike<number | string>;
>e : number | PromiseLike<string | number>
>e : number | PromiseLike<number | string>
>PromiseLike : PromiseLike<T>
async function f() {
>f : () => Promise<void>
let await_a = await a;
>await_a : string | number
>await_a : number | string
>a : any
let await_b = await b;
>await_b : string | number
>await_b : number | string
>b : any
let await_c = await c;
>await_c : string | number
>await_c : number | string
>c : any
let await_d = await d;
>await_d : string | number
>await_d : number | string
>d : any
let await_e = await e;
>await_e : string | number
>await_e : number | string
>e : any
}

View File

@@ -46,8 +46,8 @@ var r = true ? 1 : 2;
>2 : number
var r3 = true ? 1 : {};
>r3 : {}
>true ? 1 : {} : {}
>r3 : number | {}
>true ? 1 : {} : number | {}
>true : boolean
>1 : number
>{} : {}
@@ -60,15 +60,15 @@ var r4 = true ? a : b; // typeof a
>b : { x: number; z?: number; }
var r5 = true ? b : a; // typeof b
>r5 : { x: number; y?: number; } | { x: number; z?: number; }
>true ? b : a : { x: number; y?: number; } | { x: number; z?: number; }
>r5 : { x: number; z?: number; } | { x: number; y?: number; }
>true ? b : a : { x: number; z?: number; } | { x: number; y?: number; }
>true : boolean
>b : { x: number; z?: number; }
>a : { x: number; y?: number; }
var r6 = true ? (x: number) => { } : (x: Object) => { }; // returns number => void
>r6 : (x: number) => void
>true ? (x: number) => { } : (x: Object) => { } : (x: number) => void
>r6 : ((x: number) => void) | ((x: Object) => void)
>true ? (x: number) => { } : (x: Object) => { } : ((x: number) => void) | ((x: Object) => void)
>true : boolean
>(x: number) => { } : (x: number) => void
>x : number
@@ -80,7 +80,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: number) => void
>true ? (x: number) => { } : (x: Object) => { } : ((x: number) => void) | ((x: Object) => void)
>true : boolean
>(x: number) => { } : (x: number) => void
>x : number
@@ -89,8 +89,8 @@ var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { };
>Object : Object
var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => void
>r8 : (x: Object) => void
>true ? (x: Object) => { } : (x: number) => { } : (x: Object) => void
>r8 : ((x: Object) => void) | ((x: number) => void)
>true ? (x: Object) => { } : (x: number) => { } : ((x: Object) => void) | ((x: number) => void)
>true : boolean
>(x: Object) => { } : (x: Object) => void
>x : Object
@@ -107,8 +107,8 @@ var r10: Base = true ? derived : derived2; // no error since we use the contextu
>derived2 : Derived2
var r11 = true ? base : derived2;
>r11 : Base
>true ? base : derived2 : Base
>r11 : Base | Derived2
>true ? base : derived2 : Base | Derived2
>true : boolean
>base : Base
>derived2 : Derived2

View File

@@ -98,8 +98,8 @@ var e3 = t3[2]; // any
>2 : number
var e4 = t4[3]; // number
>e4 : number
>t4[3] : number
>e4 : E1 | E2 | number
>t4[3] : E1 | E2 | number
>t4 : [E1, E2, number]
>3 : number

View File

@@ -66,8 +66,8 @@ var t5: [C1, F]
>F : F
var e11 = t1[4]; // base
>e11 : base
>t1[4] : base
>e11 : C | base
>t1[4] : C | base
>t1 : [C, base]
>4 : number
@@ -78,20 +78,20 @@ var e21 = t2[4]; // {}
>4 : number
var e31 = t3[4]; // C1
>e31 : C1
>t3[4] : C1
>e31 : C1 | D1
>t3[4] : C1 | D1
>t3 : [C1, D1]
>4 : number
var e41 = t4[2]; // base1
>e41 : base1
>t4[2] : base1
>e41 : base1 | C1
>t4[2] : base1 | C1
>t4 : [base1, C1]
>2 : number
var e51 = t5[2]; // {}
>e51 : F | C1
>t5[2] : F | C1
>e51 : C1 | F
>t5[2] : C1 | F
>t5 : [C1, F]
>2 : number

View File

@@ -27,43 +27,43 @@ var z: Z;
// All these arrays should be X[]
var b1 = [x, y, z];
>b1 : X[]
>[x, y, z] : X[]
>b1 : (X | Y | Z)[]
>[x, y, z] : (X | Y | Z)[]
>x : X
>y : Y
>z : Z
var b2 = [x, z, y];
>b2 : X[]
>[x, z, y] : X[]
>b2 : (X | Z | Y)[]
>[x, z, y] : (X | Z | Y)[]
>x : X
>z : Z
>y : Y
var b3 = [y, x, z];
>b3 : X[]
>[y, x, z] : X[]
>b3 : (Y | X | Z)[]
>[y, x, z] : (Y | X | Z)[]
>y : Y
>x : X
>z : Z
var b4 = [y, z, x];
>b4 : X[]
>[y, z, x] : X[]
>b4 : (Y | Z | X)[]
>[y, z, x] : (Y | Z | X)[]
>y : Y
>z : Z
>x : X
var b5 = [z, x, y];
>b5 : X[]
>[z, x, y] : X[]
>b5 : (Z | X | Y)[]
>[z, x, y] : (Z | X | Y)[]
>z : Z
>x : X
>y : Y
var b6 = [z, y, x];
>b6 : X[]
>[z, y, x] : X[]
>b6 : (Z | Y | X)[]
>[z, y, x] : (Z | Y | X)[]
>z : Z
>y : Y
>x : X

View File

@@ -163,8 +163,8 @@ xa[1].foo(1, 2, ...a, "abc");
>xa : X[]
>1 : number
>foo : (x: number, y: number, ...z: string[]) => any
>...[1, 2, "abc"] : string | number
>[1, 2, "abc"] : (string | number)[]
>...[1, 2, "abc"] : number | string
>[1, 2, "abc"] : (number | string)[]
>1 : number
>2 : number
>"abc" : string

View File

@@ -164,8 +164,8 @@ xa[1].foo(1, 2, ...a, "abc");
>xa : X[]
>1 : number
>foo : (x: number, y: number, ...z: string[]) => any
>...[1, 2, "abc"] : string | number
>[1, 2, "abc"] : (string | number)[]
>...[1, 2, "abc"] : number | string
>[1, 2, "abc"] : (number | string)[]
>1 : number
>2 : number
>"abc" : string

View File

@@ -8,11 +8,12 @@ tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2352: Neithe
tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2352: 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(30,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(30,14): error TS2352: 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 '() => number | string' is not assignable to type '() => number'.
Type 'number | string' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot find name 't4'.
@@ -61,14 +62,15 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot
!!! error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other.
!!! error TS2352: Types of property '0' are incompatible.
!!! error TS2352: Type 'C' is not assignable to type 'A'.
!!! error TS2352: 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 TS2352: Neither type '[number, string]' nor type 'number[]' is assignable to the other.
!!! error TS2352: Types of property 'pop' are incompatible.
!!! error TS2352: Type '() => string | number' is not assignable to type '() => number'.
!!! error TS2352: Type 'string | number' is not assignable to type 'number'.
!!! error TS2352: Type '() => number | string' is not assignable to type '() => number'.
!!! error TS2352: Type 'number | string' is not assignable to type 'number'.
!!! error TS2352: Type 'string' is not assignable to type 'number'.
t4[2] = 10;
~~

View File

@@ -0,0 +1,21 @@
tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
==== tests/cases/compiler/classExtendsNull.ts (1 errors) ====
class C extends null {
constructor() {
~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
return Object.create(null);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
}
class D extends null {
constructor() {
return Object.create(null);
}
}

View File

@@ -0,0 +1,35 @@
//// [classExtendsNull.ts]
class C extends null {
constructor() {
super();
return Object.create(null);
}
}
class D extends null {
constructor() {
return Object.create(null);
}
}
//// [classExtendsNull.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var C = (function (_super) {
__extends(C, _super);
function C() {
_super.call(this);
return Object.create(null);
}
return C;
})(null);
var D = (function (_super) {
__extends(D, _super);
function D() {
return Object.create(null);
}
return D;
})(null);

View File

@@ -17,9 +17,9 @@ declare function foo<T>(obj: I<T>): T
>T : T
foo({
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[]
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[]
>foo : <T>(obj: I<T>) => T
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; }
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; 0: () => void; p: string; }
p: "",
>p : string

View File

@@ -17,9 +17,9 @@ declare function foo<T>(obj: I<T>): T
>T : T
foo({
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[]
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[]
>foo : <T>(obj: I<T>) => T
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; }
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; 0: () => void; p: string; }
p: "",
>p : string

View File

@@ -17,9 +17,9 @@ declare function foo<T>(obj: I<T>): T
>T : T
foo({
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[]
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[]
>foo : <T>(obj: I<T>) => T
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; }
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: (() => void) | number | number[]; 0: () => void; p: string; }
p: "",
>p : string

View File

@@ -17,9 +17,9 @@ declare function foo<T>(obj: I<T>): T
>T : T
foo({
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[]
>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[]
>foo : <T>(obj: I<T>) => T
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; }
>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: (() => void) | number | number[]; 0: () => void; p: string; }
p: "",
>p : string

View File

@@ -1,9 +1,9 @@
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(1,5): error TS2322: Type 'number | string' is not assignable to type 'boolean'.
Type 'number' is not assignable to type 'boolean'.
==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ====
var x: boolean = (true ? 1 : ""); // should be an error
~
!!! error TS2322: Type 'string | number' is not assignable to type 'boolean'.
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
!!! error TS2322: Type 'number | string' is not assignable to type 'boolean'.
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.

View File

@@ -31,27 +31,27 @@ var b: B;
//Cond ? Expr1 : Expr2, Expr1 is supertype
//Be Not contextually typed
true ? x : a;
>true ? x : a : X
>true ? x : a : X | A
>true : boolean
>x : X
>a : A
var result1 = true ? x : a;
>result1 : X
>true ? x : a : X
>result1 : X | A
>true ? x : a : X | A
>true : boolean
>x : X
>a : A
//Expr1 and Expr2 are literals
true ? {} : 1;
>true ? {} : 1 : {}
>true ? {} : 1 : {} | number
>true : boolean
>{} : {}
>1 : number
true ? { a: 1 } : { a: 2, b: 'string' };
>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; }
>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; } | { a: number; b: string; }
>true : boolean
>{ a: 1 } : { a: number; }
>a : number
@@ -63,15 +63,15 @@ true ? { a: 1 } : { a: 2, b: 'string' };
>'string' : string
var result2 = true ? {} : 1;
>result2 : {}
>true ? {} : 1 : {}
>result2 : {} | number
>true ? {} : 1 : {} | number
>true : boolean
>{} : {}
>1 : number
var result3 = true ? { a: 1 } : { a: 2, b: 'string' };
>result3 : { a: number; }
>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; }
>result3 : { a: number; } | { a: number; b: string; }
>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; } | { a: number; b: string; }
>true : boolean
>{ a: 1 } : { a: number; }
>a : number
@@ -86,7 +86,7 @@ var result3 = true ? { a: 1 } : { a: 2, b: 'string' };
var resultIsX1: X = true ? x : a;
>resultIsX1 : X
>X : X
>true ? x : a : X
>true ? x : a : X | A
>true : boolean
>x : X
>a : A
@@ -95,7 +95,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 : (m: A) => any
>true ? (m) => m.propertyX : (n) => n.propertyA : ((m: A) => any) | ((n: A) => number)
>true : boolean
>(m) => m.propertyX : (m: A) => any
>m : A
@@ -111,27 +111,27 @@ var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA;
//Cond ? Expr1 : Expr2, Expr2 is supertype
//Be Not contextually typed
true ? a : x;
>true ? a : x : X
>true ? a : x : A | X
>true : boolean
>a : A
>x : X
var result5 = true ? a : x;
>result5 : X
>true ? a : x : X
>result5 : A | X
>true ? a : x : A | X
>true : boolean
>a : A
>x : X
//Expr1 and Expr2 are literals
true ? 1 : {};
>true ? 1 : {} : {}
>true ? 1 : {} : number | {}
>true : boolean
>1 : number
>{} : {}
true ? { a: 2, b: 'string' } : { a: 1 };
>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; }
>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; b: string; } | { a: number; }
>true : boolean
>{ a: 2, b: 'string' } : { a: number; b: string; }
>a : number
@@ -143,15 +143,15 @@ true ? { a: 2, b: 'string' } : { a: 1 };
>1 : number
var result6 = true ? 1 : {};
>result6 : {}
>true ? 1 : {} : {}
>result6 : number | {}
>true ? 1 : {} : number | {}
>true : boolean
>1 : number
>{} : {}
var result7 = true ? { a: 2, b: 'string' } : { a: 1 };
>result7 : { a: number; }
>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; }
>result7 : { a: number; b: string; } | { a: number; }
>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; b: string; } | { a: number; }
>true : boolean
>{ a: 2, b: 'string' } : { a: number; b: string; }
>a : number
@@ -166,7 +166,7 @@ var result7 = true ? { a: 2, b: 'string' } : { a: 1 };
var resultIsX2: X = true ? x : a;
>resultIsX2 : X
>X : X
>true ? x : a : X
>true ? x : a : X | A
>true : boolean
>x : X
>a : A
@@ -175,7 +175,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 : (n: A) => any
>true ? (m) => m.propertyA : (n) => n.propertyX : ((m: A) => number) | ((n: A) => any)
>true : boolean
>(m) => m.propertyA : (m: A) => number
>m : A
@@ -218,7 +218,7 @@ 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' : string | number
>true ? 1 : 'string' : number | string
>true : boolean
>1 : number
>'string' : string

View File

@@ -1,6 +1,6 @@
tests/cases/compiler/constEnumErrors.ts(1,12): error TS2300: Duplicate identifier 'E'.
tests/cases/compiler/constEnumErrors.ts(5,8): error TS2300: Duplicate identifier 'E'.
tests/cases/compiler/constEnumErrors.ts(12,9): error TS2474: In 'const' enum declarations member initializer must be constant expression.
tests/cases/compiler/constEnumErrors.ts(12,9): error TS2651: A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums.
tests/cases/compiler/constEnumErrors.ts(14,9): error TS2474: In 'const' enum declarations member initializer must be constant expression.
tests/cases/compiler/constEnumErrors.ts(15,10): error TS2474: In 'const' enum declarations member initializer must be constant expression.
tests/cases/compiler/constEnumErrors.ts(22,13): error TS2476: A const enum member can only be accessed using a string literal.
@@ -31,7 +31,7 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS2478: 'const' enum member
// forward reference to the element of the same enum
X = Y,
~
!!! error TS2474: In 'const' enum declarations member initializer must be constant expression.
!!! error TS2651: A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums.
// forward reference to the element of the same enum
Y = E1.Z,
~~~~

View File

@@ -0,0 +1,14 @@
//// [constEnumMergingWithValues1.ts]
function foo() {}
module foo {
const enum E { X }
}
export = foo
//// [constEnumMergingWithValues1.js]
define(["require", "exports"], function (require, exports) {
function foo() { }
return foo;
});

View File

@@ -0,0 +1,16 @@
=== tests/cases/compiler/constEnumMergingWithValues1.ts ===
function foo() {}
>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17))
module foo {
>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17))
const enum E { X }
>E : Symbol(E, Decl(constEnumMergingWithValues1.ts, 2, 12))
>X : Symbol(E.X, Decl(constEnumMergingWithValues1.ts, 3, 18))
}
export = foo
>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17))

View File

@@ -0,0 +1,16 @@
=== tests/cases/compiler/constEnumMergingWithValues1.ts ===
function foo() {}
>foo : typeof foo
module foo {
>foo : typeof foo
const enum E { X }
>E : E
>X : E
}
export = foo
>foo : typeof foo

View File

@@ -0,0 +1,18 @@
//// [constEnumMergingWithValues2.ts]
class foo {}
module foo {
const enum E { X }
}
export = foo
//// [constEnumMergingWithValues2.js]
define(["require", "exports"], function (require, exports) {
var foo = (function () {
function foo() {
}
return foo;
})();
return foo;
});

View File

@@ -0,0 +1,16 @@
=== tests/cases/compiler/constEnumMergingWithValues2.ts ===
class foo {}
>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12))
module foo {
>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12))
const enum E { X }
>E : Symbol(E, Decl(constEnumMergingWithValues2.ts, 2, 12))
>X : Symbol(E.X, Decl(constEnumMergingWithValues2.ts, 3, 18))
}
export = foo
>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12))

View File

@@ -0,0 +1,16 @@
=== tests/cases/compiler/constEnumMergingWithValues2.ts ===
class foo {}
>foo : foo
module foo {
>foo : typeof foo
const enum E { X }
>E : E
>X : E
}
export = foo
>foo : foo

View File

@@ -0,0 +1,17 @@
//// [constEnumMergingWithValues3.ts]
enum foo { A }
module foo {
const enum E { X }
}
export = foo
//// [constEnumMergingWithValues3.js]
define(["require", "exports"], function (require, exports) {
var foo;
(function (foo) {
foo[foo["A"] = 0] = "A";
})(foo || (foo = {}));
return foo;
});

View File

@@ -0,0 +1,17 @@
=== tests/cases/compiler/constEnumMergingWithValues3.ts ===
enum foo { A }
>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14))
>A : Symbol(foo.A, Decl(constEnumMergingWithValues3.ts, 1, 10))
module foo {
>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14))
const enum E { X }
>E : Symbol(E, Decl(constEnumMergingWithValues3.ts, 2, 12))
>X : Symbol(E.X, Decl(constEnumMergingWithValues3.ts, 3, 18))
}
export = foo
>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14))

View File

@@ -0,0 +1,17 @@
=== tests/cases/compiler/constEnumMergingWithValues3.ts ===
enum foo { A }
>foo : foo
>A : foo
module foo {
>foo : typeof foo
const enum E { X }
>E : E
>X : E
}
export = foo
>foo : foo

View File

@@ -0,0 +1,21 @@
//// [constEnumMergingWithValues4.ts]
module foo {
const enum E { X }
}
module foo {
var x = 1;
}
export = foo
//// [constEnumMergingWithValues4.js]
define(["require", "exports"], function (require, exports) {
var foo;
(function (foo) {
var x = 1;
})(foo || (foo = {}));
return foo;
});

View File

@@ -0,0 +1,21 @@
=== tests/cases/compiler/constEnumMergingWithValues4.ts ===
module foo {
>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1))
const enum E { X }
>E : Symbol(E, Decl(constEnumMergingWithValues4.ts, 1, 12))
>X : Symbol(E.X, Decl(constEnumMergingWithValues4.ts, 2, 18))
}
module foo {
>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1))
var x = 1;
>x : Symbol(x, Decl(constEnumMergingWithValues4.ts, 6, 7))
}
export = foo
>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1))

View File

@@ -0,0 +1,22 @@
=== tests/cases/compiler/constEnumMergingWithValues4.ts ===
module foo {
>foo : typeof foo
const enum E { X }
>E : E
>X : E
}
module foo {
>foo : typeof foo
var x = 1;
>x : number
>1 : number
}
export = foo
>foo : typeof foo

View File

@@ -0,0 +1,19 @@
//// [constEnumMergingWithValues5.ts]
module foo {
const enum E { X }
}
export = foo
//// [constEnumMergingWithValues5.js]
define(["require", "exports"], function (require, exports) {
var foo;
(function (foo) {
var E;
(function (E) {
E[E["X"] = 0] = "X";
})(E || (E = {}));
})(foo || (foo = {}));
return foo;
});

View File

@@ -0,0 +1,13 @@
=== tests/cases/compiler/constEnumMergingWithValues5.ts ===
module foo {
>foo : Symbol(foo, Decl(constEnumMergingWithValues5.ts, 0, 0))
const enum E { X }
>E : Symbol(E, Decl(constEnumMergingWithValues5.ts, 1, 12))
>X : Symbol(E.X, Decl(constEnumMergingWithValues5.ts, 2, 18))
}
export = foo
>foo : Symbol(foo, Decl(constEnumMergingWithValues5.ts, 0, 0))

View File

@@ -0,0 +1,13 @@
=== tests/cases/compiler/constEnumMergingWithValues5.ts ===
module foo {
>foo : typeof foo
const enum E { X }
>E : E
>X : E
}
export = foo
>foo : typeof foo

View File

@@ -87,24 +87,24 @@ var a = baz(1, 1, g); // Should be number
>g : <T>(x: T, y: T) => T
var b: number | string;
>b : string | number
>b : number | string
var b = foo(g); // Should be number | string
>b : string | number
>foo(g) : string | number
>b : number | string
>foo(g) : number | string
>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
>b : number | string
>bar(1, "one", g) : number | string
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>1 : number
>"one" : string
>g : <T>(x: T, y: T) => T
var b = bar("one", 1, g); // Should be number | string
>b : string | number
>b : number | string
>bar("one", 1, g) : string | number
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>"one" : string
@@ -112,11 +112,11 @@ var b = bar("one", 1, g); // Should be number | string
>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
>b : number | string
>baz(b, b, g) : number | string
>baz : <T, U>(x: T, y: T, cb: (x: T, y: T) => U) => U
>b : string | number
>b : string | number
>b : number | string
>b : number | string
>g : <T>(x: T, y: T) => T
var d: number[] | string[];
@@ -138,7 +138,7 @@ var d = bar(1, "one", h); // Should be number[] | string[]
var d = bar("one", 1, h); // Should be number[] | string[]
>d : number[] | string[]
>bar("one", 1, h) : number[] | string[]
>bar("one", 1, h) : string[] | number[]
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
>"one" : string
>1 : number

View File

@@ -1,9 +1,9 @@
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'.
Type '() => number | string | boolean' is not assignable to type '() => number | string'.
Type 'number | string | boolean' is not assignable to type 'number | string'.
Type 'boolean' is not assignable to type 'number | string'.
Type 'boolean' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]'.
Types of property '0' are incompatible.
@@ -31,10 +31,10 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
~~~~~~~~~~~~
!!! 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'.
!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number | string'.
!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number | string'.
!!! error TS2322: Type 'boolean' is not assignable to type 'number | string'.
!!! error TS2322: Type 'boolean' is not assignable to type 'string'.
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 }]];

View File

@@ -82,7 +82,5 @@ var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any
>IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1))
>IWithCallSignatures4 : Symbol(IWithCallSignatures4, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 18, 1))
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52))
>a.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
>a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52))
>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18))

View File

@@ -90,10 +90,10 @@ var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any
>x4 : IWithCallSignatures | IWithCallSignatures4
>IWithCallSignatures : IWithCallSignatures
>IWithCallSignatures4 : IWithCallSignatures4
>a => /*here a should be any*/ a.toString() : (a: number) => string
>a : number
>a.toString() : string
>a.toString : (radix?: number) => string
>a : number
>toString : (radix?: number) => string
>a => /*here a should be any*/ a.toString() : (a: any) => any
>a : any
>a.toString() : any
>a.toString : any
>a : any
>toString : any

View File

@@ -187,7 +187,7 @@ var arrayI1OrI2: Array<I1<number> | I2<number>> = [i1, i2, { // Like i1
>Array : T[]
>I1 : I1<T>
>I2 : I2<T>
>[i1, i2, { // Like i1 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", }, { // Like i2 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }, { // Like i1 and i2 both commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }] : (I1<number> | I2<number>)[]
>[i1, i2, { // Like i1 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", }, { // Like i2 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }, { // Like i1 and i2 both commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }] : (I1<number> | I2<number> | { commonPropertyType: string; commonMethodType: (a: string) => string; commonMethodWithTypeParameter: (a: number) => number; methodOnlyInI1: (a: string) => string; propertyOnlyInI1: string; methodOnlyInI2: (a: string) => string; propertyOnlyInI2: string; })[]
>i1 : I1<number>
>i2 : I2<number>
>{ // Like i1 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", } : { commonPropertyType: string; commonMethodType: (a: string) => string; commonMethodWithTypeParameter: (a: number) => number; methodOnlyInI1: (a: string) => string; propertyOnlyInI1: string; }

View File

@@ -0,0 +1,13 @@
tests/cases/compiler/contextualTyping12.ts(1,13): error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'.
Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'.
Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.
==== tests/cases/compiler/contextualTyping12.ts (1 errors) ====
class foo { public bar:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'.
!!! error TS2322: Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'.
!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.

View File

@@ -1,9 +0,0 @@
=== tests/cases/compiler/contextualTyping12.ts ===
class foo { public bar:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; }
>foo : Symbol(foo, Decl(contextualTyping12.ts, 0, 0))
>bar : Symbol(bar, Decl(contextualTyping12.ts, 0, 11))
>id : Symbol(id, Decl(contextualTyping12.ts, 0, 24))
>id : Symbol(id, Decl(contextualTyping12.ts, 0, 42))
>id : Symbol(id, Decl(contextualTyping12.ts, 0, 50))
>name : Symbol(name, Decl(contextualTyping12.ts, 0, 55))

View File

@@ -1,15 +0,0 @@
=== tests/cases/compiler/contextualTyping12.ts ===
class foo { public bar:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; }
>foo : foo
>bar : { id: number; }[]
>id : number
>[{id:1}, {id:2, name:"foo"}] : { id: number; }[]
>{id:1} : { id: number; }
>id : number
>1 : number
>{id:2, name:"foo"} : { id: number; name: string; }
>id : number
>2 : number
>name : string
>"foo" : string

View File

@@ -0,0 +1,9 @@
tests/cases/compiler/contextualTyping17.ts(1,33): error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.
==== tests/cases/compiler/contextualTyping17.ts (1 errors) ====
var foo: {id:number;} = {id:4}; foo = {id: 5, name:"foo"};
~~~
!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.

View File

@@ -1,9 +0,0 @@
=== tests/cases/compiler/contextualTyping17.ts ===
var foo: {id:number;} = {id:4}; foo = {id: 5, name:"foo"};
>foo : Symbol(foo, Decl(contextualTyping17.ts, 0, 3))
>id : Symbol(id, Decl(contextualTyping17.ts, 0, 10))
>id : Symbol(id, Decl(contextualTyping17.ts, 0, 25))
>foo : Symbol(foo, Decl(contextualTyping17.ts, 0, 3))
>id : Symbol(id, Decl(contextualTyping17.ts, 0, 39))
>name : Symbol(name, Decl(contextualTyping17.ts, 0, 45))

View File

@@ -1,15 +0,0 @@
=== tests/cases/compiler/contextualTyping17.ts ===
var foo: {id:number;} = {id:4}; foo = {id: 5, name:"foo"};
>foo : { id: number; }
>id : number
>{id:4} : { id: number; }
>id : number
>4 : number
>foo = {id: 5, name:"foo"} : { id: number; name: string; }
>foo : { id: number; }
>{id: 5, name:"foo"} : { id: number; name: string; }
>id : number
>5 : number
>name : string
>"foo" : string

View File

@@ -0,0 +1,9 @@
tests/cases/compiler/contextualTyping2.ts(1,5): error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.
==== tests/cases/compiler/contextualTyping2.ts (1 errors) ====
var foo: {id:number;} = {id:4, name:"foo"};
~~~
!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.

View File

@@ -1,7 +0,0 @@
=== tests/cases/compiler/contextualTyping2.ts ===
var foo: {id:number;} = {id:4, name:"foo"};
>foo : Symbol(foo, Decl(contextualTyping2.ts, 0, 3))
>id : Symbol(id, Decl(contextualTyping2.ts, 0, 10))
>id : Symbol(id, Decl(contextualTyping2.ts, 0, 25))
>name : Symbol(name, Decl(contextualTyping2.ts, 0, 30))

View File

@@ -1,10 +0,0 @@
=== tests/cases/compiler/contextualTyping2.ts ===
var foo: {id:number;} = {id:4, name:"foo"};
>foo : { id: number; }
>id : number
>{id:4, name:"foo"} : { id: number; name: string; }
>id : number
>4 : number
>name : string
>"foo" : string

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