Merge remote-tracking branch 'origin/master' into pathMappingModuleResolution

This commit is contained in:
vladima
2015-12-17 22:56:30 -08:00
116 changed files with 4802 additions and 1100 deletions
+2 -1
View File
@@ -924,7 +924,8 @@ function lintFileAsync(options, path, cb) {
var lintTargets = compilerSources
.concat(harnessCoreSources)
.concat(serverCoreSources)
.concat(scriptSources);
.concat(scriptSources)
.concat([path.join(servicesDirectory, "services.ts")]);
desc("Runs tslint on the compiler sources");
task("lint", ["build-rules"], function() {
+7
View File
@@ -0,0 +1,7 @@
This directory contains miscellaneous documentation such as the TypeScript language specification and logo.
If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook).
# Spec Contributions
The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats.
Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests.
+63 -11
View File
@@ -222,8 +222,21 @@ namespace ts {
case SyntaxKind.ExportAssignment:
return (<ExportAssignment>node).isExportEquals ? "export=" : "default";
case SyntaxKind.BinaryExpression:
// Binary expression case is for JS module 'module.exports = expr'
return "export=";
switch (getSpecialPropertyAssignmentKind(node)) {
case SpecialPropertyAssignmentKind.ModuleExports:
// module.exports = ...
return "export=";
case SpecialPropertyAssignmentKind.ExportsProperty:
case SpecialPropertyAssignmentKind.ThisProperty:
// exports.x = ... or this.y = ...
return ((node as BinaryExpression).left as PropertyAccessExpression).name.text;
case SpecialPropertyAssignmentKind.PrototypeProperty:
// className.prototype.methodName = ...
return (((node as BinaryExpression).left as PropertyAccessExpression).expression as PropertyAccessExpression).name.text;
}
Debug.fail("Unknown binary declaration kind");
break;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ClassDeclaration:
return node.flags & NodeFlags.Default ? "default" : undefined;
@@ -1166,11 +1179,25 @@ namespace ts {
return checkStrictModeIdentifier(<Identifier>node);
case SyntaxKind.BinaryExpression:
if (isInJavaScriptFile(node)) {
if (isExportsPropertyAssignment(node)) {
bindExportsPropertyAssignment(<BinaryExpression>node);
}
else if (isModuleExportsAssignment(node)) {
bindModuleExportsAssignment(<BinaryExpression>node);
const specialKind = getSpecialPropertyAssignmentKind(node);
switch (specialKind) {
case SpecialPropertyAssignmentKind.ExportsProperty:
bindExportsPropertyAssignment(<BinaryExpression>node);
break;
case SpecialPropertyAssignmentKind.ModuleExports:
bindModuleExportsAssignment(<BinaryExpression>node);
break;
case SpecialPropertyAssignmentKind.PrototypeProperty:
bindPrototypePropertyAssignment(<BinaryExpression>node);
break;
case SpecialPropertyAssignmentKind.ThisProperty:
bindThisPropertyAssignment(<BinaryExpression>node);
break;
case SpecialPropertyAssignmentKind.None:
// Nothing to do
break;
default:
Debug.fail("Unknown special property assignment kind");
}
}
return checkStrictModeBinaryExpression(<BinaryExpression>node);
@@ -1351,6 +1378,34 @@ namespace ts {
bindExportAssignment(node);
}
function bindThisPropertyAssignment(node: BinaryExpression) {
// Declare a 'member' in case it turns out the container was an ES5 class
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
container.symbol.members = container.symbol.members || {};
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
}
function bindPrototypePropertyAssignment(node: BinaryExpression) {
// We saw a node of the form 'x.prototype.y = z'. Declare a 'member' y on x if x was a function.
// Look up the function in the local scope, since prototype assignments should
// follow the function declaration
const classId = <Identifier>(<PropertyAccessExpression>(<PropertyAccessExpression>node.left).expression).expression;
const funcSymbol = container.locals[classId.text];
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) {
return;
}
// Set up the members collection if it doesn't exist already
if (!funcSymbol.members) {
funcSymbol.members = {};
}
// Declare the method/property
declareSymbol(funcSymbol.members, funcSymbol, <PropertyAccessExpression>node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
function bindCallExpression(node: CallExpression) {
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
// this check if we've already seen the module indicator
@@ -1444,10 +1499,7 @@ namespace ts {
// If this is a property-parameter, then also declare the property symbol into the
// containing class.
if (node.flags & NodeFlags.AccessibilityModifier &&
node.parent.kind === SyntaxKind.Constructor &&
isClassLike(node.parent.parent)) {
if (isParameterPropertyDeclaration(node)) {
const classDeclaration = <ClassLikeDeclaration>node.parent.parent;
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
+326 -197
View File
@@ -67,6 +67,7 @@ namespace ts {
// 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,
getSymbolsOfParameterPropertyDeclaration,
getDeclaredTypeOfSymbol,
getPropertiesOfType,
getPropertyOfType,
@@ -161,6 +162,8 @@ namespace ts {
let jsxElementClassType: Type;
let deferredNodes: Node[];
const tupleTypes: Map<TupleType> = {};
const unionTypes: Map<UnionType> = {};
const intersectionTypes: Map<IntersectionType> = {};
@@ -428,6 +431,26 @@ namespace ts {
// return undefined if we can't find a symbol.
}
/**
* Get symbols that represent parameter-property-declaration as parameter and as property declaration
* @param parameter a parameterDeclaration node
* @param parameterName a name of the parameter to get the symbols for.
* @return a tuple of two symbols
*/
function getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): [Symbol, Symbol] {
const constructoDeclaration = parameter.parent;
const classDeclaration = parameter.parent.parent;
const parameterSymbol = getSymbol(constructoDeclaration.locals, parameterName, SymbolFlags.Value);
const propertySymbol = getSymbol(classDeclaration.symbol.members, parameterName, SymbolFlags.Value);
if (parameterSymbol && propertySymbol) {
return [parameterSymbol, propertySymbol];
}
Debug.fail("There should exist two symbols, one as property declaration and one as parameter declaration");
}
function isBlockScopedNameDeclaredBeforeUse(declaration: Declaration, usage: Node): boolean {
const declarationFile = getSourceFileOfNode(declaration);
const useFile = getSourceFileOfNode(usage);
@@ -2743,9 +2766,13 @@ namespace ts {
if (declaration.kind === SyntaxKind.BinaryExpression) {
return links.type = checkExpression((<BinaryExpression>declaration).right);
}
// Handle exports.p = expr
if (declaration.kind === SyntaxKind.PropertyAccessExpression) {
return checkExpressionCached((<BinaryExpression>declaration.parent).right);
// Declarations only exist for property access expressions for certain
// special assignment kinds
if (declaration.parent.kind === SyntaxKind.BinaryExpression) {
// Handle exports.p = expr or this.p = expr or className.prototype.method = expr
return links.type = checkExpressionCached((<BinaryExpression>declaration.parent).right);
}
}
// Handle variable, parameter or property
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
@@ -3501,7 +3528,7 @@ namespace ts {
function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature {
for (const s of signatureList) {
if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
if (compareSignaturesIdentical(s, signature, partialMatch, ignoreReturnTypes, compareTypesIdentical)) {
return s;
}
}
@@ -3608,37 +3635,29 @@ namespace ts {
function resolveAnonymousTypeMembers(type: AnonymousType) {
const symbol = type.symbol;
let members: SymbolTable;
let callSignatures: Signature[];
let constructSignatures: Signature[];
let stringIndexType: Type;
let numberIndexType: Type;
if (type.target) {
members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature);
constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature);
stringIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.String), type.mapper);
numberIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.Number), type.mapper);
const members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
const callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature);
const constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature);
const stringIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.String), type.mapper);
const numberIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.Number), type.mapper);
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
else if (symbol.flags & SymbolFlags.TypeLiteral) {
members = symbol.members;
callSignatures = getSignaturesOfSymbol(members["__call"]);
constructSignatures = getSignaturesOfSymbol(members["__new"]);
stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
const members = symbol.members;
const callSignatures = getSignaturesOfSymbol(members["__call"]);
const constructSignatures = getSignaturesOfSymbol(members["__new"]);
const stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
const numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
else {
// Combinations of function, class, enum and module
members = emptySymbols;
callSignatures = emptyArray;
constructSignatures = emptyArray;
let members = emptySymbols;
let constructSignatures: Signature[] = emptyArray;
if (symbol.flags & SymbolFlags.HasExports) {
members = getExportsOfSymbol(symbol);
}
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) {
callSignatures = getSignaturesOfSymbol(symbol);
}
if (symbol.flags & SymbolFlags.Class) {
const classType = getDeclaredTypeOfClassOrInterface(symbol);
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
@@ -3651,10 +3670,16 @@ namespace ts {
addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
}
}
stringIndexType = undefined;
numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined;
const numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined;
setObjectTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexType);
// We resolve the members before computing the signatures because a signature may use
// typeof with a qualified name expression that circularly references the type we are
// in the process of resolving (see issue #6072). The temporarily empty signature list
// will never be observed because a qualified name can't reference signatures.
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) {
(<ResolvedType>type).callSignatures = getSignaturesOfSymbol(symbol);
}
}
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
function resolveStructuredTypeMembers(type: ObjectType): ResolvedType {
@@ -3764,11 +3789,14 @@ namespace ts {
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol {
const types = containingType.types;
let props: Symbol[];
// Flags we want to propagate to the result if they exist in all source symbols
let commonFlags = (containingType.flags & TypeFlags.Intersection) ? SymbolFlags.Optional : SymbolFlags.None;
for (const current of types) {
const type = getApparentType(current);
if (type !== unknownType) {
const prop = getPropertyOfType(type, name);
if (prop && !(getDeclarationFlagsFromSymbol(prop) & (NodeFlags.Private | NodeFlags.Protected))) {
commonFlags &= prop.flags;
if (!props) {
props = [prop];
}
@@ -3796,7 +3824,12 @@ namespace ts {
}
propTypes.push(getTypeOfSymbol(prop));
}
const result = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty, name);
const result = <TransientSymbol>createSymbol(
SymbolFlags.Property |
SymbolFlags.Transient |
SymbolFlags.SyntheticProperty |
commonFlags,
name);
result.containingType = containingType;
result.declarations = declarations;
result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes);
@@ -4955,7 +4988,7 @@ namespace ts {
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
}
function compareTypes(source: Type, target: Type): Ternary {
function compareTypesIdentical(source: Type, target: Type): Ternary {
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False;
}
@@ -4975,10 +5008,96 @@ namespace ts {
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain);
}
function isSignatureAssignableTo(source: Signature, target: Signature): boolean {
const sourceType = getOrCreateTypeFromSignature(source);
const targetType = getOrCreateTypeFromSignature(target);
return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined);
/**
* See signatureRelatedTo, compareSignaturesIdentical
*/
function isSignatureAssignableTo(source: Signature, target: Signature, ignoreReturnTypes: boolean): boolean {
// TODO (drosen): De-duplicate code between related functions.
if (source === target) {
return true;
}
if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) {
return false;
}
// Spec 1.0 Section 3.8.3 & 3.8.4:
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
source = getErasedSignature(source);
target = getErasedSignature(target);
const sourceMax = getNumNonRestParameters(source);
const targetMax = getNumNonRestParameters(target);
const checkCount = getNumParametersToCheckForSignatureRelatability(source, sourceMax, target, targetMax);
for (let i = 0; i < checkCount; i++) {
const s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
const t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
const related = isTypeAssignableTo(t, s) || isTypeAssignableTo(s, t);
if (!related) {
return false;
}
}
if (!ignoreReturnTypes) {
const targetReturnType = getReturnTypeOfSignature(target);
if (targetReturnType === voidType) {
return true;
}
const sourceReturnType = getReturnTypeOfSignature(source);
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) {
if (!(sourceReturnType.flags & TypeFlags.PredicateType)) {
return false;
}
}
return isTypeAssignableTo(sourceReturnType, targetReturnType);
}
return true;
}
function isImplementationCompatibleWithOverload(implementation: Signature, overload: Signature): boolean {
const erasedSource = getErasedSignature(implementation);
const erasedTarget = getErasedSignature(overload);
// First see if the return types are compatible in either direction.
const sourceReturnType = getReturnTypeOfSignature(erasedSource);
const targetReturnType = getReturnTypeOfSignature(erasedTarget);
if (targetReturnType === voidType
|| checkTypeRelatedTo(targetReturnType, sourceReturnType, assignableRelation, /*errorNode*/ undefined)
|| checkTypeRelatedTo(sourceReturnType, targetReturnType, assignableRelation, /*errorNode*/ undefined)) {
return isSignatureAssignableTo(erasedSource, erasedTarget, /*ignoreReturnTypes*/ true);
}
return false;
}
function getNumNonRestParameters(signature: Signature) {
const numParams = signature.parameters.length;
return signature.hasRestParameter ?
numParams - 1 :
numParams;
}
function getNumParametersToCheckForSignatureRelatability(source: Signature, sourceNonRestParamCount: number, target: Signature, targetNonRestParamCount: number) {
if (source.hasRestParameter === target.hasRestParameter) {
if (source.hasRestParameter) {
// If both have rest parameters, get the max and add 1 to
// compensate for the rest parameter.
return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1;
}
else {
return Math.min(sourceNonRestParamCount, targetNonRestParamCount);
}
}
else {
// Return the count for whichever signature doesn't have rest parameters.
return source.hasRestParameter ?
targetNonRestParamCount :
sourceNonRestParamCount;
}
}
/**
@@ -5062,6 +5181,11 @@ namespace ts {
if (source === undefinedType) return Ternary.True;
if (source === nullType && target !== undefinedType) return Ternary.True;
if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True;
if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) {
if (result = enumRelatedTo(source, target)) {
return result;
}
}
if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True;
if (relation === assignableRelation) {
if (isTypeAny(source)) return Ternary.True;
@@ -5565,7 +5689,7 @@ namespace ts {
shouldElaborateErrors = false;
}
}
// don't elaborate the primitive apparent types (like Number)
// don't elaborate the primitive apparent types (like Number)
// because the actual primitives will have already been reported.
if (shouldElaborateErrors && !isPrimitiveApparentType(source)) {
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
@@ -5612,7 +5736,11 @@ namespace ts {
}
}
/**
* See signatureAssignableTo, signatureAssignableTo
*/
function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary {
// TODO (drosen): De-duplicate code between related functions.
if (source === target) {
return Ternary.True;
}
@@ -5664,10 +5792,12 @@ namespace ts {
}
const targetReturnType = getReturnTypeOfSignature(target);
if (targetReturnType === voidType) return result;
if (targetReturnType === voidType) {
return result;
}
const sourceReturnType = getReturnTypeOfSignature(source);
// The follow block preserves old behavior forbidding boolean returning functions from being assignable to type guard returning functions
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) {
if (!(sourceReturnType.flags & TypeFlags.PredicateType)) {
if (reportErrors) {
@@ -5688,7 +5818,7 @@ namespace ts {
}
let result = Ternary.True;
for (let i = 0, len = sourceSignatures.length; i < len; ++i) {
const related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
if (!related) {
return Ternary.False;
}
@@ -5776,6 +5906,27 @@ namespace ts {
}
return Ternary.False;
}
function enumRelatedTo(source: Type, target: Type) {
if (source.symbol.name !== target.symbol.name ||
source.symbol.flags & SymbolFlags.ConstEnum ||
target.symbol.flags & SymbolFlags.ConstEnum) {
return Ternary.False;
}
const targetEnumType = getTypeOfSymbol(target.symbol);
for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) {
if (property.flags & SymbolFlags.EnumMember) {
const targetProperty = getPropertyOfType(targetEnumType, property.name);
if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) {
reportError(Diagnostics.Property_0_is_missing_in_type_1,
property.name,
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
return Ternary.False;
}
}
}
return Ternary.True;
}
}
// Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case
@@ -5800,7 +5951,7 @@ namespace ts {
}
function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean {
return compareProperties(sourceProp, targetProp, compareTypes) !== Ternary.False;
return compareProperties(sourceProp, targetProp, compareTypesIdentical) !== Ternary.False;
}
function compareProperties(sourceProp: Symbol, targetProp: Symbol, compareTypes: (source: Type, target: Type) => Ternary): Ternary {
@@ -5847,7 +5998,11 @@ namespace ts {
return false;
}
function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
/**
* See signatureRelatedTo, compareSignaturesIdentical
*/
function compareSignaturesIdentical(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
// TODO (drosen): De-duplicate code between related functions.
if (source === target) {
return Ternary.True;
}
@@ -7023,6 +7178,23 @@ namespace ts {
const symbol = getSymbolOfNode(container.parent);
return container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : (<InterfaceType>getDeclaredTypeOfSymbol(symbol)).thisType;
}
// If this is a function in a JS file, it might be a class method. Check if it's the RHS
// of a x.prototype.y = function [name]() { .... }
if (isInJavaScriptFile(node) && container.kind === SyntaxKind.FunctionExpression) {
if (getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) {
// Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container')
const className = (((container.parent as BinaryExpression) // x.protoype.y = f
.left as PropertyAccessExpression) // x.prototype.y
.expression as PropertyAccessExpression) // x.prototype
.expression; // x
const classSymbol = checkExpression(className).symbol;
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
return getInferredClassType(classSymbol);
}
}
}
return anyType;
}
@@ -7037,17 +7209,14 @@ namespace ts {
function checkSuperExpression(node: Node): Type {
const isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).expression === node;
const classDeclaration = getContainingClass(node);
const classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
const baseClassType = classType && getBaseTypes(classType)[0];
let container = getSuperContainer(node, /*includeFunctions*/ true);
let container = getSuperContainer(node, /*stopOnFunctions*/ true);
let needToCaptureLexicalThis = false;
if (!isCallExpression) {
// adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting
while (container && container.kind === SyntaxKind.ArrowFunction) {
container = getSuperContainer(container, /*includeFunctions*/ true);
container = getSuperContainer(container, /*stopOnFunctions*/ true);
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
}
}
@@ -7055,43 +7224,66 @@ namespace ts {
const canUseSuperExpression = isLegalUsageOfSuperExpression(container);
let nodeCheckFlag: NodeCheckFlags = 0;
// always set NodeCheckFlags for 'super' expression node
if (canUseSuperExpression) {
if ((container.flags & NodeFlags.Static) || isCallExpression) {
nodeCheckFlag = NodeCheckFlags.SuperStatic;
}
else {
nodeCheckFlag = NodeCheckFlags.SuperInstance;
}
getNodeLinks(node).flags |= nodeCheckFlag;
if (needToCaptureLexicalThis) {
// call expressions are allowed only in constructors so they should always capture correct 'this'
// super property access expressions can also appear in arrow functions -
// in this case they should also use correct lexical this
captureLexicalThis(node.parent, container);
}
}
if (!baseClassType) {
if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) {
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
}
return unknownType;
}
if (!canUseSuperExpression) {
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
// issue more specific error if super is used in computed property name
// class A { foo() { return "1" }}
// class B {
// [super.foo()]() {}
// }
let current = node;
while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) {
current = current.parent;
}
if (current && current.kind === SyntaxKind.ComputedPropertyName) {
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
}
else if (isCallExpression) {
error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
}
else if (!container || !container.parent || !(isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression)) {
error(node, Diagnostics.super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions);
}
else {
error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class);
}
return unknownType;
}
if ((container.flags & NodeFlags.Static) || isCallExpression) {
nodeCheckFlag = NodeCheckFlags.SuperStatic;
}
else {
nodeCheckFlag = NodeCheckFlags.SuperInstance;
}
getNodeLinks(node).flags |= nodeCheckFlag;
if (needToCaptureLexicalThis) {
// call expressions are allowed only in constructors so they should always capture correct 'this'
// super property access expressions can also appear in arrow functions -
// in this case they should also use correct lexical this
captureLexicalThis(node.parent, container);
}
if (container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
if (languageVersion < ScriptTarget.ES6) {
error(node, Diagnostics.super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher);
return unknownType;
}
else {
// for object literal assume that type of 'super' is 'any'
return anyType;
}
}
// at this point the only legal case for parent is ClassLikeDeclaration
const classLikeDeclaration = <ClassLikeDeclaration>container.parent;
const classType = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classLikeDeclaration));
const baseClassType = classType && getBaseTypes(classType)[0];
if (!baseClassType) {
if (!getClassExtendsHeritageClauseElement(classLikeDeclaration)) {
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
}
return unknownType;
}
@@ -7121,8 +7313,8 @@ namespace ts {
// - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance
// - In a static member function or static member accessor
// topmost container must be something that is directly nested in the class declaration
if (container && isClassLike(container.parent)) {
// topmost container must be something that is directly nested in the class declaration\object literal expression
if (isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
if (container.flags & NodeFlags.Static) {
return container.kind === SyntaxKind.MethodDeclaration ||
container.kind === SyntaxKind.MethodSignature ||
@@ -7538,7 +7730,7 @@ namespace ts {
// This signature will contribute to contextual union signature
signatureList = [signature];
}
else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) {
else if (!compareSignaturesIdentical(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypesIdentical)) {
// Signatures aren't identical, do not use
return undefined;
}
@@ -8213,9 +8405,9 @@ namespace ts {
// Props is of type 'any' or unknown
return links.resolvedJsxType = attributesType;
}
else if (!(attributesType.flags & TypeFlags.ObjectType)) {
// Props is not an object type
error(node.tagName, Diagnostics.JSX_element_attributes_type_0_must_be_an_object_type, typeToString(attributesType));
else if (attributesType.flags & TypeFlags.Union) {
// Props cannot be a union type
error(node.tagName, Diagnostics.JSX_element_attributes_type_0_may_not_be_a_union_type, typeToString(attributesType));
return links.resolvedJsxType = anyType;
}
else {
@@ -9744,6 +9936,14 @@ namespace ts {
return links.resolvedSignature;
}
function getInferredClassType(symbol: Symbol) {
const links = getSymbolLinks(symbol);
if (!links.inferredClassType) {
links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
}
return links.inferredClassType;
}
/**
* Syntactically and semantically checks a call or new expression.
* @param node The call/new expression to be checked.
@@ -9765,8 +9965,14 @@ namespace ts {
declaration.kind !== SyntaxKind.ConstructSignature &&
declaration.kind !== SyntaxKind.ConstructorType) {
// When resolved signature is a call signature (and not a construct signature) the result type is any
if (compilerOptions.noImplicitAny) {
// When resolved signature is a call signature (and not a construct signature) the result type is any, unless
// the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
// in a JS file
const funcSymbol = checkExpression(node.expression).symbol;
if (funcSymbol && funcSymbol.members && (funcSymbol.flags & SymbolFlags.Function)) {
return getInferredClassType(funcSymbol);
}
else if (compilerOptions.noImplicitAny) {
error(node, Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
return anyType;
@@ -10123,6 +10329,7 @@ namespace ts {
if (!contextChecked) {
checkSignatureDeclaration(node);
checkNodeDeferred(node);
}
}
}
@@ -10135,7 +10342,7 @@ namespace ts {
return type;
}
function checkFunctionExpressionOrObjectLiteralMethodBody(node: ArrowFunction | FunctionExpression | MethodDeclaration) {
function checkFunctionExpressionOrObjectLiteralMethodDeferred(node: ArrowFunction | FunctionExpression | MethodDeclaration) {
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
const isAsync = isAsyncFunctionLike(node);
@@ -10178,8 +10385,6 @@ namespace ts {
checkTypeAssignableTo(exprType, returnOrPromisedType, node.body);
}
}
checkFunctionAndClassExpressionBodies(node.body);
}
}
}
@@ -11428,13 +11633,13 @@ namespace ts {
if (node.parent.kind !== SyntaxKind.ObjectLiteralExpression) {
checkSourceElement(node.body);
}
else {
checkNodeDeferred(node);
}
}
function checkObjectLiteralAccessorBody(node: AccessorDeclaration) {
if (node.body) {
checkSourceElement(node.body);
checkFunctionAndClassExpressionBodies(node.body);
}
function checkAccessorDeferred(node: AccessorDeclaration) {
checkSourceElement(node.body);
}
function checkMissingDeclaration(node: Node) {
@@ -11546,7 +11751,7 @@ namespace ts {
}
for (const otherSignature of signaturesToCheck) {
if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature, /*ignoreReturnTypes*/ false)) {
return;
}
}
@@ -11793,7 +11998,7 @@ namespace ts {
//
// The implementation is completely unrelated to the specialized signature, yet we do not check this.
for (const signature of signatures) {
if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) {
if (!signature.hasStringLiterals && !isImplementationCompatibleWithOverload(bodySignature, signature)) {
error(signature.declaration, Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
break;
}
@@ -12373,11 +12578,7 @@ namespace ts {
if (node.kind === SyntaxKind.Block) {
checkGrammarStatementInAmbientContext(node);
}
forEach(node.statements, checkSourceElement);
if (isFunctionBlock(node) || node.kind === SyntaxKind.ModuleBlock) {
checkFunctionAndClassExpressionBodies(node);
}
}
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
@@ -13406,15 +13607,19 @@ namespace ts {
function checkClassExpression(node: ClassExpression): Type {
checkClassLikeDeclaration(node);
checkNodeDeferred(node);
return getTypeOfSymbol(getSymbolOfNode(node));
}
function checkClassExpressionDeferred(node: ClassExpression) {
forEach(node.members, checkSourceElement);
}
function checkClassDeclaration(node: ClassDeclaration) {
if (!node.name && !(node.flags & NodeFlags.Default)) {
grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
}
checkClassLikeDeclaration(node);
forEach(node.members, checkSourceElement);
}
@@ -14478,107 +14683,29 @@ namespace ts {
// Here, performing a full type check of the body of the function expression whilst in the process of
// determining the type of foo would cause foo to be given type any because of the recursive reference.
// Delaying the type check of the body ensures foo has been assigned a type.
function checkFunctionAndClassExpressionBodies(node: Node): void {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
forEach((<FunctionLikeDeclaration>node).parameters, checkFunctionAndClassExpressionBodies);
checkFunctionExpressionOrObjectLiteralMethodBody(<FunctionExpression>node);
break;
case SyntaxKind.ClassExpression:
forEach((<ClassExpression>node).members, checkSourceElement);
forEachChild(node, checkFunctionAndClassExpressionBodies);
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
forEach(node.decorators, checkFunctionAndClassExpressionBodies);
forEach((<MethodDeclaration>node).parameters, checkFunctionAndClassExpressionBodies);
if (isObjectLiteralMethod(node)) {
checkFunctionExpressionOrObjectLiteralMethodBody(node);
}
break;
case SyntaxKind.Constructor:
case SyntaxKind.FunctionDeclaration:
forEach((<FunctionLikeDeclaration>node).parameters, checkFunctionAndClassExpressionBodies);
break;
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
forEach((<FunctionLikeDeclaration>node).parameters, checkFunctionAndClassExpressionBodies);
if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) {
checkObjectLiteralAccessorBody(<AccessorDeclaration>node);
}
break;
case SyntaxKind.WithStatement:
checkFunctionAndClassExpressionBodies((<WithStatement>node).expression);
break;
case SyntaxKind.Decorator:
case SyntaxKind.Parameter:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.ObjectBindingPattern:
case SyntaxKind.ArrayBindingPattern:
case SyntaxKind.BindingElement:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ElementAccessExpression:
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
case SyntaxKind.TaggedTemplateExpression:
case SyntaxKind.TemplateExpression:
case SyntaxKind.TemplateSpan:
case SyntaxKind.TypeAssertionExpression:
case SyntaxKind.AsExpression:
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.TypeOfExpression:
case SyntaxKind.VoidExpression:
case SyntaxKind.AwaitExpression:
case SyntaxKind.DeleteExpression:
case SyntaxKind.PrefixUnaryExpression:
case SyntaxKind.PostfixUnaryExpression:
case SyntaxKind.BinaryExpression:
case SyntaxKind.ConditionalExpression:
case SyntaxKind.SpreadElementExpression:
case SyntaxKind.YieldExpression:
case SyntaxKind.Block:
case SyntaxKind.ModuleBlock:
case SyntaxKind.VariableStatement:
case SyntaxKind.ExpressionStatement:
case SyntaxKind.IfStatement:
case SyntaxKind.DoStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.ForStatement:
case SyntaxKind.ForInStatement:
case SyntaxKind.ForOfStatement:
case SyntaxKind.ContinueStatement:
case SyntaxKind.BreakStatement:
case SyntaxKind.ReturnStatement:
case SyntaxKind.SwitchStatement:
case SyntaxKind.CaseBlock:
case SyntaxKind.CaseClause:
case SyntaxKind.DefaultClause:
case SyntaxKind.LabeledStatement:
case SyntaxKind.ThrowStatement:
case SyntaxKind.TryStatement:
case SyntaxKind.CatchClause:
case SyntaxKind.VariableDeclaration:
case SyntaxKind.VariableDeclarationList:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.HeritageClause:
case SyntaxKind.ExpressionWithTypeArguments:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.ExportAssignment:
case SyntaxKind.SourceFile:
case SyntaxKind.JsxExpression:
case SyntaxKind.JsxElement:
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.JsxAttribute:
case SyntaxKind.JsxSpreadAttribute:
case SyntaxKind.JsxOpeningElement:
forEachChild(node, checkFunctionAndClassExpressionBodies);
break;
function checkNodeDeferred(node: Node) {
if (deferredNodes) {
deferredNodes.push(node);
}
}
function checkDeferredNodes() {
for (const node of deferredNodes) {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
checkFunctionExpressionOrObjectLiteralMethodDeferred(<FunctionExpression>node);
break;
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
checkAccessorDeferred(<AccessorDeclaration>node);
break;
case SyntaxKind.ClassExpression:
checkClassExpressionDeferred(<ClassExpression>node);
break;
}
}
}
@@ -14613,8 +14740,10 @@ namespace ts {
emitAwaiter = false;
potentialThisCollisions.length = 0;
deferredNodes = [];
forEach(node.statements, checkSourceElement);
checkFunctionAndClassExpressionBodies(node);
checkDeferredNodes();
deferredNodes = undefined;
if (isExternalOrCommonJsModule(node)) {
checkExternalModuleExports(node);
+9 -1
View File
@@ -1691,7 +1691,7 @@
"category": "Error",
"code": 2528
},
"JSX element attributes type '{0}' must be an object type.": {
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600
},
@@ -1759,6 +1759,14 @@
"category": "Error",
"code": 2658
},
"'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.": {
"category": "Error",
"code": 2659
},
"'super' can only be referenced in members of derived classes or object literal expressions.": {
"category": "Error",
"code": 2660
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
+15
View File
@@ -1723,6 +1723,7 @@ namespace ts {
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
getSymbolAtLocation(node: Node): Symbol;
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
getShorthandAssignmentValueSymbol(location: Node): Symbol;
getTypeAtLocation(node: Node): Type;
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
@@ -2017,6 +2018,7 @@ namespace ts {
type?: Type; // Type of value symbol
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
inferredClassType?: Type; // Type of an inferred ES5 class
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic)
mapper?: TypeMapper; // Type mapper for instantiation alias
referenced?: boolean; // True if alias symbol has been referenced as a value
@@ -2316,6 +2318,19 @@ namespace ts {
// It is optional because in contextual signature instantiation, nothing fails
}
/* @internal */
export const enum SpecialPropertyAssignmentKind {
None,
/// exports.name = expr
ExportsProperty,
/// module.exports = expr
ModuleExports,
/// className.prototype.name = expr
PrototypeProperty,
/// this.name = expr
ThisProperty
}
export interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;
+63 -54
View File
@@ -775,26 +775,38 @@ namespace ts {
}
}
export function getSuperContainer(node: Node, includeFunctions: boolean): Node {
/**
* Given an super call\property node returns a closest node where either
* - super call\property is legal in the node and not legal in the parent node the node.
* i.e. super call is legal in constructor but not legal in the class body.
* - node is arrow function (so caller might need to call getSuperContainer in case if he needs to climb higher)
* - super call\property is definitely illegal in the node (but might be legal in some subnode)
* i.e. super property access is illegal in function declaration but can be legal in the statement list
*/
export function getSuperContainer(node: Node, stopOnFunctions: boolean): Node {
while (true) {
node = node.parent;
if (!node) return node;
if (!node) {
return node;
}
switch (node.kind) {
case SyntaxKind.ComputedPropertyName:
// If the grandparent node is an object literal (as opposed to a class),
// then the computed property is not a 'super' container.
// A computed property name in a class needs to be a super container
// so that we can error on it.
if (isClassLike(node.parent.parent)) {
return node;
}
// If this is a computed property, then the parent should not
// make it a super container. The parent might be a property
// in an object literal, like a method or accessor. But in order for
// such a parent to be a super container, the reference must be in
// the *body* of the container.
node = node.parent;
break;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
if (!stopOnFunctions) {
continue;
}
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node;
case SyntaxKind.Decorator:
// Decorators are always applied outside of the body of a class or method.
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
@@ -808,20 +820,6 @@ namespace ts {
node = node.parent;
}
break;
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
if (!includeFunctions) {
continue;
}
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node;
}
}
}
@@ -1068,33 +1066,40 @@ namespace ts {
(<CallExpression>expression).arguments[0].kind === SyntaxKind.StringLiteral;
}
/**
* Returns true if the node is an assignment to a property on the identifier 'exports'.
* This function does not test if the node is in a JavaScript file or not.
*/
export function isExportsPropertyAssignment(expression: Node): boolean {
// of the form 'exports.name = expr' where 'name' and 'expr' are arbitrary
return isInJavaScriptFile(expression) &&
(expression.kind === SyntaxKind.BinaryExpression) &&
((<BinaryExpression>expression).operatorToken.kind === SyntaxKind.EqualsToken) &&
((<BinaryExpression>expression).left.kind === SyntaxKind.PropertyAccessExpression) &&
((<PropertyAccessExpression>(<BinaryExpression>expression).left).expression.kind === SyntaxKind.Identifier) &&
((<Identifier>((<PropertyAccessExpression>(<BinaryExpression>expression).left).expression)).text === "exports");
}
/// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property
/// assignments we treat as special in the binder
export function getSpecialPropertyAssignmentKind(expression: Node): SpecialPropertyAssignmentKind {
if (expression.kind !== SyntaxKind.BinaryExpression) {
return SpecialPropertyAssignmentKind.None;
}
const expr = <BinaryExpression>expression;
if (expr.operatorToken.kind !== SyntaxKind.EqualsToken || expr.left.kind !== SyntaxKind.PropertyAccessExpression) {
return SpecialPropertyAssignmentKind.None;
}
const lhs = <PropertyAccessExpression>expr.left;
if (lhs.expression.kind === SyntaxKind.Identifier) {
const lhsId = <Identifier>lhs.expression;
if (lhsId.text === "exports") {
// exports.name = expr
return SpecialPropertyAssignmentKind.ExportsProperty;
}
else if (lhsId.text === "module" && lhs.name.text === "exports") {
// module.exports = expr
return SpecialPropertyAssignmentKind.ModuleExports;
}
}
else if (lhs.expression.kind === SyntaxKind.ThisKeyword) {
return SpecialPropertyAssignmentKind.ThisProperty;
}
else if (lhs.expression.kind === SyntaxKind.PropertyAccessExpression) {
// chained dot, e.g. x.y.z = expr; this var is the 'x.y' part
const innerPropertyAccess = <PropertyAccessExpression>lhs.expression;
if (innerPropertyAccess.expression.kind === SyntaxKind.Identifier && innerPropertyAccess.name.text === "prototype") {
return SpecialPropertyAssignmentKind.PrototypeProperty;
}
}
/**
* Returns true if the node is an assignment to the property access expression 'module.exports'.
* This function does not test if the node is in a JavaScript file or not.
*/
export function isModuleExportsAssignment(expression: Node): boolean {
// of the form 'module.exports = expr' where 'expr' is arbitrary
return isInJavaScriptFile(expression) &&
(expression.kind === SyntaxKind.BinaryExpression) &&
((<BinaryExpression>expression).operatorToken.kind === SyntaxKind.EqualsToken) &&
((<BinaryExpression>expression).left.kind === SyntaxKind.PropertyAccessExpression) &&
((<PropertyAccessExpression>(<BinaryExpression>expression).left).expression.kind === SyntaxKind.Identifier) &&
((<Identifier>((<PropertyAccessExpression>(<BinaryExpression>expression).left).expression)).text === "module") &&
((<PropertyAccessExpression>(<BinaryExpression>expression).left).name.text === "exports");
return SpecialPropertyAssignmentKind.None;
}
export function getExternalModuleName(node: Node): Expression {
@@ -2741,4 +2746,8 @@ namespace ts {
}
}
}
export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean {
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
}
}
+22 -4
View File
@@ -1162,7 +1162,7 @@ namespace FourSlash {
public printCurrentQuickInfo() {
const quickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
Harness.IO.log(JSON.stringify(quickInfo));
Harness.IO.log("Quick Info: " + quickInfo.displayParts.map(part => part.text).join(""));
}
public printErrorList() {
@@ -1204,12 +1204,26 @@ namespace FourSlash {
public printMemberListMembers() {
const members = this.getMemberListAtCaret();
Harness.IO.log(JSON.stringify(members));
this.printMembersOrCompletions(members);
}
public printCompletionListMembers() {
const completions = this.getCompletionListAtCaret();
Harness.IO.log(JSON.stringify(completions));
this.printMembersOrCompletions(completions);
}
private printMembersOrCompletions(info: ts.CompletionInfo) {
function pad(s: string, length: number) {
return s + new Array(length - s.length + 1).join(" ");
}
function max<T>(arr: T[], selector: (x: T) => number): number {
return arr.reduce((prev, x) => Math.max(prev, selector(x)), 0);
}
const longestNameLength = max(info.entries, m => m.name.length);
const longestKindLength = max(info.entries, m => m.kind.length);
info.entries.sort((m, n) => m.sortText > n.sortText ? 1 : m.sortText < n.sortText ? -1 : m.name > n.name ? 1 : m.name < n.name ? -1 : 0);
const membersString = info.entries.map(m => `${pad(m.name, longestNameLength)} ${pad(m.kind, longestKindLength)} ${m.kindModifiers}`).join("\n");
Harness.IO.log(membersString);
}
public printReferences() {
@@ -2768,6 +2782,10 @@ namespace FourSlashInterface {
this.state.verifyCompletionListItemsCountIsGreaterThan(count, this.negative);
}
public assertHasRanges(ranges: FourSlash.Range[]) {
assert(ranges.length !== 0, "Array of ranges is expected to be non-empty");
}
public completionListIsEmpty() {
this.state.verifyCompletionListIsEmpty(this.negative);
}
@@ -3287,4 +3305,4 @@ namespace FourSlashInterface {
};
}
}
}
}
+545 -537
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,40 @@
//// [circularTypeofWithFunctionModule.ts]
// Repro from #6072
class Foo {}
function maker (value: string): typeof maker.Bar {
return maker.Bar;
}
namespace maker {
export class Bar extends Foo {}
}
//// [circularTypeofWithFunctionModule.js]
// Repro from #6072
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 Foo = (function () {
function Foo() {
}
return Foo;
}());
function maker(value) {
return maker.Bar;
}
var maker;
(function (maker) {
var Bar = (function (_super) {
__extends(Bar, _super);
function Bar() {
_super.apply(this, arguments);
}
return Bar;
}(Foo));
maker.Bar = Bar;
})(maker || (maker = {}));
@@ -0,0 +1,27 @@
=== tests/cases/compiler/circularTypeofWithFunctionModule.ts ===
// Repro from #6072
class Foo {}
>Foo : Symbol(Foo, Decl(circularTypeofWithFunctionModule.ts, 0, 0))
function maker (value: string): typeof maker.Bar {
>maker : Symbol(maker, Decl(circularTypeofWithFunctionModule.ts, 2, 12), Decl(circularTypeofWithFunctionModule.ts, 6, 1))
>value : Symbol(value, Decl(circularTypeofWithFunctionModule.ts, 4, 16))
>maker.Bar : Symbol(maker.Bar, Decl(circularTypeofWithFunctionModule.ts, 8, 17))
>maker : Symbol(maker, Decl(circularTypeofWithFunctionModule.ts, 2, 12), Decl(circularTypeofWithFunctionModule.ts, 6, 1))
>Bar : Symbol(maker.Bar, Decl(circularTypeofWithFunctionModule.ts, 8, 17))
return maker.Bar;
>maker.Bar : Symbol(maker.Bar, Decl(circularTypeofWithFunctionModule.ts, 8, 17))
>maker : Symbol(maker, Decl(circularTypeofWithFunctionModule.ts, 2, 12), Decl(circularTypeofWithFunctionModule.ts, 6, 1))
>Bar : Symbol(maker.Bar, Decl(circularTypeofWithFunctionModule.ts, 8, 17))
}
namespace maker {
>maker : Symbol(maker, Decl(circularTypeofWithFunctionModule.ts, 2, 12), Decl(circularTypeofWithFunctionModule.ts, 6, 1))
export class Bar extends Foo {}
>Bar : Symbol(Bar, Decl(circularTypeofWithFunctionModule.ts, 8, 17))
>Foo : Symbol(Foo, Decl(circularTypeofWithFunctionModule.ts, 0, 0))
}
@@ -0,0 +1,27 @@
=== tests/cases/compiler/circularTypeofWithFunctionModule.ts ===
// Repro from #6072
class Foo {}
>Foo : Foo
function maker (value: string): typeof maker.Bar {
>maker : typeof maker
>value : string
>maker.Bar : typeof maker.Bar
>maker : typeof maker
>Bar : typeof maker.Bar
return maker.Bar;
>maker.Bar : typeof maker.Bar
>maker : typeof maker
>Bar : typeof maker.Bar
}
namespace maker {
>maker : typeof maker
export class Bar extends Foo {}
>Bar : Bar
>Foo : Foo
}
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11,19): error TS2466: 'super' cannot be referenced in a computed property name.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts (1 errors) ====
@@ -14,7 +14,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11
//treatment of other similar violations.
[(super(), "prop")]() { }
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
!!! error TS2466: 'super' cannot be referenced in a computed property name.
};
}
}
@@ -1,4 +1,4 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11,19): error TS2466: 'super' cannot be referenced in a computed property name.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts (1 errors) ====
@@ -14,7 +14,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11
//treatment of other similar violations.
[(super(), "prop")]() { }
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
!!! error TS2466: 'super' cannot be referenced in a computed property name.
};
}
}
@@ -1,37 +0,0 @@
//// [conformanceFunctionOverloads.ts]
// Function overloads do not emit code
// Function overload signature with optional parameter
// Function overload signature with optional parameter
// Function overloads with generic and non-generic overloads
// Function overloads whose only difference is returning different unconstrained generic parameters
// Function overloads whose only difference is returning different constrained generic parameters
// Function overloads that differ only by type parameter constraints
// Function overloads with matching accessibility
// Function overloads with matching export
// Function overloads with more params than implementation signature
// Function overloads where return types are same infinitely recursive type reference
//// [conformanceFunctionOverloads.js]
// Function overloads do not emit code
// Function overload signature with optional parameter
// Function overload signature with optional parameter
// Function overloads with generic and non-generic overloads
// Function overloads whose only difference is returning different unconstrained generic parameters
// Function overloads whose only difference is returning different constrained generic parameters
// Function overloads that differ only by type parameter constraints
// Function overloads with matching accessibility
// Function overloads with matching export
// Function overloads with more params than implementation signature
// Function overloads where return types are same infinitely recursive type reference
@@ -1,25 +0,0 @@
=== tests/cases/conformance/functions/conformanceFunctionOverloads.ts ===
// Function overloads do not emit code
No type information for this code.
No type information for this code.// Function overload signature with optional parameter
No type information for this code.
No type information for this code.// Function overload signature with optional parameter
No type information for this code.
No type information for this code.// Function overloads with generic and non-generic overloads
No type information for this code.
No type information for this code.// Function overloads whose only difference is returning different unconstrained generic parameters
No type information for this code.
No type information for this code.// Function overloads whose only difference is returning different constrained generic parameters
No type information for this code.
No type information for this code.// Function overloads that differ only by type parameter constraints
No type information for this code.
No type information for this code.// Function overloads with matching accessibility
No type information for this code.
No type information for this code.// Function overloads with matching export
No type information for this code.
No type information for this code.// Function overloads with more params than implementation signature
No type information for this code.
No type information for this code.// Function overloads where return types are same infinitely recursive type reference
No type information for this code.
No type information for this code.
No type information for this code.
@@ -1,25 +0,0 @@
=== tests/cases/conformance/functions/conformanceFunctionOverloads.ts ===
// Function overloads do not emit code
No type information for this code.
No type information for this code.// Function overload signature with optional parameter
No type information for this code.
No type information for this code.// Function overload signature with optional parameter
No type information for this code.
No type information for this code.// Function overloads with generic and non-generic overloads
No type information for this code.
No type information for this code.// Function overloads whose only difference is returning different unconstrained generic parameters
No type information for this code.
No type information for this code.// Function overloads whose only difference is returning different constrained generic parameters
No type information for this code.
No type information for this code.// Function overloads that differ only by type parameter constraints
No type information for this code.
No type information for this code.// Function overloads with matching accessibility
No type information for this code.
No type information for this code.// Function overloads with matching export
No type information for this code.
No type information for this code.// Function overloads with more params than implementation signature
No type information for this code.
No type information for this code.// Function overloads where return types are same infinitely recursive type reference
No type information for this code.
No type information for this code.
No type information for this code.
@@ -1,4 +1,4 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts (1 errors) ====
@@ -9,7 +9,7 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10
class C extends S {
@super.decorator
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
method() { }
}
}
@@ -1,6 +1,6 @@
tests/cases/compiler/emitThisInSuperMethodCall.ts(10,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/emitThisInSuperMethodCall.ts(17,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/emitThisInSuperMethodCall.ts(10,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/emitThisInSuperMethodCall.ts(17,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/compiler/emitThisInSuperMethodCall.ts (3 errors) ====
@@ -15,7 +15,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super'
function inner() {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
};
}
@@ -24,7 +24,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super'
() => {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -32,7 +32,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super'
function inner() {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -0,0 +1,129 @@
tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'.
Property 'd' is missing in type 'First.E'.
tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'.
Property 'd' is missing in type 'First.E'.
tests/cases/compiler/enumAssignmentCompat3.ts(71,1): error TS2322: Type 'Nope' is not assignable to type 'E'.
tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'.
Property 'c' is missing in type 'Ab.E'.
tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'.
Property 'a' is missing in type 'Cd.E'.
tests/cases/compiler/enumAssignmentCompat3.ts(77,1): error TS2322: Type 'E' is not assignable to type 'Nope'.
tests/cases/compiler/enumAssignmentCompat3.ts(82,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'.
tests/cases/compiler/enumAssignmentCompat3.ts(83,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'.
tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'.
Property 'd' is missing in type 'First.E'.
==== tests/cases/compiler/enumAssignmentCompat3.ts (9 errors) ====
namespace First {
export enum E {
a, b, c,
}
}
namespace Abc {
export enum E {
a, b, c,
}
export enum Nope {
a, b, c,
}
}
namespace Abcd {
export enum E {
a, b, c, d,
}
}
namespace Ab {
export enum E {
a, b,
}
}
namespace Cd {
export enum E {
c, d,
}
}
namespace Const {
export const enum E {
a, b, c,
}
}
namespace Decl {
export declare enum E {
a, b, c = 3,
}
}
namespace Merged {
export enum E {
a, b,
}
export enum E {
c = 3, d,
}
}
namespace Merged2 {
export enum E {
a, b, c
}
export module E {
export let d = 5;
}
}
var abc: First.E;
var secondAbc: Abc.E;
var secondAbcd: Abcd.E;
var secondAb: Ab.E;
var secondCd: Cd.E;
var nope: Abc.Nope;
var k: Const.E;
var decl: Decl.E;
var merged: Merged.E;
var merged2: Merged2.E;
abc = secondAbc; // ok
abc = secondAbcd; // missing 'd'
~~~
!!! error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'.
!!! error TS2322: Property 'd' is missing in type 'First.E'.
abc = secondAb; // ok
abc = secondCd; // missing 'd'
~~~
!!! error TS2322: Type 'Cd.E' is not assignable to type 'First.E'.
!!! error TS2322: Property 'd' is missing in type 'First.E'.
abc = nope; // nope!
~~~
!!! error TS2322: Type 'Nope' is not assignable to type 'E'.
abc = decl; // ok
secondAbc = abc; // ok
secondAbcd = abc; // ok
secondAb = abc; // missing 'c'
~~~~~~~~
!!! error TS2322: Type 'First.E' is not assignable to type 'Ab.E'.
!!! error TS2322: Property 'c' is missing in type 'Ab.E'.
secondCd = abc; // missing 'a' and 'b'
~~~~~~~~
!!! error TS2322: Type 'First.E' is not assignable to type 'Cd.E'.
!!! error TS2322: Property 'a' is missing in type 'Cd.E'.
nope = abc; // nope!
~~~~
!!! error TS2322: Type 'E' is not assignable to type 'Nope'.
decl = abc; // ok
// const is only assignable to itself
k = k;
abc = k; // error
~~~
!!! error TS2322: Type 'Const.E' is not assignable to type 'First.E'.
k = abc;
~
!!! error TS2322: Type 'First.E' is not assignable to type 'Const.E'.
// merged enums compare all their members
abc = merged; // missing 'd'
~~~
!!! error TS2322: Type 'Merged.E' is not assignable to type 'First.E'.
!!! error TS2322: Property 'd' is missing in type 'First.E'.
merged = abc; // ok
abc = merged2; // ok
merged2 = abc; // ok
@@ -0,0 +1,202 @@
//// [enumAssignmentCompat3.ts]
namespace First {
export enum E {
a, b, c,
}
}
namespace Abc {
export enum E {
a, b, c,
}
export enum Nope {
a, b, c,
}
}
namespace Abcd {
export enum E {
a, b, c, d,
}
}
namespace Ab {
export enum E {
a, b,
}
}
namespace Cd {
export enum E {
c, d,
}
}
namespace Const {
export const enum E {
a, b, c,
}
}
namespace Decl {
export declare enum E {
a, b, c = 3,
}
}
namespace Merged {
export enum E {
a, b,
}
export enum E {
c = 3, d,
}
}
namespace Merged2 {
export enum E {
a, b, c
}
export module E {
export let d = 5;
}
}
var abc: First.E;
var secondAbc: Abc.E;
var secondAbcd: Abcd.E;
var secondAb: Ab.E;
var secondCd: Cd.E;
var nope: Abc.Nope;
var k: Const.E;
var decl: Decl.E;
var merged: Merged.E;
var merged2: Merged2.E;
abc = secondAbc; // ok
abc = secondAbcd; // missing 'd'
abc = secondAb; // ok
abc = secondCd; // missing 'd'
abc = nope; // nope!
abc = decl; // ok
secondAbc = abc; // ok
secondAbcd = abc; // ok
secondAb = abc; // missing 'c'
secondCd = abc; // missing 'a' and 'b'
nope = abc; // nope!
decl = abc; // ok
// const is only assignable to itself
k = k;
abc = k; // error
k = abc;
// merged enums compare all their members
abc = merged; // missing 'd'
merged = abc; // ok
abc = merged2; // ok
merged2 = abc; // ok
//// [enumAssignmentCompat3.js]
var First;
(function (First) {
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
E[E["c"] = 2] = "c";
})(First.E || (First.E = {}));
var E = First.E;
})(First || (First = {}));
var Abc;
(function (Abc) {
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
E[E["c"] = 2] = "c";
})(Abc.E || (Abc.E = {}));
var E = Abc.E;
(function (Nope) {
Nope[Nope["a"] = 0] = "a";
Nope[Nope["b"] = 1] = "b";
Nope[Nope["c"] = 2] = "c";
})(Abc.Nope || (Abc.Nope = {}));
var Nope = Abc.Nope;
})(Abc || (Abc = {}));
var Abcd;
(function (Abcd) {
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
E[E["c"] = 2] = "c";
E[E["d"] = 3] = "d";
})(Abcd.E || (Abcd.E = {}));
var E = Abcd.E;
})(Abcd || (Abcd = {}));
var Ab;
(function (Ab) {
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
})(Ab.E || (Ab.E = {}));
var E = Ab.E;
})(Ab || (Ab = {}));
var Cd;
(function (Cd) {
(function (E) {
E[E["c"] = 0] = "c";
E[E["d"] = 1] = "d";
})(Cd.E || (Cd.E = {}));
var E = Cd.E;
})(Cd || (Cd = {}));
var Decl;
(function (Decl) {
})(Decl || (Decl = {}));
var Merged;
(function (Merged) {
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
})(Merged.E || (Merged.E = {}));
var E = Merged.E;
(function (E) {
E[E["c"] = 3] = "c";
E[E["d"] = 4] = "d";
})(Merged.E || (Merged.E = {}));
var E = Merged.E;
})(Merged || (Merged = {}));
var Merged2;
(function (Merged2) {
(function (E) {
E[E["a"] = 0] = "a";
E[E["b"] = 1] = "b";
E[E["c"] = 2] = "c";
})(Merged2.E || (Merged2.E = {}));
var E = Merged2.E;
var E;
(function (E) {
E.d = 5;
})(E = Merged2.E || (Merged2.E = {}));
})(Merged2 || (Merged2 = {}));
var abc;
var secondAbc;
var secondAbcd;
var secondAb;
var secondCd;
var nope;
var k;
var decl;
var merged;
var merged2;
abc = secondAbc; // ok
abc = secondAbcd; // missing 'd'
abc = secondAb; // ok
abc = secondCd; // missing 'd'
abc = nope; // nope!
abc = decl; // ok
secondAbc = abc; // ok
secondAbcd = abc; // ok
secondAb = abc; // missing 'c'
secondCd = abc; // missing 'a' and 'b'
nope = abc; // nope!
decl = abc; // ok
// const is only assignable to itself
k = k;
abc = k; // error
k = abc;
// merged enums compare all their members
abc = merged; // missing 'd'
merged = abc; // ok
abc = merged2; // ok
merged2 = abc; // ok
@@ -1,12 +1,12 @@
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(4,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(18,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(22,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(26,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(22,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(26,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(58,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(62,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
@@ -27,50 +27,50 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T
fn() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
//super call in class accessor (get and set) with no base type
get foo() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
return null;
}
set foo(v) {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
//super call in class member initializer with no base type
p = super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
//super call in static class member function with no base type
static fn() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
//super call in static class member initializer with no base type
static k = super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
//super call in static class accessor (get and set) with no base type
static get q() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
return null;
}
static set q(n) {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
}
@@ -15,8 +15,8 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(65,23): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(68,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(69,19): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(73,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(76,40): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(73,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(76,40): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(87,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(91,23): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(94,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
@@ -34,8 +34,8 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(120,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(121,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(122,9): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts (38 errors) ====
@@ -147,12 +147,12 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
function inner() {
super.publicFunc();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
var x = {
test: function () { return super.publicFunc(); }
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -239,7 +239,7 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess
// In object literal
var obj = { n: super.wat, p: super.foo() };
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
@@ -0,0 +1,10 @@
tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts(1,10): error TS2394: Overload signature is not compatible with function implementation.
==== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts (1 errors) ====
function f(x: string): number;
~
!!! error TS2394: Overload signature is not compatible with function implementation.
function f(x: string): void {
return;
}
@@ -0,0 +1,10 @@
//// [functionOverloadCompatibilityWithVoid01.ts]
function f(x: string): number;
function f(x: string): void {
return;
}
//// [functionOverloadCompatibilityWithVoid01.js]
function f(x) {
return;
}
@@ -0,0 +1,10 @@
//// [functionOverloadCompatibilityWithVoid02.ts]
function f(x: string): void;
function f(x: string): number {
return 0;
}
//// [functionOverloadCompatibilityWithVoid02.js]
function f(x) {
return 0;
}
@@ -0,0 +1,11 @@
=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts ===
function f(x: string): void;
>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 28))
>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 11))
function f(x: string): number {
>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 28))
>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid02.ts, 1, 11))
return 0;
}
@@ -0,0 +1,12 @@
=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts ===
function f(x: string): void;
>f : (x: string) => void
>x : string
function f(x: string): number {
>f : (x: string) => void
>x : string
return 0;
>0 : number
}
@@ -0,0 +1,10 @@
//// [functionOverloadCompatibilityWithVoid03.ts]
function f(x: string): void;
function f(x: string): void {
return;
}
//// [functionOverloadCompatibilityWithVoid03.js]
function f(x) {
return;
}
@@ -0,0 +1,11 @@
=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts ===
function f(x: string): void;
>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 28))
>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 11))
function f(x: string): void {
>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 28))
>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid03.ts, 1, 11))
return;
}
@@ -0,0 +1,11 @@
=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts ===
function f(x: string): void;
>f : (x: string) => void
>x : string
function f(x: string): void {
>f : (x: string) => void
>x : string
return;
}
@@ -1,10 +0,0 @@
tests/cases/compiler/functionOverloads22.ts(2,10): error TS2394: Overload signature is not compatible with function implementation.
==== tests/cases/compiler/functionOverloads22.ts (1 errors) ====
function foo(bar:number):{a:number;}[];
function foo(bar:string):{a:number; b:string;}[];
~~~
!!! error TS2394: Overload signature is not compatible with function implementation.
function foo(bar:any):{a:any;b?:any;}[] { return [{a:""}] }
@@ -0,0 +1,19 @@
=== tests/cases/compiler/functionOverloads22.ts ===
function foo(bar:number):{a:number;}[];
>foo : Symbol(foo, Decl(functionOverloads22.ts, 0, 0), Decl(functionOverloads22.ts, 0, 39), Decl(functionOverloads22.ts, 1, 49))
>bar : Symbol(bar, Decl(functionOverloads22.ts, 0, 13))
>a : Symbol(a, Decl(functionOverloads22.ts, 0, 26))
function foo(bar:string):{a:number; b:string;}[];
>foo : Symbol(foo, Decl(functionOverloads22.ts, 0, 0), Decl(functionOverloads22.ts, 0, 39), Decl(functionOverloads22.ts, 1, 49))
>bar : Symbol(bar, Decl(functionOverloads22.ts, 1, 13))
>a : Symbol(a, Decl(functionOverloads22.ts, 1, 26))
>b : Symbol(b, Decl(functionOverloads22.ts, 1, 35))
function foo(bar:any):{a:any;b?:any;}[] { return [{a:""}] }
>foo : Symbol(foo, Decl(functionOverloads22.ts, 0, 0), Decl(functionOverloads22.ts, 0, 39), Decl(functionOverloads22.ts, 1, 49))
>bar : Symbol(bar, Decl(functionOverloads22.ts, 2, 13))
>a : Symbol(a, Decl(functionOverloads22.ts, 2, 23))
>b : Symbol(b, Decl(functionOverloads22.ts, 2, 29))
>a : Symbol(a, Decl(functionOverloads22.ts, 2, 51))
@@ -0,0 +1,22 @@
=== tests/cases/compiler/functionOverloads22.ts ===
function foo(bar:number):{a:number;}[];
>foo : { (bar: number): { a: number; }[]; (bar: string): { a: number; b: string; }[]; }
>bar : number
>a : number
function foo(bar:string):{a:number; b:string;}[];
>foo : { (bar: number): { a: number; }[]; (bar: string): { a: number; b: string; }[]; }
>bar : string
>a : number
>b : string
function foo(bar:any):{a:any;b?:any;}[] { return [{a:""}] }
>foo : { (bar: number): { a: number; }[]; (bar: string): { a: number; b: string; }[]; }
>bar : any
>a : any
>b : any
>[{a:""}] : { a: string; }[]
>{a:""} : { a: string; }
>a : string
>"" : string
@@ -0,0 +1,24 @@
//// [functionOverloads43.ts]
function foo(bar: { a:number }[]): number;
function foo(bar: { a:string }[]): string;
function foo([x]: { a:number | string }[]): string | number {
if (x) {
return x.a;
}
return undefined;
}
var x = foo([{a: "str"}]);
var y = foo([{a: 100}]);
//// [functionOverloads43.js]
function foo(_a) {
var x = _a[0];
if (x) {
return x.a;
}
return undefined;
}
var x = foo([{ a: "str" }]);
var y = foo([{ a: 100 }]);
@@ -0,0 +1,39 @@
=== tests/cases/compiler/functionOverloads43.ts ===
function foo(bar: { a:number }[]): number;
>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42))
>bar : Symbol(bar, Decl(functionOverloads43.ts, 0, 13))
>a : Symbol(a, Decl(functionOverloads43.ts, 0, 19))
function foo(bar: { a:string }[]): string;
>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42))
>bar : Symbol(bar, Decl(functionOverloads43.ts, 1, 13))
>a : Symbol(a, Decl(functionOverloads43.ts, 1, 19))
function foo([x]: { a:number | string }[]): string | number {
>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42))
>x : Symbol(x, Decl(functionOverloads43.ts, 2, 14))
>a : Symbol(a, Decl(functionOverloads43.ts, 2, 19))
if (x) {
>x : Symbol(x, Decl(functionOverloads43.ts, 2, 14))
return x.a;
>x.a : Symbol(a, Decl(functionOverloads43.ts, 2, 19))
>x : Symbol(x, Decl(functionOverloads43.ts, 2, 14))
>a : Symbol(a, Decl(functionOverloads43.ts, 2, 19))
}
return undefined;
>undefined : Symbol(undefined)
}
var x = foo([{a: "str"}]);
>x : Symbol(x, Decl(functionOverloads43.ts, 10, 3))
>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42))
>a : Symbol(a, Decl(functionOverloads43.ts, 10, 14))
var y = foo([{a: 100}]);
>y : Symbol(y, Decl(functionOverloads43.ts, 11, 3))
>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42))
>a : Symbol(a, Decl(functionOverloads43.ts, 11, 14))
@@ -0,0 +1,47 @@
=== tests/cases/compiler/functionOverloads43.ts ===
function foo(bar: { a:number }[]): number;
>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; }
>bar : { a: number; }[]
>a : number
function foo(bar: { a:string }[]): string;
>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; }
>bar : { a: string; }[]
>a : string
function foo([x]: { a:number | string }[]): string | number {
>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; }
>x : { a: number | string; }
>a : number | string
if (x) {
>x : { a: number | string; }
return x.a;
>x.a : number | string
>x : { a: number | string; }
>a : number | string
}
return undefined;
>undefined : undefined
}
var x = foo([{a: "str"}]);
>x : string
>foo([{a: "str"}]) : string
>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; }
>[{a: "str"}] : { a: string; }[]
>{a: "str"} : { a: string; }
>a : string
>"str" : string
var y = foo([{a: 100}]);
>y : number
>foo([{a: 100}]) : number
>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; }
>[{a: 100}] : { a: number; }[]
>{a: 100} : { a: number; }
>a : number
>100 : number
@@ -0,0 +1,37 @@
//// [functionOverloads44.ts]
interface Animal { animal }
interface Dog extends Animal { dog }
interface Cat extends Animal { cat }
function foo1(bar: { a:number }[]): Dog;
function foo1(bar: { a:string }[]): Animal;
function foo1([x]: { a:number | string }[]): Dog {
return undefined;
}
function foo2(bar: { a:number }[]): Cat;
function foo2(bar: { a:string }[]): Cat | Dog;
function foo2([x]: { a:number | string }[]): Cat {
return undefined;
}
var x1 = foo1([{a: "str"}]);
var y1 = foo1([{a: 100}]);
var x2 = foo2([{a: "str"}]);
var y2 = foo2([{a: 100}]);
//// [functionOverloads44.js]
function foo1(_a) {
var x = _a[0];
return undefined;
}
function foo2(_a) {
var x = _a[0];
return undefined;
}
var x1 = foo1([{ a: "str" }]);
var y1 = foo1([{ a: 100 }]);
var x2 = foo2([{ a: "str" }]);
var y2 = foo2([{ a: 100 }]);
@@ -0,0 +1,81 @@
=== tests/cases/compiler/functionOverloads44.ts ===
interface Animal { animal }
>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0))
>animal : Symbol(animal, Decl(functionOverloads44.ts, 0, 18))
interface Dog extends Animal { dog }
>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27))
>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0))
>dog : Symbol(dog, Decl(functionOverloads44.ts, 1, 30))
interface Cat extends Animal { cat }
>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36))
>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0))
>cat : Symbol(cat, Decl(functionOverloads44.ts, 2, 30))
function foo1(bar: { a:number }[]): Dog;
>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43))
>bar : Symbol(bar, Decl(functionOverloads44.ts, 4, 14))
>a : Symbol(a, Decl(functionOverloads44.ts, 4, 20))
>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27))
function foo1(bar: { a:string }[]): Animal;
>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43))
>bar : Symbol(bar, Decl(functionOverloads44.ts, 5, 14))
>a : Symbol(a, Decl(functionOverloads44.ts, 5, 20))
>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0))
function foo1([x]: { a:number | string }[]): Dog {
>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43))
>x : Symbol(x, Decl(functionOverloads44.ts, 6, 15))
>a : Symbol(a, Decl(functionOverloads44.ts, 6, 20))
>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27))
return undefined;
>undefined : Symbol(undefined)
}
function foo2(bar: { a:number }[]): Cat;
>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46))
>bar : Symbol(bar, Decl(functionOverloads44.ts, 10, 14))
>a : Symbol(a, Decl(functionOverloads44.ts, 10, 20))
>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36))
function foo2(bar: { a:string }[]): Cat | Dog;
>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46))
>bar : Symbol(bar, Decl(functionOverloads44.ts, 11, 14))
>a : Symbol(a, Decl(functionOverloads44.ts, 11, 20))
>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36))
>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27))
function foo2([x]: { a:number | string }[]): Cat {
>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46))
>x : Symbol(x, Decl(functionOverloads44.ts, 12, 15))
>a : Symbol(a, Decl(functionOverloads44.ts, 12, 20))
>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36))
return undefined;
>undefined : Symbol(undefined)
}
var x1 = foo1([{a: "str"}]);
>x1 : Symbol(x1, Decl(functionOverloads44.ts, 17, 3))
>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43))
>a : Symbol(a, Decl(functionOverloads44.ts, 17, 16))
var y1 = foo1([{a: 100}]);
>y1 : Symbol(y1, Decl(functionOverloads44.ts, 18, 3))
>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43))
>a : Symbol(a, Decl(functionOverloads44.ts, 18, 16))
var x2 = foo2([{a: "str"}]);
>x2 : Symbol(x2, Decl(functionOverloads44.ts, 20, 3))
>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46))
>a : Symbol(a, Decl(functionOverloads44.ts, 20, 16))
var y2 = foo2([{a: 100}]);
>y2 : Symbol(y2, Decl(functionOverloads44.ts, 21, 3))
>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46))
>a : Symbol(a, Decl(functionOverloads44.ts, 21, 16))
@@ -0,0 +1,97 @@
=== tests/cases/compiler/functionOverloads44.ts ===
interface Animal { animal }
>Animal : Animal
>animal : any
interface Dog extends Animal { dog }
>Dog : Dog
>Animal : Animal
>dog : any
interface Cat extends Animal { cat }
>Cat : Cat
>Animal : Animal
>cat : any
function foo1(bar: { a:number }[]): Dog;
>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; }
>bar : { a: number; }[]
>a : number
>Dog : Dog
function foo1(bar: { a:string }[]): Animal;
>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; }
>bar : { a: string; }[]
>a : string
>Animal : Animal
function foo1([x]: { a:number | string }[]): Dog {
>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; }
>x : { a: number | string; }
>a : number | string
>Dog : Dog
return undefined;
>undefined : undefined
}
function foo2(bar: { a:number }[]): Cat;
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; }
>bar : { a: number; }[]
>a : number
>Cat : Cat
function foo2(bar: { a:string }[]): Cat | Dog;
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; }
>bar : { a: string; }[]
>a : string
>Cat : Cat
>Dog : Dog
function foo2([x]: { a:number | string }[]): Cat {
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; }
>x : { a: number | string; }
>a : number | string
>Cat : Cat
return undefined;
>undefined : undefined
}
var x1 = foo1([{a: "str"}]);
>x1 : Animal
>foo1([{a: "str"}]) : Animal
>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; }
>[{a: "str"}] : { a: string; }[]
>{a: "str"} : { a: string; }
>a : string
>"str" : string
var y1 = foo1([{a: 100}]);
>y1 : Dog
>foo1([{a: 100}]) : Dog
>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; }
>[{a: 100}] : { a: number; }[]
>{a: 100} : { a: number; }
>a : number
>100 : number
var x2 = foo2([{a: "str"}]);
>x2 : Cat | Dog
>foo2([{a: "str"}]) : Cat | Dog
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; }
>[{a: "str"}] : { a: string; }[]
>{a: "str"} : { a: string; }
>a : string
>"str" : string
var y2 = foo2([{a: 100}]);
>y2 : Cat
>foo2([{a: 100}]) : Cat
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; }
>[{a: 100}] : { a: number; }[]
>{a: 100} : { a: number; }
>a : number
>100 : number
@@ -0,0 +1,37 @@
//// [functionOverloads45.ts]
interface Animal { animal }
interface Dog extends Animal { dog }
interface Cat extends Animal { cat }
function foo1(bar: { a:number }[]): Cat;
function foo1(bar: { a:string }[]): Dog;
function foo1([x]: { a:number | string }[]): Animal {
return undefined;
}
function foo2(bar: { a:number }[]): Cat;
function foo2(bar: { a:string }[]): Dog;
function foo2([x]: { a:number | string }[]): Cat | Dog {
return undefined;
}
var x1 = foo1([{a: "str"}]);
var y1 = foo1([{a: 100}]);
var x2 = foo2([{a: "str"}]);
var y2 = foo2([{a: 100}]);
//// [functionOverloads45.js]
function foo1(_a) {
var x = _a[0];
return undefined;
}
function foo2(_a) {
var x = _a[0];
return undefined;
}
var x1 = foo1([{ a: "str" }]);
var y1 = foo1([{ a: 100 }]);
var x2 = foo2([{ a: "str" }]);
var y2 = foo2([{ a: 100 }]);
@@ -0,0 +1,81 @@
=== tests/cases/compiler/functionOverloads45.ts ===
interface Animal { animal }
>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0))
>animal : Symbol(animal, Decl(functionOverloads45.ts, 0, 18))
interface Dog extends Animal { dog }
>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27))
>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0))
>dog : Symbol(dog, Decl(functionOverloads45.ts, 1, 30))
interface Cat extends Animal { cat }
>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36))
>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0))
>cat : Symbol(cat, Decl(functionOverloads45.ts, 2, 30))
function foo1(bar: { a:number }[]): Cat;
>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40))
>bar : Symbol(bar, Decl(functionOverloads45.ts, 4, 14))
>a : Symbol(a, Decl(functionOverloads45.ts, 4, 20))
>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36))
function foo1(bar: { a:string }[]): Dog;
>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40))
>bar : Symbol(bar, Decl(functionOverloads45.ts, 5, 14))
>a : Symbol(a, Decl(functionOverloads45.ts, 5, 20))
>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27))
function foo1([x]: { a:number | string }[]): Animal {
>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40))
>x : Symbol(x, Decl(functionOverloads45.ts, 6, 15))
>a : Symbol(a, Decl(functionOverloads45.ts, 6, 20))
>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0))
return undefined;
>undefined : Symbol(undefined)
}
function foo2(bar: { a:number }[]): Cat;
>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40))
>bar : Symbol(bar, Decl(functionOverloads45.ts, 10, 14))
>a : Symbol(a, Decl(functionOverloads45.ts, 10, 20))
>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36))
function foo2(bar: { a:string }[]): Dog;
>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40))
>bar : Symbol(bar, Decl(functionOverloads45.ts, 11, 14))
>a : Symbol(a, Decl(functionOverloads45.ts, 11, 20))
>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27))
function foo2([x]: { a:number | string }[]): Cat | Dog {
>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40))
>x : Symbol(x, Decl(functionOverloads45.ts, 12, 15))
>a : Symbol(a, Decl(functionOverloads45.ts, 12, 20))
>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36))
>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27))
return undefined;
>undefined : Symbol(undefined)
}
var x1 = foo1([{a: "str"}]);
>x1 : Symbol(x1, Decl(functionOverloads45.ts, 17, 3))
>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40))
>a : Symbol(a, Decl(functionOverloads45.ts, 17, 16))
var y1 = foo1([{a: 100}]);
>y1 : Symbol(y1, Decl(functionOverloads45.ts, 18, 3))
>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40))
>a : Symbol(a, Decl(functionOverloads45.ts, 18, 16))
var x2 = foo2([{a: "str"}]);
>x2 : Symbol(x2, Decl(functionOverloads45.ts, 20, 3))
>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40))
>a : Symbol(a, Decl(functionOverloads45.ts, 20, 16))
var y2 = foo2([{a: 100}]);
>y2 : Symbol(y2, Decl(functionOverloads45.ts, 21, 3))
>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40))
>a : Symbol(a, Decl(functionOverloads45.ts, 21, 16))
@@ -0,0 +1,97 @@
=== tests/cases/compiler/functionOverloads45.ts ===
interface Animal { animal }
>Animal : Animal
>animal : any
interface Dog extends Animal { dog }
>Dog : Dog
>Animal : Animal
>dog : any
interface Cat extends Animal { cat }
>Cat : Cat
>Animal : Animal
>cat : any
function foo1(bar: { a:number }[]): Cat;
>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>bar : { a: number; }[]
>a : number
>Cat : Cat
function foo1(bar: { a:string }[]): Dog;
>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>bar : { a: string; }[]
>a : string
>Dog : Dog
function foo1([x]: { a:number | string }[]): Animal {
>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>x : { a: number | string; }
>a : number | string
>Animal : Animal
return undefined;
>undefined : undefined
}
function foo2(bar: { a:number }[]): Cat;
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>bar : { a: number; }[]
>a : number
>Cat : Cat
function foo2(bar: { a:string }[]): Dog;
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>bar : { a: string; }[]
>a : string
>Dog : Dog
function foo2([x]: { a:number | string }[]): Cat | Dog {
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>x : { a: number | string; }
>a : number | string
>Cat : Cat
>Dog : Dog
return undefined;
>undefined : undefined
}
var x1 = foo1([{a: "str"}]);
>x1 : Dog
>foo1([{a: "str"}]) : Dog
>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>[{a: "str"}] : { a: string; }[]
>{a: "str"} : { a: string; }
>a : string
>"str" : string
var y1 = foo1([{a: 100}]);
>y1 : Cat
>foo1([{a: 100}]) : Cat
>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>[{a: 100}] : { a: number; }[]
>{a: 100} : { a: number; }
>a : number
>100 : number
var x2 = foo2([{a: "str"}]);
>x2 : Dog
>foo2([{a: "str"}]) : Dog
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>[{a: "str"}] : { a: string; }[]
>{a: "str"} : { a: string; }
>a : string
>"str" : string
var y2 = foo2([{a: 100}]);
>y2 : Cat
>foo2([{a: 100}]) : Cat
>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; }
>[{a: 100}] : { a: number; }[]
>{a: 100} : { a: number; }
>a : number
>100 : number
@@ -1,20 +1,11 @@
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'.
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ====
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (1 errors) ====
return this.edit(role)
~~~~~~
!!! error TS1108: A 'return' statement can only be used within a function body.
~~~~
!!! error TS2304: Cannot find name 'role'.
.then((role: Role) =>
~~~~
!!! error TS2304: Cannot find name 'Role'.
this.roleService.add(role)
.then((data: ng.IHttpPromiseCallbackArg<Role>) => data.data));
~~
!!! error TS2503: Cannot find namespace 'ng'.
@@ -6,9 +6,8 @@ return this.edit(role)
//// [multiLinePropertyAccessAndArrowFunctionIndent1.js]
var _this = this;
return this.edit(role)
.then(function (role) {
return _this.roleService.add(role)
return this.roleService.add(role)
.then(function (data) { return data.data; });
});
@@ -1,19 +0,0 @@
tests/cases/compiler/overloadOnConstConstraintChecks4.ts(9,10): error TS2394: Overload signature is not compatible with function implementation.
==== tests/cases/compiler/overloadOnConstConstraintChecks4.ts (1 errors) ====
class Z { }
class A extends Z { private x = 1 }
class B extends A {}
class C extends A {
public foo() { }
}
function foo(name: 'hi'): B;
function foo(name: 'bye'): C;
function foo(name: string): A; // error
~~~
!!! error TS2394: Overload signature is not compatible with function implementation.
function foo(name: any): Z {
return null;
}
@@ -7,7 +7,7 @@ class C extends A {
}
function foo(name: 'hi'): B;
function foo(name: 'bye'): C;
function foo(name: string): A; // error
function foo(name: string): A;
function foo(name: any): Z {
return null;
}
@@ -0,0 +1,43 @@
=== tests/cases/compiler/overloadOnConstConstraintChecks4.ts ===
class Z { }
>Z : Symbol(Z, Decl(overloadOnConstConstraintChecks4.ts, 0, 0))
class A extends Z { private x = 1 }
>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11))
>Z : Symbol(Z, Decl(overloadOnConstConstraintChecks4.ts, 0, 0))
>x : Symbol(x, Decl(overloadOnConstConstraintChecks4.ts, 1, 19))
class B extends A {}
>B : Symbol(B, Decl(overloadOnConstConstraintChecks4.ts, 1, 35))
>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11))
class C extends A {
>C : Symbol(C, Decl(overloadOnConstConstraintChecks4.ts, 2, 20))
>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11))
public foo() { }
>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 3, 19))
}
function foo(name: 'hi'): B;
>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30))
>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 6, 13))
>B : Symbol(B, Decl(overloadOnConstConstraintChecks4.ts, 1, 35))
function foo(name: 'bye'): C;
>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30))
>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 7, 13))
>C : Symbol(C, Decl(overloadOnConstConstraintChecks4.ts, 2, 20))
function foo(name: string): A;
>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30))
>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 8, 13))
>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11))
function foo(name: any): Z {
>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30))
>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 9, 13))
>Z : Symbol(Z, Decl(overloadOnConstConstraintChecks4.ts, 0, 0))
return null;
}
@@ -0,0 +1,45 @@
=== tests/cases/compiler/overloadOnConstConstraintChecks4.ts ===
class Z { }
>Z : Z
class A extends Z { private x = 1 }
>A : A
>Z : Z
>x : number
>1 : number
class B extends A {}
>B : B
>A : A
class C extends A {
>C : C
>A : A
public foo() { }
>foo : () => void
}
function foo(name: 'hi'): B;
>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; }
>name : "hi"
>B : B
function foo(name: 'bye'): C;
>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; }
>name : "bye"
>C : C
function foo(name: string): A;
>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; }
>name : string
>A : A
function foo(name: any): Z {
>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; }
>name : any
>Z : Z
return null;
>null : null
}
@@ -1,8 +1,7 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(6,5): error TS2304: Cannot find name 'private'.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (2 errors) ====
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (1 errors) ====
return {
~~~~~~
!!! error TS1108: A 'return' statement can only be used within a function body.
@@ -11,8 +10,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMe
// 'private' should not be considered a member variable here.
private[key] = value;
~~~~~~~
!!! error TS2304: Cannot find name 'private'.
}
@@ -20,7 +20,7 @@ function hasKind(entity: Entity, kind: "A"): entity is A;
function hasKind(entity: Entity, kind: "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is Entity;
function hasKind(entity: Entity, kind: Kind): boolean {
return kind === is;
return entity.kind === kind;
}
let x: A = {
@@ -44,7 +44,7 @@ else {
//// [stringLiteralTypesAsTags01.js]
function hasKind(entity, kind) {
return kind === is;
return entity.kind === kind;
}
var x = {
kind: "A",
@@ -0,0 +1,112 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts ===
type Kind = "A" | "B"
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0))
interface Entity {
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
kind: Kind;
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 3, 18))
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0))
}
interface A extends Entity {
>A : Symbol(A, Decl(stringLiteralTypesAsTags01.ts, 5, 1))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
kind: "A";
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 7, 28))
a: number;
>a : Symbol(a, Decl(stringLiteralTypesAsTags01.ts, 8, 14))
}
interface B extends Entity {
>B : Symbol(B, Decl(stringLiteralTypesAsTags01.ts, 10, 1))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
kind: "B";
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 12, 28))
b: string;
>b : Symbol(b, Decl(stringLiteralTypesAsTags01.ts, 13, 14))
}
function hasKind(entity: Entity, kind: "A"): entity is A;
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 17, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 17, 32))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 17, 17))
>A : Symbol(A, Decl(stringLiteralTypesAsTags01.ts, 5, 1))
function hasKind(entity: Entity, kind: "B"): entity is B;
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 18, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 18, 32))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 18, 17))
>B : Symbol(B, Decl(stringLiteralTypesAsTags01.ts, 10, 1))
function hasKind(entity: Entity, kind: Kind): entity is Entity;
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 19, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 19, 32))
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 19, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
function hasKind(entity: Entity, kind: Kind): boolean {
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 20, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 20, 32))
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0))
return entity.kind === kind;
>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags01.ts, 3, 18))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 20, 17))
>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags01.ts, 3, 18))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 20, 32))
}
let x: A = {
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
>A : Symbol(A, Decl(stringLiteralTypesAsTags01.ts, 5, 1))
kind: "A",
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 24, 12))
a: 100,
>a : Symbol(a, Decl(stringLiteralTypesAsTags01.ts, 25, 14))
}
if (hasKind(x, "A")) {
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63))
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
let a = x;
>a : Symbol(a, Decl(stringLiteralTypesAsTags01.ts, 30, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
}
else {
let b = x;
>b : Symbol(b, Decl(stringLiteralTypesAsTags01.ts, 33, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
}
if (!hasKind(x, "B")) {
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63))
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
let c = x;
>c : Symbol(c, Decl(stringLiteralTypesAsTags01.ts, 37, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
}
else {
let d = x;
>d : Symbol(d, Decl(stringLiteralTypesAsTags01.ts, 40, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3))
}
@@ -0,0 +1,121 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts ===
type Kind = "A" | "B"
>Kind : "A" | "B"
interface Entity {
>Entity : Entity
kind: Kind;
>kind : "A" | "B"
>Kind : "A" | "B"
}
interface A extends Entity {
>A : A
>Entity : Entity
kind: "A";
>kind : "A"
a: number;
>a : number
}
interface B extends Entity {
>B : B
>Entity : Entity
kind: "B";
>kind : "B"
b: string;
>b : string
}
function hasKind(entity: Entity, kind: "A"): entity is A;
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; }
>entity : Entity
>Entity : Entity
>kind : "A"
>entity : any
>A : A
function hasKind(entity: Entity, kind: "B"): entity is B;
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; }
>entity : Entity
>Entity : Entity
>kind : "B"
>entity : any
>B : B
function hasKind(entity: Entity, kind: Kind): entity is Entity;
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; }
>entity : Entity
>Entity : Entity
>kind : "A" | "B"
>Kind : "A" | "B"
>entity : any
>Entity : Entity
function hasKind(entity: Entity, kind: Kind): boolean {
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; }
>entity : Entity
>Entity : Entity
>kind : "A" | "B"
>Kind : "A" | "B"
return entity.kind === kind;
>entity.kind === kind : boolean
>entity.kind : "A" | "B"
>entity : Entity
>kind : "A" | "B"
>kind : "A" | "B"
}
let x: A = {
>x : A
>A : A
>{ kind: "A", a: 100,} : { kind: "A"; a: number; }
kind: "A",
>kind : "A"
>"A" : "A"
a: 100,
>a : number
>100 : number
}
if (hasKind(x, "A")) {
>hasKind(x, "A") : entity is A
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; }
>x : A
>"A" : "A"
let a = x;
>a : A
>x : A
}
else {
let b = x;
>b : A
>x : A
}
if (!hasKind(x, "B")) {
>!hasKind(x, "B") : boolean
>hasKind(x, "B") : entity is B
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; }
>x : A
>"B" : "B"
let c = x;
>c : A
>x : A
}
else {
let d = x;
>d : A
>x : A
}
@@ -1,8 +1,8 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(20,10): error TS2394: Overload signature is not compatible with function implementation.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(22,21): error TS2304: Cannot find name 'is'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts(18,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts(19,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (2 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts (2 errors) ====
type Kind = "A" | "B"
@@ -21,14 +21,13 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(22,21)
}
function hasKind(entity: Entity, kind: "A"): entity is A;
function hasKind(entity: Entity, kind: "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is Entity;
~~~~~~~
!!! error TS2394: Overload signature is not compatible with function implementation.
function hasKind(entity: Entity, kind: Kind): boolean {
return kind === is;
~~
!!! error TS2304: Cannot find name 'is'.
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
function hasKind(entity: Entity, kind: "B"): entity is B;
~~~~~~~
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
function hasKind(entity: Entity, kind: Kind): entity is (A | B) {
return entity.kind === kind;
}
let x: A = {
@@ -0,0 +1,81 @@
//// [stringLiteralTypesAsTags02.ts]
type Kind = "A" | "B"
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
function hasKind(entity: Entity, kind: "A"): entity is A;
function hasKind(entity: Entity, kind: "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is (A | B) {
return entity.kind === kind;
}
let x: A = {
kind: "A",
a: 100,
}
if (hasKind(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!hasKind(x, "B")) {
let c = x;
}
else {
let d = x;
}
//// [stringLiteralTypesAsTags02.js]
function hasKind(entity, kind) {
return entity.kind === kind;
}
var x = {
kind: "A",
a: 100
};
if (hasKind(x, "A")) {
var a = x;
}
else {
var b = x;
}
if (!hasKind(x, "B")) {
var c = x;
}
else {
var d = x;
}
//// [stringLiteralTypesAsTags02.d.ts]
declare type Kind = "A" | "B";
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
declare function hasKind(entity: Entity, kind: "A"): entity is A;
declare function hasKind(entity: Entity, kind: "B"): entity is B;
declare let x: A;
@@ -0,0 +1,85 @@
//// [stringLiteralTypesAsTags03.ts]
type Kind = "A" | "B"
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid
// interpreting respective overloads as "specialized" signatures.
// That way, we can avoid the need to look for a compatible overload
// signature and simply check compatibility with the implementation.
function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is Entity {
return entity.kind === kind;
}
let x: A = {
kind: "A",
a: 100,
}
if (hasKind(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!hasKind(x, "B")) {
let c = x;
}
else {
let d = x;
}
//// [stringLiteralTypesAsTags03.js]
function hasKind(entity, kind) {
return entity.kind === kind;
}
var x = {
kind: "A",
a: 100
};
if (hasKind(x, "A")) {
var a = x;
}
else {
var b = x;
}
if (!hasKind(x, "B")) {
var c = x;
}
else {
var d = x;
}
//// [stringLiteralTypesAsTags03.d.ts]
declare type Kind = "A" | "B";
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
declare function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
declare function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
declare let x: A;
@@ -0,0 +1,109 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts ===
type Kind = "A" | "B"
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0))
interface Entity {
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
kind: Kind;
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18))
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0))
}
interface A extends Entity {
>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
kind: "A";
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 7, 28))
a: number;
>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 8, 14))
}
interface B extends Entity {
>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
kind: "B";
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 12, 28))
b: string;
>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 13, 14))
}
// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid
// interpreting respective overloads as "specialized" signatures.
// That way, we can avoid the need to look for a compatible overload
// signature and simply check compatibility with the implementation.
function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 21, 32))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17))
>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1))
function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 22, 32))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17))
>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1))
function hasKind(entity: Entity, kind: Kind): entity is Entity {
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32))
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17))
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
return entity.kind === kind;
>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18))
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17))
>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18))
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32))
}
let x: A = {
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1))
kind: "A",
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 27, 12))
a: 100,
>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 28, 14))
}
if (hasKind(x, "A")) {
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
let a = x;
>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 33, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
}
else {
let b = x;
>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 36, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
}
if (!hasKind(x, "B")) {
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
let c = x;
>c : Symbol(c, Decl(stringLiteralTypesAsTags03.ts, 40, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
}
else {
let d = x;
>d : Symbol(d, Decl(stringLiteralTypesAsTags03.ts, 43, 7))
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
}
@@ -0,0 +1,118 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts ===
type Kind = "A" | "B"
>Kind : "A" | "B"
interface Entity {
>Entity : Entity
kind: Kind;
>kind : "A" | "B"
>Kind : "A" | "B"
}
interface A extends Entity {
>A : A
>Entity : Entity
kind: "A";
>kind : "A"
a: number;
>a : number
}
interface B extends Entity {
>B : B
>Entity : Entity
kind: "B";
>kind : "B"
b: string;
>b : string
}
// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid
// interpreting respective overloads as "specialized" signatures.
// That way, we can avoid the need to look for a compatible overload
// signature and simply check compatibility with the implementation.
function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; }
>entity : Entity
>Entity : Entity
>kind : "A"
>entity : any
>A : A
function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; }
>entity : Entity
>Entity : Entity
>kind : "B"
>entity : any
>B : B
function hasKind(entity: Entity, kind: Kind): entity is Entity {
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; }
>entity : Entity
>Entity : Entity
>kind : "A" | "B"
>Kind : "A" | "B"
>entity : any
>Entity : Entity
return entity.kind === kind;
>entity.kind === kind : boolean
>entity.kind : "A" | "B"
>entity : Entity
>kind : "A" | "B"
>kind : "A" | "B"
}
let x: A = {
>x : A
>A : A
>{ kind: "A", a: 100,} : { kind: "A"; a: number; }
kind: "A",
>kind : "A"
>"A" : "A"
a: 100,
>a : number
>100 : number
}
if (hasKind(x, "A")) {
>hasKind(x, "A") : entity is A
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; }
>x : A
>"A" : "A"
let a = x;
>a : A
>x : A
}
else {
let b = x;
>b : A
>x : A
}
if (!hasKind(x, "B")) {
>!hasKind(x, "B") : boolean
>hasKind(x, "B") : entity is B
>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; }
>x : A
>"B" : "B"
let c = x;
>c : A
>x : A
}
else {
let d = x;
>d : A
>x : A
}
@@ -1,59 +0,0 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(11,10): error TS2354: No best common type exists among return expressions.
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts (1 errors) ====
type PrimitiveName = 'string' | 'number' | 'boolean';
function getFalsyPrimitive(x: "string"): string;
function getFalsyPrimitive(x: "number"): number;
function getFalsyPrimitive(x: "boolean"): boolean;
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
function getFalsyPrimitive(x: "number" | "string"): number | string;
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
function getFalsyPrimitive(x: PrimitiveName) {
~~~~~~~~~~~~~~~~~
!!! error TS2354: No best common type exists among return expressions.
if (x === "string") {
return "";
}
if (x === "number") {
return 0;
}
if (x === "boolean") {
return false;
}
// Should be unreachable.
throw "Invalid value";
}
namespace Consts1 {
const EMPTY_STRING = getFalsyPrimitive("string");
const ZERO = getFalsyPrimitive('number');
const FALSE = getFalsyPrimitive("boolean");
}
const string: "string" = "string"
const number: "number" = "number"
const boolean: "boolean" = "boolean"
const stringOrNumber = string || number;
const stringOrBoolean = string || boolean;
const booleanOrNumber = number || boolean;
const stringOrBooleanOrNumber = stringOrBoolean || number;
namespace Consts2 {
const EMPTY_STRING = getFalsyPrimitive(string);
const ZERO = getFalsyPrimitive(number);
const FALSE = getFalsyPrimitive(boolean);
const a = getFalsyPrimitive(stringOrNumber);
const b = getFalsyPrimitive(stringOrBoolean);
const c = getFalsyPrimitive(booleanOrNumber);
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
}
@@ -9,7 +9,7 @@ function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
function getFalsyPrimitive(x: "number" | "string"): number | string;
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
function getFalsyPrimitive(x: PrimitiveName) {
function getFalsyPrimitive(x: PrimitiveName): number | string | boolean {
if (x === "string") {
return "";
}
@@ -0,0 +1,144 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts ===
type PrimitiveName = 'string' | 'number' | 'boolean';
>PrimitiveName : Symbol(PrimitiveName, Decl(stringLiteralTypesOverloads01.ts, 0, 0))
function getFalsyPrimitive(x: "string"): string;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 3, 27))
function getFalsyPrimitive(x: "number"): number;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 4, 27))
function getFalsyPrimitive(x: "boolean"): boolean;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 5, 27))
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 6, 27))
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 7, 27))
function getFalsyPrimitive(x: "number" | "string"): number | string;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 8, 27))
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 9, 27))
function getFalsyPrimitive(x: PrimitiveName): number | string | boolean {
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27))
>PrimitiveName : Symbol(PrimitiveName, Decl(stringLiteralTypesOverloads01.ts, 0, 0))
if (x === "string") {
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27))
return "";
}
if (x === "number") {
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27))
return 0;
}
if (x === "boolean") {
>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27))
return false;
}
// Should be unreachable.
throw "Invalid value";
}
namespace Consts1 {
>Consts1 : Symbol(Consts1, Decl(stringLiteralTypesOverloads01.ts, 23, 1))
const EMPTY_STRING = getFalsyPrimitive("string");
>EMPTY_STRING : Symbol(EMPTY_STRING, Decl(stringLiteralTypesOverloads01.ts, 26, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
const ZERO = getFalsyPrimitive('number');
>ZERO : Symbol(ZERO, Decl(stringLiteralTypesOverloads01.ts, 27, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
const FALSE = getFalsyPrimitive("boolean");
>FALSE : Symbol(FALSE, Decl(stringLiteralTypesOverloads01.ts, 28, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
}
const string: "string" = "string"
>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5))
const number: "number" = "number"
>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5))
const boolean: "boolean" = "boolean"
>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5))
const stringOrNumber = string || number;
>stringOrNumber : Symbol(stringOrNumber, Decl(stringLiteralTypesOverloads01.ts, 35, 5))
>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5))
>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5))
const stringOrBoolean = string || boolean;
>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads01.ts, 36, 5))
>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5))
>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5))
const booleanOrNumber = number || boolean;
>booleanOrNumber : Symbol(booleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 37, 5))
>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5))
>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5))
const stringOrBooleanOrNumber = stringOrBoolean || number;
>stringOrBooleanOrNumber : Symbol(stringOrBooleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 38, 5))
>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads01.ts, 36, 5))
>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5))
namespace Consts2 {
>Consts2 : Symbol(Consts2, Decl(stringLiteralTypesOverloads01.ts, 38, 58))
const EMPTY_STRING = getFalsyPrimitive(string);
>EMPTY_STRING : Symbol(EMPTY_STRING, Decl(stringLiteralTypesOverloads01.ts, 41, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5))
const ZERO = getFalsyPrimitive(number);
>ZERO : Symbol(ZERO, Decl(stringLiteralTypesOverloads01.ts, 42, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5))
const FALSE = getFalsyPrimitive(boolean);
>FALSE : Symbol(FALSE, Decl(stringLiteralTypesOverloads01.ts, 43, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5))
const a = getFalsyPrimitive(stringOrNumber);
>a : Symbol(a, Decl(stringLiteralTypesOverloads01.ts, 45, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>stringOrNumber : Symbol(stringOrNumber, Decl(stringLiteralTypesOverloads01.ts, 35, 5))
const b = getFalsyPrimitive(stringOrBoolean);
>b : Symbol(b, Decl(stringLiteralTypesOverloads01.ts, 46, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads01.ts, 36, 5))
const c = getFalsyPrimitive(booleanOrNumber);
>c : Symbol(c, Decl(stringLiteralTypesOverloads01.ts, 47, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>booleanOrNumber : Symbol(booleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 37, 5))
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
>d : Symbol(d, Decl(stringLiteralTypesOverloads01.ts, 48, 9))
>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90))
>stringOrBooleanOrNumber : Symbol(stringOrBooleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 38, 5))
}
@@ -0,0 +1,174 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts ===
type PrimitiveName = 'string' | 'number' | 'boolean';
>PrimitiveName : "string" | "number" | "boolean"
function getFalsyPrimitive(x: "string"): string;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "string"
function getFalsyPrimitive(x: "number"): number;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "number"
function getFalsyPrimitive(x: "boolean"): boolean;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "boolean"
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "boolean" | "string"
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "boolean" | "number"
function getFalsyPrimitive(x: "number" | "string"): number | string;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "number" | "string"
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "number" | "string" | "boolean"
function getFalsyPrimitive(x: PrimitiveName): number | string | boolean {
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>x : "string" | "number" | "boolean"
>PrimitiveName : "string" | "number" | "boolean"
if (x === "string") {
>x === "string" : boolean
>x : "string" | "number" | "boolean"
>"string" : string
return "";
>"" : string
}
if (x === "number") {
>x === "number" : boolean
>x : "string" | "number" | "boolean"
>"number" : string
return 0;
>0 : number
}
if (x === "boolean") {
>x === "boolean" : boolean
>x : "string" | "number" | "boolean"
>"boolean" : string
return false;
>false : boolean
}
// Should be unreachable.
throw "Invalid value";
>"Invalid value" : string
}
namespace Consts1 {
>Consts1 : typeof Consts1
const EMPTY_STRING = getFalsyPrimitive("string");
>EMPTY_STRING : string
>getFalsyPrimitive("string") : string
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>"string" : "string"
const ZERO = getFalsyPrimitive('number');
>ZERO : number
>getFalsyPrimitive('number') : number
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>'number' : "number"
const FALSE = getFalsyPrimitive("boolean");
>FALSE : boolean
>getFalsyPrimitive("boolean") : boolean
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>"boolean" : "boolean"
}
const string: "string" = "string"
>string : "string"
>"string" : "string"
const number: "number" = "number"
>number : "number"
>"number" : "number"
const boolean: "boolean" = "boolean"
>boolean : "boolean"
>"boolean" : "boolean"
const stringOrNumber = string || number;
>stringOrNumber : "string" | "number"
>string || number : "string" | "number"
>string : "string"
>number : "number"
const stringOrBoolean = string || boolean;
>stringOrBoolean : "string" | "boolean"
>string || boolean : "string" | "boolean"
>string : "string"
>boolean : "boolean"
const booleanOrNumber = number || boolean;
>booleanOrNumber : "number" | "boolean"
>number || boolean : "number" | "boolean"
>number : "number"
>boolean : "boolean"
const stringOrBooleanOrNumber = stringOrBoolean || number;
>stringOrBooleanOrNumber : "string" | "boolean" | "number"
>stringOrBoolean || number : "string" | "boolean" | "number"
>stringOrBoolean : "string" | "boolean"
>number : "number"
namespace Consts2 {
>Consts2 : typeof Consts2
const EMPTY_STRING = getFalsyPrimitive(string);
>EMPTY_STRING : string
>getFalsyPrimitive(string) : string
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>string : "string"
const ZERO = getFalsyPrimitive(number);
>ZERO : number
>getFalsyPrimitive(number) : number
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>number : "number"
const FALSE = getFalsyPrimitive(boolean);
>FALSE : boolean
>getFalsyPrimitive(boolean) : boolean
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>boolean : "boolean"
const a = getFalsyPrimitive(stringOrNumber);
>a : number | string
>getFalsyPrimitive(stringOrNumber) : number | string
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>stringOrNumber : "string" | "number"
const b = getFalsyPrimitive(stringOrBoolean);
>b : boolean | string
>getFalsyPrimitive(stringOrBoolean) : boolean | string
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>stringOrBoolean : "string" | "boolean"
const c = getFalsyPrimitive(booleanOrNumber);
>c : boolean | number
>getFalsyPrimitive(booleanOrNumber) : boolean | number
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>booleanOrNumber : "number" | "boolean"
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
>d : number | string | boolean
>getFalsyPrimitive(stringOrBooleanOrNumber) : number | string | boolean
>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; }
>stringOrBooleanOrNumber : "string" | "boolean" | "number"
}
@@ -1,4 +1,4 @@
tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
==== tests/cases/compiler/superCallFromFunction1.ts (1 errors) ====
@@ -6,5 +6,5 @@ tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can o
function foo() {
super(value => String(value));
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
@@ -1,15 +1,15 @@
tests/cases/compiler/superErrors.ts(3,13): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superErrors.ts(3,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(3,18): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(4,19): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superErrors.ts(4,19): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(4,24): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(5,31): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/superErrors.ts(5,31): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(5,36): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(22,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(27,27): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(31,36): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(22,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(27,27): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(31,36): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(31,41): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(39,27): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(43,36): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/superErrors.ts(39,27): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(43,36): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superErrors.ts(43,41): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(47,22): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superErrors.ts(48,28): error TS1034: 'super' must be followed by an argument list or member access.
@@ -21,17 +21,17 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow
// super in a non class context
var x = super;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
var y = () => super;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
var z = () => () => () => super;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}
@@ -52,20 +52,20 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow
function inner() {
super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
// super call in a lambda in an inner function in a constructor
function inner2() {
var x = () => super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
// super call in a lambda in a function expression in a constructor
(function() { return () => super; })();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}
@@ -77,13 +77,13 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow
function inner() {
var x = () => super.sayHello();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
// super call in a lambda in a function expression in a constructor
(function() { return () => super; })();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}
@@ -0,0 +1,95 @@
tests/cases/compiler/superInObjectLiterals_ES5.ts(7,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(10,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(14,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(39,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(42,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(46,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/superInObjectLiterals_ES5.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES5.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/compiler/superInObjectLiterals_ES5.ts (11 errors) ====
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
~~~~~
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
},
get prop() {
super.method();
~~~~~
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
return 10;
},
set prop(value) {
super.method();
~~~~~
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
~~~~~
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
},
get prop() {
super.method();
~~~~~
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
return 10;
},
set prop(value) {
super.method();
~~~~~
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
}
};
}
}
@@ -0,0 +1,133 @@
//// [superInObjectLiterals_ES5.ts]
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
//// [superInObjectLiterals_ES5.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 obj = {
__proto__: {
method: function () {
}
},
method: function () {
_super.prototype.method.call(this);
},
get prop() {
_super.prototype.method.call(this);
return 10;
},
set prop(value) {
_super.prototype.method.call(this);
},
p1: function () {
_super.method.call(this);
},
p2: function f() {
_super.method.call(this);
},
p3: function () {
_super.method.call(this);
}
};
var A = (function () {
function A() {
}
A.prototype.method = function () { };
return A;
}());
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
B.prototype.f = function () {
var _this = this;
var obj = {
__proto__: {
method: function () {
}
},
method: function () {
_super.prototype.method.call(this);
},
get prop() {
_super.prototype.method.call(this);
return 10;
},
set prop(value) {
_super.prototype.method.call(this);
},
p1: function () {
_super.method.call(this);
},
p2: function f() {
_super.method.call(this);
},
p3: function () {
_super.prototype.method.call(_this);
}
};
};
return B;
}(A));
@@ -0,0 +1,77 @@
tests/cases/compiler/superInObjectLiterals_ES6.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/superInObjectLiterals_ES6.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
==== tests/cases/compiler/superInObjectLiterals_ES6.ts (5 errors) ====
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p2: function f() {
super.method();
~~~~~
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
},
p3: () => {
super.method();
}
};
}
}
@@ -0,0 +1,119 @@
//// [superInObjectLiterals_ES6.ts]
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
//// [superInObjectLiterals_ES6.js]
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
@@ -0,0 +1,46 @@
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts]
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES5.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 A = (function () {
function A() {
}
A.prototype.foo = function () { return 1; };
return A;
}());
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
B.prototype.foo = function () { return 2; };
B.prototype.bar = function () {
return (function () {
function class_1() {
}
class_1.prototype[_super.prototype.foo.call(this)] = function () {
return 100;
};
return class_1;
}());
};
return B;
}(A));
@@ -0,0 +1,29 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts ===
class A {
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0))
foo() { return 1; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9))
}
class B extends A {
>B : Symbol(B, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 2, 1))
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0))
foo() { return 2; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 4, 19))
bar() {
>bar : Symbol(bar, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 5, 23))
return class {
[super.foo()]() {
>super.foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9))
>super : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0))
>foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9))
return 100;
}
}
}
}
@@ -0,0 +1,35 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts ===
class A {
>A : A
foo() { return 1; }
>foo : () => number
>1 : number
}
class B extends A {
>B : B
>A : A
foo() { return 2; }
>foo : () => number
>2 : number
bar() {
>bar : () => typeof (Anonymous class)
return class {
>class { [super.foo()]() { return 100; } } : typeof (Anonymous class)
[super.foo()]() {
>super.foo() : number
>super.foo : () => number
>super : A
>foo : () => number
return 100;
>100 : number
}
}
}
}
@@ -0,0 +1,31 @@
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts]
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}
//// [superPropertyAccessInComputedPropertiesOfNestedType_ES6.js]
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
;
}
}
@@ -0,0 +1,29 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts ===
class A {
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0))
foo() { return 1; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9))
}
class B extends A {
>B : Symbol(B, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 2, 1))
>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0))
foo() { return 2; }
>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 4, 19))
bar() {
>bar : Symbol(bar, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 5, 23))
return class {
[super.foo()]() {
>super.foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9))
>super : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0))
>foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9))
return 100;
}
}
}
}
@@ -0,0 +1,35 @@
=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts ===
class A {
>A : A
foo() { return 1; }
>foo : () => number
>1 : number
}
class B extends A {
>B : B
>A : A
foo() { return 2; }
>foo : () => number
>2 : number
bar() {
>bar : () => typeof (Anonymous class)
return class {
>class { [super.foo()]() { return 100; } } : typeof (Anonymous class)
[super.foo()]() {
>super.foo() : number
>super.foo : () => number
>super : A
>foo : () => number
return 100;
>100 : number
}
}
}
}
@@ -1,10 +1,10 @@
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2335: 'super' can only be referenced in a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(20,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
==== tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts (7 errors) ====
@@ -16,19 +16,19 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24):
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return super._foo;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
},
set foo(value: string) {
~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
super._foo = value;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
},
test: function () {
return super._foo;
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions.
}
}
}
@@ -42,7 +42,7 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24):
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return super.test();
~~~~~
!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.
}
};
}
@@ -38,10 +38,10 @@ var ObjectLiteral;
var ThisInObjectLiteral = {
_foo: '1',
get foo() {
return _super._foo;
return _super.prototype._foo;
},
set foo(value) {
_super._foo = value;
_super.prototype._foo = value;
},
test: function () {
return _super._foo;
@@ -62,7 +62,7 @@ var SuperObjectTest = (function (_super) {
SuperObjectTest.prototype.testing = function () {
var test = {
get F() {
return _super.test.call(this);
return _super.prototype.test.call(this);
}
};
};
@@ -0,0 +1,33 @@
tests/cases/conformance/jsx/file.tsx(11,22): error TS2339: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'.
==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
declare module JSX {
interface Element { }
interface IntrinsicElements {
}
interface ElementAttributesProperty {
props;
}
interface IntrinsicAttributes {
ref?: string;
}
}
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
class MyComponent {
render() {
}
props: {
ref?: string;
}
}
// Should be an OK
var x = <MyComponent bar='world' />;
~~~
!!! error TS2339: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'.
@@ -0,0 +1,41 @@
//// [tests/cases/conformance/jsx/tsxAttributeResolution11.tsx] ////
//// [react.d.ts]
declare module JSX {
interface Element { }
interface IntrinsicElements {
}
interface ElementAttributesProperty {
props;
}
interface IntrinsicAttributes {
ref?: string;
}
}
//// [file.tsx]
class MyComponent {
render() {
}
props: {
ref?: string;
}
}
// Should be an OK
var x = <MyComponent bar='world' />;
//// [file.jsx]
var MyComponent = (function () {
function MyComponent() {
}
MyComponent.prototype.render = function () {
};
return MyComponent;
}());
// Should be an OK
var x = <MyComponent bar='world'/>;
@@ -0,0 +1,11 @@
// Repro from #6072
class Foo {}
function maker (value: string): typeof maker.Bar {
return maker.Bar;
}
namespace maker {
export class Bar extends Foo {}
}
@@ -0,0 +1,89 @@
namespace First {
export enum E {
a, b, c,
}
}
namespace Abc {
export enum E {
a, b, c,
}
export enum Nope {
a, b, c,
}
}
namespace Abcd {
export enum E {
a, b, c, d,
}
}
namespace Ab {
export enum E {
a, b,
}
}
namespace Cd {
export enum E {
c, d,
}
}
namespace Const {
export const enum E {
a, b, c,
}
}
namespace Decl {
export declare enum E {
a, b, c = 3,
}
}
namespace Merged {
export enum E {
a, b,
}
export enum E {
c = 3, d,
}
}
namespace Merged2 {
export enum E {
a, b, c
}
export module E {
export let d = 5;
}
}
var abc: First.E;
var secondAbc: Abc.E;
var secondAbcd: Abcd.E;
var secondAb: Ab.E;
var secondCd: Cd.E;
var nope: Abc.Nope;
var k: Const.E;
var decl: Decl.E;
var merged: Merged.E;
var merged2: Merged2.E;
abc = secondAbc; // ok
abc = secondAbcd; // missing 'd'
abc = secondAb; // ok
abc = secondCd; // missing 'd'
abc = nope; // nope!
abc = decl; // ok
secondAbc = abc; // ok
secondAbcd = abc; // ok
secondAb = abc; // missing 'c'
secondCd = abc; // missing 'a' and 'b'
nope = abc; // nope!
decl = abc; // ok
// const is only assignable to itself
k = k;
abc = k; // error
k = abc;
// merged enums compare all their members
abc = merged; // missing 'd'
merged = abc; // ok
abc = merged2; // ok
merged2 = abc; // ok
@@ -0,0 +1,12 @@
function foo(bar: { a:number }[]): number;
function foo(bar: { a:string }[]): string;
function foo([x]: { a:number | string }[]): string | number {
if (x) {
return x.a;
}
return undefined;
}
var x = foo([{a: "str"}]);
var y = foo([{a: 100}]);
@@ -0,0 +1,22 @@
interface Animal { animal }
interface Dog extends Animal { dog }
interface Cat extends Animal { cat }
function foo1(bar: { a:number }[]): Dog;
function foo1(bar: { a:string }[]): Animal;
function foo1([x]: { a:number | string }[]): Dog {
return undefined;
}
function foo2(bar: { a:number }[]): Cat;
function foo2(bar: { a:string }[]): Cat | Dog;
function foo2([x]: { a:number | string }[]): Cat {
return undefined;
}
var x1 = foo1([{a: "str"}]);
var y1 = foo1([{a: 100}]);
var x2 = foo2([{a: "str"}]);
var y2 = foo2([{a: 100}]);
@@ -0,0 +1,22 @@
interface Animal { animal }
interface Dog extends Animal { dog }
interface Cat extends Animal { cat }
function foo1(bar: { a:number }[]): Cat;
function foo1(bar: { a:string }[]): Dog;
function foo1([x]: { a:number | string }[]): Animal {
return undefined;
}
function foo2(bar: { a:number }[]): Cat;
function foo2(bar: { a:string }[]): Dog;
function foo2([x]: { a:number | string }[]): Cat | Dog {
return undefined;
}
var x1 = foo1([{a: "str"}]);
var y1 = foo1([{a: 100}]);
var x2 = foo2([{a: "str"}]);
var y2 = foo2([{a: 100}]);
@@ -6,7 +6,7 @@ class C extends A {
}
function foo(name: 'hi'): B;
function foo(name: 'bye'): C;
function foo(name: string): A; // error
function foo(name: string): A;
function foo(name: any): Z {
return null;
}
@@ -0,0 +1,60 @@
// @target: ES5
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
@@ -0,0 +1,60 @@
// @target: ES6
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
class A {
method() { }
}
class B extends A {
f() {
var obj = {
__proto__: {
method() {
}
},
method() {
super.method();
},
get prop() {
super.method();
return 10;
},
set prop(value) {
super.method();
},
p1: function () {
super.method();
},
p2: function f() {
super.method();
},
p3: () => {
super.method();
}
};
}
}
@@ -0,0 +1,15 @@
// @target: ES5
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}
@@ -0,0 +1,15 @@
// @target: ES6
class A {
foo() { return 1; }
}
class B extends A {
foo() { return 2; }
bar() {
return class {
[super.foo()]() {
return 100;
}
}
}
}
@@ -1,22 +0,0 @@
// Function overloads do not emit code
// Function overload signature with optional parameter
// Function overload signature with optional parameter
// Function overloads with generic and non-generic overloads
// Function overloads whose only difference is returning different unconstrained generic parameters
// Function overloads whose only difference is returning different constrained generic parameters
// Function overloads that differ only by type parameter constraints
// Function overloads with matching accessibility
// Function overloads with matching export
// Function overloads with more params than implementation signature
// Function overloads where return types are same infinitely recursive type reference
@@ -0,0 +1,4 @@
function f(x: string): number;
function f(x: string): void {
return;
}
@@ -0,0 +1,4 @@
function f(x: string): void;
function f(x: string): number {
return 0;
}
@@ -0,0 +1,4 @@
function f(x: string): void;
function f(x: string): void {
return;
}
@@ -0,0 +1,29 @@
//@jsx: preserve
//@module: amd
//@filename: react.d.ts
declare module JSX {
interface Element { }
interface IntrinsicElements {
}
interface ElementAttributesProperty {
props;
}
interface IntrinsicAttributes {
ref?: string;
}
}
//@filename: file.tsx
class MyComponent {
render() {
}
props: {
ref?: string;
}
}
// Should be an OK
var x = <MyComponent bar='world' />;
@@ -20,7 +20,7 @@ function hasKind(entity: Entity, kind: "A"): entity is A;
function hasKind(entity: Entity, kind: "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is Entity;
function hasKind(entity: Entity, kind: Kind): boolean {
return kind === is;
return entity.kind === kind;
}
let x: A = {
@@ -0,0 +1,42 @@
// @declaration: true
type Kind = "A" | "B"
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
function hasKind(entity: Entity, kind: "A"): entity is A;
function hasKind(entity: Entity, kind: "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is (A | B) {
return entity.kind === kind;
}
let x: A = {
kind: "A",
a: 100,
}
if (hasKind(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!hasKind(x, "B")) {
let c = x;
}
else {
let d = x;
}
@@ -0,0 +1,46 @@
// @declaration: true
type Kind = "A" | "B"
interface Entity {
kind: Kind;
}
interface A extends Entity {
kind: "A";
a: number;
}
interface B extends Entity {
kind: "B";
b: string;
}
// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid
// interpreting respective overloads as "specialized" signatures.
// That way, we can avoid the need to look for a compatible overload
// signature and simply check compatibility with the implementation.
function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
function hasKind(entity: Entity, kind: Kind): entity is Entity {
return entity.kind === kind;
}
let x: A = {
kind: "A",
a: 100,
}
if (hasKind(x, "A")) {
let a = x;
}
else {
let b = x;
}
if (!hasKind(x, "B")) {
let c = x;
}
else {
let d = x;
}
@@ -9,7 +9,7 @@ function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
function getFalsyPrimitive(x: "number" | "string"): number | string;
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
function getFalsyPrimitive(x: PrimitiveName) {
function getFalsyPrimitive(x: PrimitiveName): number | string | boolean {
if (x === "string") {
return "";
}
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// class Foo {
//// constructor(private /*0*/privateParam: number,
//// public /*1*/publicParam: string,
//// protected /*2*/protectedParam: boolean) {
////
//// let localPrivate = /*3*/privateParam;
//// this./*4*/privateParam += 10;
////
//// let localPublic = /*5*/publicParam;
//// this./*6*/publicParam += " Hello!";
////
//// let localProtected = /*7*/protectedParam;
//// this./*8*/protectedParam = false;
//// }
//// }
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(3, ["file1.ts"]);
}
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// class Foo {
//// constructor(private {/*0*/privateParam}: number,
//// public {/*1*/publicParam}: string,
//// protected {/*2*/protectedParam}: boolean) {
////
//// let localPrivate = /*3*/privateParam;
//// this.privateParam += 10; // this is not valid syntax
////
//// let localPublic = /*4*/publicParam;
//// this.publicParam += " Hello!"; // this is not valid syntax
////
//// let localProtected = /*5*/protectedParam;
//// this.protectedParam = false; // this is not valid syntax
//// }
//// }
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
}
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts'/>
// @Filename: file1.ts
//// class Foo {
//// constructor(private [/*0*/privateParam]: number,
//// public [/*1*/publicParam]: string,
//// protected [/*2*/protectedParam]: boolean) {
////
//// let localPrivate = /*3*/privateParam;
//// this.privateParam += 10; // this is not valid syntax
////
//// let localPublic = /*4*/publicParam;
//// this.publicParam += " Hello!"; // this is not valid syntax
////
//// let localProtected = /*5*/protectedParam;
//// this.protectedParam = false; // this is not valid syntax
//// }
//// }
let markers = test.markers()
for (let marker of markers) {
goTo.position(marker.position);
verify.documentHighlightsAtPositionCount(2, ["file1.ts"]);
}

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