diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 00000000000..dcd2280570c --- /dev/null +++ b/issue_template.md @@ -0,0 +1,27 @@ + + +**TypeScript Version:** + +1.7.5 / 1.8.0-beta / nightly (1.9.0-dev.20160217) + +**Code** + +```ts +// A self-contained demonstration of the problem follows... + +``` + +**Expected behavior:** + +**Actual behavior:** diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 00000000000..2baaa3521dd --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,16 @@ + + +**Fixes issue:** # diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a95162804a..7000ace8aff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -133,8 +133,8 @@ namespace ts { const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - const anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); - const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); + const anySignature = createSignature(undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); + const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); @@ -1713,6 +1713,25 @@ namespace ts { return result; } + function typePredicateToString(typePredicate: TypePredicate, enclosingDeclaration?: Declaration, flags?: TypeFormatFlags): string { + const writer = getSingleLineStringWriter(); + getSymbolDisplayBuilder().buildTypePredicateDisplay(typePredicate, writer, enclosingDeclaration, flags); + const result = writer.string(); + releaseStringWriter(writer); + + return result; + } + + function visibilityToString(flags: NodeFlags) { + if (flags === NodeFlags.Private) { + return "private"; + } + if (flags === NodeFlags.Protected) { + return "protected"; + } + return "public"; + } + function getTypeAliasForTypeLiteral(type: Type): Symbol { if (type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral) { let node = type.symbol.declarations[0].parent; @@ -1846,16 +1865,10 @@ namespace ts { function writeType(type: Type, flags: TypeFormatFlags) { // Write undefined/null type as any if (type.flags & TypeFlags.Intrinsic) { - if (type.flags & TypeFlags.PredicateType) { - buildTypePredicateDisplay(writer, (type as PredicateType).predicate); - buildTypeDisplay((type as PredicateType).predicate.type, writer, enclosingDeclaration, flags, symbolStack); - } - else { - // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && isTypeAny(type) - ? "any" - : (type).intrinsicName); - } + // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving + writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && isTypeAny(type) + ? "any" + : (type).intrinsicName); } else if (type.flags & TypeFlags.ThisType) { if (inObjectTypeLiteral) { @@ -2219,7 +2232,7 @@ namespace ts { writePunctuation(writer, SyntaxKind.CloseParenToken); } - function buildTypePredicateDisplay(writer: SymbolWriter, predicate: TypePredicate) { + function buildTypePredicateDisplay(predicate: TypePredicate, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]): void { if (isIdentifierTypePredicate(predicate)) { writer.writeParameter(predicate.parameterName); } @@ -2229,6 +2242,7 @@ namespace ts { writeSpace(writer); writeKeyword(writer, SyntaxKind.IsKeyword); writeSpace(writer); + buildTypeDisplay(predicate.type, writer, enclosingDeclaration, flags, symbolStack); } function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { @@ -2241,8 +2255,13 @@ namespace ts { } writeSpace(writer); - const returnType = getReturnTypeOfSignature(signature); - buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack); + if (signature.typePredicate) { + buildTypePredicateDisplay(signature.typePredicate, writer, enclosingDeclaration, flags, symbolStack); + } + else { + const returnType = getReturnTypeOfSignature(signature); + buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack); + } } function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind, symbolStack?: Symbol[]) { @@ -2261,6 +2280,7 @@ namespace ts { } buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } @@ -2268,6 +2288,7 @@ namespace ts { buildSymbolDisplay, buildTypeDisplay, buildTypeParameterDisplay, + buildTypePredicateDisplay, buildParameterDisplay, buildDisplayForParametersAndDelimiters, buildDisplayForTypeParametersAndDelimiters, @@ -2808,9 +2829,6 @@ namespace ts { if (declaration.kind === SyntaxKind.PropertyAssignment) { return type; } - if (type.flags & TypeFlags.PredicateType && (declaration.kind === SyntaxKind.PropertyDeclaration || declaration.kind === SyntaxKind.PropertySignature)) { - return type; - } return getWidenedType(type); } @@ -3541,12 +3559,13 @@ namespace ts { } function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], parameters: Symbol[], - resolvedReturnType: Type, minArgumentCount: number, hasRestParameter: boolean, hasStringLiterals: boolean): Signature { + resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasStringLiterals: boolean): Signature { const sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; sig.resolvedReturnType = resolvedReturnType; + sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; sig.hasRestParameter = hasRestParameter; sig.hasStringLiterals = hasStringLiterals; @@ -3555,14 +3574,14 @@ namespace ts { function cloneSignature(sig: Signature): Signature { return createSignature(sig.declaration, sig.typeParameters, sig.parameters, sig.resolvedReturnType, - sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); } function getDefaultConstructSignatures(classType: InterfaceType): Signature[] { const baseConstructorType = getBaseConstructorTypeOfClass(classType); const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct); if (baseSignatures.length === 0) { - return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false)]; + return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false)]; } const baseTypeNode = getBaseTypeNodeOfClass(classType); const typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode); @@ -3995,6 +4014,19 @@ namespace ts { return getIndexTypeOfStructuredType(getApparentType(type), kind); } + function getImplicitIndexTypeOfType(type: Type, kind: IndexKind): Type { + if (isObjectLiteralType(type)) { + const propTypes: Type[] = []; + for (const prop of getPropertiesOfType(type)) { + if (kind === IndexKind.String || isNumericLiteralName(prop.name)) { + propTypes.push(getTypeOfSymbol(prop)); + } + } + return getUnionType(propTypes); + } + return undefined; + } + function getTypeParametersFromJSDocTemplate(declaration: SignatureDeclaration): TypeParameter[] { if (declaration.flags & NodeFlags.JavaScriptFile) { const templateTag = getJSDocTemplateTag(declaration); @@ -4094,6 +4126,7 @@ namespace ts { let minArgumentCount = -1; const isJSConstructSignature = isJSDocConstructSignature(declaration); let returnType: Type = undefined; + let typePredicate: TypePredicate = undefined; // If this is a JSDoc construct signature, then skip the first parameter in the // parameter list. The first parameter represents the return type of the construct @@ -4137,6 +4170,9 @@ namespace ts { } else if (declaration.type) { returnType = getTypeFromTypeNode(declaration.type); + if (declaration.type.kind === SyntaxKind.TypePredicate) { + typePredicate = createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode); + } } else { if (declaration.flags & NodeFlags.JavaScriptFile) { @@ -4158,7 +4194,7 @@ namespace ts { } } - links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -4886,25 +4922,6 @@ namespace ts { return links.resolvedType; } - function getPredicateType(node: TypePredicateNode): Type { - return createPredicateType(getSymbolOfNode(node), createTypePredicateFromTypePredicateNode(node)); - } - - function createPredicateType(symbol: Symbol, predicate: ThisTypePredicate | IdentifierTypePredicate) { - const type = createType(TypeFlags.Boolean | TypeFlags.PredicateType) as PredicateType; - type.symbol = symbol; - type.predicate = predicate; - return type; - } - - function getTypeFromPredicateTypeNode(node: TypePredicateNode): Type { - const links = getNodeLinks(node); - if (!links.resolvedType) { - links.resolvedType = getPredicateType(node); - } - return links.resolvedType; - } - function getTypeFromTypeNode(node: TypeNode): Type { switch (node.kind) { case SyntaxKind.AnyKeyword: @@ -4929,7 +4946,7 @@ namespace ts { case SyntaxKind.JSDocTypeReference: return getTypeFromTypeReference(node); case SyntaxKind.TypePredicate: - return getTypeFromPredicateTypeNode(node); + return booleanType; case SyntaxKind.ExpressionWithTypeArguments: return getTypeFromTypeReference(node); case SyntaxKind.TypeQuery: @@ -5083,6 +5100,7 @@ namespace ts { function instantiateSignature(signature: Signature, mapper: TypeMapper, eraseTypeParameters?: boolean): Signature { let freshTypeParameters: TypeParameter[]; + let freshTypePredicate: TypePredicate; if (signature.typeParameters && !eraseTypeParameters) { // First create a fresh set of type parameters, then include a mapping from the old to the // new type parameters in the mapper function. Finally store this mapper in the new type @@ -5093,9 +5111,13 @@ namespace ts { tp.mapper = mapper; } } + if (signature.typePredicate) { + freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); + } const result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), + freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; @@ -5165,10 +5187,6 @@ namespace ts { if (type.flags & TypeFlags.Intersection) { return getIntersectionType(instantiateList((type).types, mapper, instantiateType)); } - if (type.flags & TypeFlags.PredicateType) { - const predicate = (type as PredicateType).predicate; - return createPredicateType(type.symbol, cloneTypePredicate(predicate, mapper)); - } } return type; } @@ -5314,21 +5332,58 @@ namespace ts { 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)) { + if (target.typePredicate) { + if (source.typePredicate) { + result &= compareTypePredicateRelatedTo(source.typePredicate, target.typePredicate, reportErrors, errorReporter, compareTypes); + } + else if (isIdentifierTypePredicate(target.typePredicate)) { if (reportErrors) { errorReporter(Diagnostics.Signature_0_must_have_a_type_predicate, signatureToString(source)); } return Ternary.False; } } + else { + result &= compareTypes(sourceReturnType, targetReturnType, reportErrors); + } - result &= compareTypes(sourceReturnType, targetReturnType, reportErrors); } return result; } + function compareTypePredicateRelatedTo(source: TypePredicate, + target: TypePredicate, + reportErrors: boolean, + errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void, + compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary { + if (source.kind !== target.kind) { + if (reportErrors) { + errorReporter(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard); + errorReporter(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typePredicateToString(source), typePredicateToString(target)); + } + return Ternary.False; + } + + if (source.kind === TypePredicateKind.Identifier) { + const sourceIdentifierPredicate = source as IdentifierTypePredicate; + const targetIdentifierPredicate = target as IdentifierTypePredicate; + if (sourceIdentifierPredicate.parameterIndex !== targetIdentifierPredicate.parameterIndex) { + if (reportErrors) { + errorReporter(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceIdentifierPredicate.parameterName, targetIdentifierPredicate.parameterName); + errorReporter(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typePredicateToString(source), typePredicateToString(target)); + } + return Ternary.False; + } + } + + const related = compareTypes(source.type, target.type, reportErrors); + if (related === Ternary.False && reportErrors) { + errorReporter(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typePredicateToString(source), typePredicateToString(target)); + } + return related; + } + function isImplementationCompatibleWithOverload(implementation: Signature, overload: Signature): boolean { const erasedSource = getErasedSignature(implementation); const erasedTarget = getErasedSignature(overload); @@ -5456,33 +5511,6 @@ namespace ts { if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; } if (source.flags & TypeFlags.Boolean && target.flags & TypeFlags.Boolean) { - if (source.flags & TypeFlags.PredicateType && target.flags & TypeFlags.PredicateType) { - const sourcePredicate = source as PredicateType; - const targetPredicate = target as PredicateType; - if (sourcePredicate.predicate.kind !== targetPredicate.predicate.kind) { - if (reportErrors) { - reportError(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard); - reportError(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typeToString(source), typeToString(target)); - } - return Ternary.False; - } - if (sourcePredicate.predicate.kind === TypePredicateKind.Identifier) { - const sourceIdentifierPredicate = sourcePredicate.predicate as IdentifierTypePredicate; - const targetIdentifierPredicate = targetPredicate.predicate as IdentifierTypePredicate; - if (sourceIdentifierPredicate.parameterIndex !== targetIdentifierPredicate.parameterIndex) { - if (reportErrors) { - reportError(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceIdentifierPredicate.parameterName, targetIdentifierPredicate.parameterName); - reportError(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typeToString(source), typeToString(target)); - } - return Ternary.False; - } - } - const related = isRelatedTo(sourcePredicate.predicate.type, targetPredicate.predicate.type, reportErrors, headMessage); - if (related === Ternary.False && reportErrors) { - reportError(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typeToString(source), typeToString(target)); - } - return related; - } return Ternary.True; } @@ -5774,9 +5802,9 @@ namespace ts { if (result) { result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors); if (result) { - result &= stringIndexTypesRelatedTo(source, originalSource, target, reportErrors); + result &= indexTypesRelatedTo(source, originalSource, target, IndexKind.String, reportErrors); if (result) { - result &= numberIndexTypesRelatedTo(source, originalSource, target, reportErrors); + result &= indexTypesRelatedTo(source, originalSource, target, IndexKind.Number, reportErrors); } } } @@ -5916,16 +5944,20 @@ namespace ts { const sourceSignatures = getSignaturesOfType(source, kind); const targetSignatures = getSignaturesOfType(target, kind); - if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length && - isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { - // An abstract constructor type is not assignable to a non-abstract constructor type + if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length) { + if (isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { + // An abstract constructor type is not assignable to a non-abstract constructor type // as it would otherwise be possible to new an abstract class. Note that the assignability - // check we perform for an extends clause excludes construct signatures from the target, - // so this check never proceeds. - if (reportErrors) { - reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + // check we perform for an extends clause excludes construct signatures from the target, + // so this check never proceeds. + if (reportErrors) { + reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return Ternary.False; + } + if (!constructorVisibilitiesAreCompatible(sourceSignatures[0], targetSignatures[0], reportErrors)) { + return Ternary.False; } - return Ternary.False; } let result = Ternary.True; @@ -5978,76 +6010,65 @@ namespace ts { return result; } - function stringIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { - if (relation === identityRelation) { - return indexTypesIdenticalTo(IndexKind.String, source, target); + function eachPropertyRelatedTo(source: Type, target: Type, kind: IndexKind, reportErrors: boolean): Ternary { + let result = Ternary.True; + for (const prop of getPropertiesOfObjectType(source)) { + if (kind === IndexKind.String || isNumericLiteralName(prop.name)) { + const related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors); + if (!related) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); + } + return Ternary.False; + } + result &= related; + } } - const targetInfo = getIndexInfoOfType(target, IndexKind.String); - if (targetInfo) { - if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { - // non-primitive assignment to any is always allowed, eg - // `var x: { [index: string]: any } = { property: 12 };` - return Ternary.True; - } - const sourceInfo = getIndexInfoOfType(source, IndexKind.String); - if (!sourceInfo) { - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); + return result; + } + + function indexInfoRelatedTo(sourceInfo: IndexInfo, targetInfo: IndexInfo, reportErrors: boolean) { + const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); + if (!related && reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible); + } + return related; + } + + function indexTypesRelatedTo(source: Type, originalSource: Type, target: Type, kind: IndexKind, reportErrors: boolean) { + if (relation === identityRelation) { + return indexTypesIdenticalTo(source, target, kind); + } + const targetInfo = getIndexInfoOfType(target, kind); + if (!targetInfo || ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive))) { + // Index signature of type any permits assignment from everything but primitives + return Ternary.True; + } + const sourceInfo = getIndexInfoOfType(source, kind) || + kind === IndexKind.Number && getIndexInfoOfType(source, IndexKind.String); + if (sourceInfo) { + return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors); + } + if (isObjectLiteralType(source)) { + let related = Ternary.True; + if (kind === IndexKind.String) { + const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); + if (sourceNumberInfo) { + related = indexInfoRelatedTo(sourceNumberInfo, targetInfo, reportErrors); } - return Ternary.False; } - const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); - if (!related) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible); - } - return Ternary.False; + if (related) { + related &= eachPropertyRelatedTo(source, targetInfo.type, kind, reportErrors); } return related; } - return Ternary.True; + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); + } + return Ternary.False; } - function numberIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { - if (relation === identityRelation) { - return indexTypesIdenticalTo(IndexKind.Number, source, target); - } - const targetInfo = getIndexInfoOfType(target, IndexKind.Number); - if (targetInfo) { - if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { - // non-primitive assignment to any is always allowed, eg - // `var x: { [index: number]: any } = { property: 12 };` - return Ternary.True; - } - const sourceStringInfo = getIndexInfoOfType(source, IndexKind.String); - const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); - if (!(sourceStringInfo || sourceNumberInfo)) { - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return Ternary.False; - } - let related: Ternary; - if (sourceStringInfo && sourceNumberInfo) { - // If we know for sure we're testing both string and numeric index types then only report errors from the second one - related = isRelatedTo(sourceStringInfo.type, targetInfo.type, /*reportErrors*/ false) || - isRelatedTo(sourceNumberInfo.type, targetInfo.type, reportErrors); - } - else { - related = isRelatedTo((sourceStringInfo || sourceNumberInfo).type, targetInfo.type, reportErrors); - } - if (!related) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible); - } - return Ternary.False; - } - return related; - } - return Ternary.True; - } - - function indexTypesIdenticalTo(indexKind: IndexKind, source: Type, target: Type): Ternary { + function indexTypesIdenticalTo(source: Type, target: Type, indexKind: IndexKind): Ternary { const targetInfo = getIndexInfoOfType(target, indexKind); const sourceInfo = getIndexInfoOfType(source, indexKind); if (!sourceInfo && !targetInfo) { @@ -6079,6 +6100,36 @@ namespace ts { } return Ternary.True; } + + function constructorVisibilitiesAreCompatible(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { + if (!sourceSignature.declaration || !targetSignature.declaration) { + return true; + } + + const sourceAccessibility = sourceSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); + const targetAccessibility = targetSignature.declaration.flags & (NodeFlags.Private | NodeFlags.Protected); + + // A public, protected and private signature is assignable to a private signature. + if (targetAccessibility === NodeFlags.Private) { + return true; + } + + // A public and protected signature is assignable to a protected signature. + if (targetAccessibility === NodeFlags.Protected && sourceAccessibility !== NodeFlags.Private) { + return true; + } + + // Only a public signature is assignable to public signature. + if (targetAccessibility !== NodeFlags.Protected && !sourceAccessibility) { + return true; + } + + if (reportErrors) { + reportError(Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, visibilityToString(sourceAccessibility), visibilityToString(targetAccessibility)); + } + + return false; + } } // Return true if the given type is the constructor type for an abstract class @@ -6325,6 +6376,16 @@ namespace ts { return strictNullChecks && type.flags & TypeFlags.Union ? getNonNullableTypeFromUnionType(type as UnionType) : type; } + /** + * Return true if type was inferred from an object literal or written as an object type literal + * with no call or construct signatures. + */ + function isObjectLiteralType(type: Type) { + return type.symbol && (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral)) !== 0 && + getSignaturesOfType(type, SignatureKind.Call).length === 0 && + getSignaturesOfType(type, SignatureKind.Construct).length === 0; + } + function getRegularTypeOfObjectLiteral(type: Type): Type { if (type.flags & TypeFlags.FreshObjectLiteral) { let regularType = (type).regularType; @@ -6377,9 +6438,6 @@ namespace ts { if (type.flags & TypeFlags.Undefined) { return anyType; } - if (type.flags & TypeFlags.PredicateType) { - return booleanType; - } if (type.flags & TypeFlags.ObjectLiteral) { return getWidenedTypeOfObjectLiteral(type); } @@ -6607,11 +6665,6 @@ namespace ts { inferFromTypes(sourceTypes[i], targetTypes[i]); } } - else if (source.flags & TypeFlags.PredicateType && target.flags & TypeFlags.PredicateType) { - if ((source as PredicateType).predicate.kind === (target as PredicateType).predicate.kind) { - inferFromTypes((source as PredicateType).predicate.type, (target as PredicateType).predicate.type); - } - } else if (source.flags & TypeFlags.Tuple && target.flags & TypeFlags.Tuple && (source).elementTypes.length === (target).elementTypes.length) { // If source and target are tuples of the same size, infer from element types const sourceTypes = (source).elementTypes; @@ -6676,9 +6729,7 @@ namespace ts { inferFromProperties(source, target); inferFromSignatures(source, target, SignatureKind.Call); inferFromSignatures(source, target, SignatureKind.Construct); - inferFromIndexTypes(source, target, IndexKind.String, IndexKind.String); - inferFromIndexTypes(source, target, IndexKind.Number, IndexKind.Number); - inferFromIndexTypes(source, target, IndexKind.String, IndexKind.Number); + inferFromIndexTypes(source, target); depth--; } } @@ -6707,15 +6758,31 @@ namespace ts { function inferFromSignature(source: Signature, target: Signature) { forEachMatchingParameterType(source, target, inferFromTypes); - inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + + if (source.typePredicate && target.typePredicate && source.typePredicate.kind === target.typePredicate.kind) { + inferFromTypes(source.typePredicate.type, target.typePredicate.type); + } + else { + inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } } - function inferFromIndexTypes(source: Type, target: Type, sourceKind: IndexKind, targetKind: IndexKind) { - const targetIndexType = getIndexTypeOfType(target, targetKind); - if (targetIndexType) { - const sourceIndexType = getIndexTypeOfType(source, sourceKind); + function inferFromIndexTypes(source: Type, target: Type) { + const targetStringIndexType = getIndexTypeOfType(target, IndexKind.String); + if (targetStringIndexType) { + const sourceIndexType = getIndexTypeOfType(source, IndexKind.String) || + getImplicitIndexTypeOfType(source, IndexKind.String); if (sourceIndexType) { - inferFromTypes(sourceIndexType, targetIndexType); + inferFromTypes(sourceIndexType, targetStringIndexType); + } + } + const targetNumberIndexType = getIndexTypeOfType(target, IndexKind.Number); + if (targetNumberIndexType) { + const sourceIndexType = getIndexTypeOfType(source, IndexKind.Number) || + getIndexTypeOfType(source, IndexKind.String) || + getImplicitIndexTypeOfType(source, IndexKind.Number); + if (sourceIndexType) { + inferFromTypes(sourceIndexType, targetNumberIndexType); } } } @@ -7138,46 +7205,33 @@ namespace ts { return originalType; } - function narrowTypeByTypePredicate(type: Type, expr: CallExpression, assumeTrue: boolean): Type { + function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type { if (type.flags & TypeFlags.Any) { return type; } - const signature = getResolvedSignature(expr); - const predicateType = getReturnTypeOfSignature(signature); + const signature = getResolvedSignature(callExpression); - if (!predicateType || !(predicateType.flags & TypeFlags.PredicateType)) { + const predicate = signature.typePredicate; + if (!predicate) { return type; } - const predicate = (predicateType as PredicateType).predicate; + if (isIdentifierTypePredicate(predicate)) { - const callExpression = expr as CallExpression; if (callExpression.arguments[predicate.parameterIndex] && getSymbolAtTypePredicatePosition(callExpression.arguments[predicate.parameterIndex]) === symbol) { return getNarrowedType(type, predicate.type, assumeTrue); } } else { - const expression = skipParenthesizedNodes(expr.expression); - return narrowTypeByThisTypePredicate(type, predicate, expression, assumeTrue); + const invokedExpression = skipParenthesizedNodes(callExpression.expression); + return narrowTypeByThisTypePredicate(type, predicate, invokedExpression, assumeTrue); } return type; } - function narrowTypeByTypePredicateMember(type: Type, expr: ElementAccessExpression | PropertyAccessExpression, assumeTrue: boolean): Type { - if (type.flags & TypeFlags.Any) { - return type; - } - const memberType = getTypeOfExpression(expr); - if (!(memberType.flags & TypeFlags.PredicateType)) { - return type; - } - - return narrowTypeByThisTypePredicate(type, (memberType as PredicateType).predicate as ThisTypePredicate, expr, assumeTrue); - } - - function narrowTypeByThisTypePredicate(type: Type, predicate: ThisTypePredicate, expression: Expression, assumeTrue: boolean): Type { - if (expression.kind === SyntaxKind.ElementAccessExpression || expression.kind === SyntaxKind.PropertyAccessExpression) { - const accessExpression = expression as ElementAccessExpression | PropertyAccessExpression; + function narrowTypeByThisTypePredicate(type: Type, predicate: ThisTypePredicate, invokedExpression: Expression, assumeTrue: boolean): Type { + if (invokedExpression.kind === SyntaxKind.ElementAccessExpression || invokedExpression.kind === SyntaxKind.PropertyAccessExpression) { + const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression; const possibleIdentifier = skipParenthesizedNodes(accessExpression.expression); if (possibleIdentifier.kind === SyntaxKind.Identifier && getSymbolAtTypePredicatePosition(possibleIdentifier) === symbol) { return getNarrowedType(type, predicate.type, assumeTrue); @@ -7191,8 +7245,7 @@ namespace ts { switch (expr.kind) { case SyntaxKind.Identifier: case SyntaxKind.PropertyAccessExpression: - case SyntaxKind.QualifiedName: - return getSymbolOfEntityNameOrPropertyAccessExpression(expr as Node as (EntityName | PropertyAccessExpression)); + return getSymbolOfEntityNameOrPropertyAccessExpression(expr as (Identifier | PropertyAccessExpression)); } } @@ -7226,9 +7279,6 @@ namespace ts { return narrowType(type, (expr).operand, !assumeTrue); } break; - case SyntaxKind.ElementAccessExpression: - case SyntaxKind.PropertyAccessExpression: - return narrowTypeByTypePredicateMember(type, expr as (ElementAccessExpression | PropertyAccessExpression), assumeTrue); } return type; } @@ -7401,6 +7451,46 @@ namespace ts { } } + function findFirstSuperCall(n: Node): Node { + if (isSuperCallExpression(n)) { + return n; + } + else if (isFunctionLike(n)) { + return undefined; + } + return forEachChild(n, findFirstSuperCall); + } + + /** + * Return a cached result if super-statement is already found. + * Otherwise, find a super statement in a given constructor function and cache the result in the node-links of the constructor + * + * @param constructor constructor-function to look for super statement + */ + function getSuperCallInConstructor(constructor: ConstructorDeclaration): ExpressionStatement { + const links = getNodeLinks(constructor); + + // Only trying to find super-call if we haven't yet tried to find one. Once we try, we will record the result + if (links.hasSuperCall === undefined) { + links.superCall = findFirstSuperCall(constructor.body); + links.hasSuperCall = links.superCall ? true : false; + } + return links.superCall; + } + + /** + * Check if the given class-declaration extends null then return true. + * Otherwise, return false + * @param classDecl a class declaration to check if it extends null + */ + function classDeclarationExtendsNull(classDecl: ClassDeclaration): boolean { + const classSymbol = getSymbolOfNode(classDecl); + const classInstanceType = getDeclaredTypeOfSymbol(classSymbol); + const baseConstructorType = getBaseConstructorTypeOfClass(classInstanceType); + + return baseConstructorType === nullType; + } + function checkThisExpression(node: Node): Type { // Stop at the first arrow function so that we can // tell whether 'this' needs to be captured. @@ -7408,10 +7498,25 @@ namespace ts { let needToCaptureLexicalThis = false; if (container.kind === SyntaxKind.Constructor) { - const baseTypeNode = getClassExtendsHeritageClauseElement(container.parent); - if (baseTypeNode && !(getNodeCheckFlags(container) & NodeCheckFlags.HasSeenSuperCall)) { - // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); + const containingClassDecl = container.parent; + const baseTypeNode = getClassExtendsHeritageClauseElement(containingClassDecl); + + // If a containing class does not have extends clause or the class extends null + // skip checking whether super statement is called before "this" accessing. + if (baseTypeNode && !classDeclarationExtendsNull(containingClassDecl)) { + const superCall = getSuperCallInConstructor(container); + + // We should give an error in the following cases: + // - No super-call + // - "this" is accessing before super-call. + // i.e super(this) + // this.x; super(); + // We want to make sure that super-call is done before accessing "this" so that + // "this" is not accessed as a parameter of the super-call. + if (!superCall || superCall.end > node.pos) { + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); + } } } @@ -7897,11 +8002,6 @@ namespace ts { return !!(type.flags & TypeFlags.Union ? forEach((type).types, isTupleLikeType) : isTupleLikeType(type)); } - // Return true if the given contextual type provides an index signature of the given kind - function contextualTypeHasIndexSignature(type: Type, kind: IndexKind): boolean { - return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexInfoOfStructuredType(t, kind)) : getIndexInfoOfStructuredType(type, kind)); - } - // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of // the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one // exists. Otherwise, it is the type of the string index signature in T, if one exists. @@ -8297,6 +8397,17 @@ namespace ts { return links.resolvedType; } + function getObjectLiteralIndexInfo(node: ObjectLiteralExpression, properties: Symbol[], kind: IndexKind): IndexInfo { + const propTypes: Type[] = []; + for (let i = 0; i < properties.length; i++) { + if (kind === IndexKind.String || isNumericName(node.properties[i].name)) { + propTypes.push(getTypeOfSymbol(properties[i])); + } + } + const unionType = propTypes.length ? getUnionType(propTypes) : undefinedType; + return createIndexInfo(unionType, /*isReadonly*/ false); + } + function checkObjectLiteral(node: ObjectLiteralExpression, contextualMapper?: TypeMapper): Type { const inDestructuringPattern = isAssignmentTarget(node); // Grammar checking @@ -8308,8 +8419,10 @@ namespace ts { const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); let typeFlags: TypeFlags = 0; - let patternWithComputedProperties = false; + let hasComputedStringProperty = false; + let hasComputedNumberProperty = false; + for (const memberDecl of node.properties) { let member = memberDecl.symbol; if (memberDecl.kind === SyntaxKind.PropertyAssignment || @@ -8373,7 +8486,15 @@ namespace ts { checkAccessorDeclaration(memberDecl); } - if (!hasDynamicName(memberDecl)) { + if (hasDynamicName(memberDecl)) { + if (isNumericName(memberDecl.name)) { + hasComputedNumberProperty = true; + } + else { + hasComputedStringProperty = true; + } + } + else { propertiesTable[member.name] = member; } propertiesArray.push(member); @@ -8394,8 +8515,8 @@ namespace ts { } } - const stringIndexInfo = getIndexInfo(IndexKind.String); - const numberIndexInfo = getIndexInfo(IndexKind.Number); + const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined; + const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined; const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral; result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0); @@ -8403,29 +8524,6 @@ namespace ts { result.pattern = node; } return result; - - function getIndexInfo(kind: IndexKind) { - if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { - const propTypes: Type[] = []; - for (let i = 0; i < propertiesArray.length; i++) { - const propertyDecl = node.properties[i]; - if (kind === IndexKind.String || isNumericName(propertyDecl.name)) { - // Do not call getSymbolOfNode(propertyDecl), as that will get the - // original symbol for the node. We actually want to get the symbol - // created by checkObjectLiteral, since that will be appropriately - // contextually typed and resolved. - const type = getTypeOfSymbol(propertiesArray[i]); - if (!contains(propTypes, type)) { - propTypes.push(type); - } - } - } - const unionType = propTypes.length ? getUnionType(propTypes) : undefinedType; - typeFlags |= unionType.flags; - return createIndexInfo(unionType, /*isReadonly*/ false); - } - return undefined; - } } function checkJsxSelfClosingElement(node: JsxSelfClosingElement) { @@ -10185,6 +10283,9 @@ namespace ts { // that the user will not add any. const constructSignatures = getSignaturesOfType(expressionType, SignatureKind.Construct); if (constructSignatures.length) { + if (!isConstructorAccessible(node, constructSignatures[0])) { + return resolveErrorCall(node); + } return resolveCall(node, constructSignatures, candidatesOutArray); } @@ -10205,6 +10306,36 @@ namespace ts { return resolveErrorCall(node); } + function isConstructorAccessible(node: NewExpression, signature: Signature) { + if (!signature || !signature.declaration) { + return true; + } + + const declaration = signature.declaration; + const flags = declaration.flags; + + // Public constructor is accessible. + if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) { + return true; + } + + const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(declaration.parent.symbol); + const declaringClass = getDeclaredTypeOfSymbol(declaration.parent.symbol); + + // A private or protected constructor can only be instantiated within it's own class + if (!isNodeWithinClass(node, declaringClassDeclaration)) { + if (flags & NodeFlags.Private) { + error(node, Diagnostics.Constructor_of_class_0_is_private_and_only_accessible_within_the_class_declaration, typeToString(declaringClass)); + } + if (flags & NodeFlags.Protected) { + error(node, Diagnostics.Constructor_of_class_0_is_protected_and_only_accessible_within_the_class_declaration, typeToString(declaringClass)); + } + return false; + } + + return true; + } + function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[]): Signature { const tagType = checkExpression(node.tag); const apparentType = getApparentType(tagType); @@ -10325,14 +10456,11 @@ namespace ts { checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); const signature = getResolvedSignature(node); - if (node.expression.kind === SyntaxKind.SuperKeyword) { - const containingFunction = getContainingFunction(node.expression); - if (containingFunction && containingFunction.kind === SyntaxKind.Constructor) { - getNodeLinks(containingFunction).flags |= NodeCheckFlags.HasSeenSuperCall; - } + if (node.expression.kind === SyntaxKind.SuperKeyword) { return voidType; } + if (node.kind === SyntaxKind.NewExpression) { const declaration = signature.declaration; @@ -10621,12 +10749,13 @@ namespace ts { return aggregatedTypes; } - /* - *TypeScript Specification 1.0 (6.3) - July 2014 - * An explicitly typed function whose return type isn't the Void type, - * the Any type, or a union type containing the Void or Any type as a constituent - * must have at least one return statement somewhere in its body. - * An exception to this rule is if the function implementation consists of a single 'throw' statement. + /** + * TypeScript Specification 1.0 (6.3) - July 2014 + * An explicitly typed function whose return type isn't the Void type, + * the Any type, or a union type containing the Void or Any type as a constituent + * must have at least one return statement somewhere in its body. + * An exception to this rule is if the function implementation consists of a single 'throw' statement. + * * @param returnType - return type of the function, can be undefined if return type is not explicitly specified */ function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func: FunctionLikeDeclaration, returnType: Type): void { @@ -11661,21 +11790,24 @@ namespace ts { return -1; } - function checkTypePredicate(node: TypePredicateNode) { + function checkTypePredicate(node: TypePredicateNode): void { const parent = getTypePredicateParent(node); if (!parent) { + // The parent must not be valid. + error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); return; } - const returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(parent)); - if (!returnType || !(returnType.flags & TypeFlags.PredicateType)) { + + const typePredicate = getSignatureFromDeclaration(parent).typePredicate; + if (!typePredicate) { return; } + const { parameterName } = node; - if (parameterName.kind === SyntaxKind.ThisType) { + if (isThisTypePredicate(typePredicate)) { getTypeFromThisTypeNode(parameterName as ThisTypeNode); } else { - const typePredicate = (returnType).predicate; if (typePredicate.parameterIndex >= 0) { if (parent.parameters[typePredicate.parameterIndex].dotDotDotToken) { error(parameterName, @@ -11690,12 +11822,8 @@ namespace ts { else if (parameterName) { let hasReportedError = false; for (const { name } of parent.parameters) { - if ((name.kind === SyntaxKind.ObjectBindingPattern || - name.kind === SyntaxKind.ArrayBindingPattern) && - checkIfTypePredicateVariableIsDeclaredInBindingPattern( - name, - parameterName, - typePredicate.parameterName)) { + if (isBindingPattern(name) && + checkIfTypePredicateVariableIsDeclaredInBindingPattern(name, parameterName, typePredicate.parameterName)) { hasReportedError = true; break; } @@ -11763,8 +11891,9 @@ namespace ts { forEach(node.parameters, checkParameter); - checkSourceElement(node.type); - + if (node.type) { + checkSourceElement(node.type); + } if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); @@ -11931,13 +12060,11 @@ namespace ts { // constructors of derived classes must contain at least one super call somewhere in their function body. const containingClassDecl = node.parent; if (getClassExtendsHeritageClauseElement(containingClassDecl)) { - const containingClassSymbol = getSymbolOfNode(containingClassDecl); - const containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); - const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); - - if (containsSuperCall(node.body)) { - if (baseConstructorType === nullType) { - error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); + const classExtendsNull = classDeclarationExtendsNull(containingClassDecl); + const superCall = getSuperCallInConstructor(node); + if (superCall) { + if (classExtendsNull) { + error(superCall, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } // The first statement in the body of a constructor (excluding prologue directives) must be a super call @@ -11954,6 +12081,7 @@ namespace ts { if (superCallShouldBeFirst) { const statements = (node.body).statements; let superCallStatement: ExpressionStatement; + for (const statement of statements) { if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { superCallStatement = statement; @@ -11968,7 +12096,7 @@ namespace ts { } } } - else if (baseConstructorType !== nullType) { + else if (!classExtendsNull) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); } } @@ -12159,7 +12287,7 @@ namespace ts { error(o.name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); } else if (deviation & (NodeFlags.Private | NodeFlags.Protected)) { - error(o.name, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); + error(o.name || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & NodeFlags.Abstract) { error(o.name, Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract); @@ -12827,7 +12955,7 @@ namespace ts { } if (!compilerOptions.experimentalDecorators) { - error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); + error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning); } if (compilerOptions.emitDecoratorMetadata) { @@ -13721,7 +13849,7 @@ namespace ts { error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } - else if (func.type || isGetAccessorWithAnnotatedSetAccessor(func) || returnType.flags & TypeFlags.PredicateType) { + else if (func.type || isGetAccessorWithAnnotatedSetAccessor(func)) { if (isAsyncFunctionLike(func)) { const promisedType = getPromisedType(returnType); const awaitedType = checkAwaitedType(exprType, node.expression, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); @@ -14028,6 +14156,7 @@ namespace ts { if (baseTypes.length && produceDiagnostics) { const baseType = baseTypes[0]; const staticBaseType = getBaseConstructorTypeOfClass(type); + checkBaseTypeAccessibility(staticBaseType, baseTypeNode); checkSourceElement(baseTypeNode.expression); if (baseTypeNode.typeArguments) { forEach(baseTypeNode.typeArguments, checkSourceElement); @@ -14083,6 +14212,19 @@ namespace ts { } } + function checkBaseTypeAccessibility(type: ObjectType, node: ExpressionWithTypeArguments) { + const signatures = getSignaturesOfType(type, SignatureKind.Construct); + if (signatures.length) { + const declaration = signatures[0].declaration; + if (declaration && declaration.flags & NodeFlags.Private) { + const typeClassDeclaration = getClassLikeDeclarationOfSymbol(type.symbol); + if (!isNodeWithinClass(node, typeClassDeclaration)) { + error(node, Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, (node.expression).text); + } + } + } + } + function getTargetSymbol(s: Symbol) { // if symbol is instantiated its flags are not copied from the 'target' // so we'll need to get back original 'target' symbol to work with correct set of flags @@ -15000,11 +15142,20 @@ namespace ts { continue; } const { declarations, flags } = exports[id]; - // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries. (TS Exceptions: namespaces, function overloads, enums, and interfaces) - if (!(flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) && (flags & SymbolFlags.TypeAlias ? declarations.length - 1 : declarations.length) > 1) { - const exportedDeclarations: Declaration[] = filter(declarations, isNotOverload); - if (exportedDeclarations.length > 1) { - for (const declaration of exportedDeclarations) { + // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries. + // (TS Exceptions: namespaces, function overloads, enums, and interfaces) + if (flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) { + continue; + } + const exportedDeclarationsCount = countWhere(declarations, isNotOverload); + if (flags & SymbolFlags.TypeAlias && exportedDeclarationsCount <= 2) { + // it is legal to merge type alias with other values + // so count should be either 1 (just type alias) or 2 (type alias + merged value) + continue; + } + if (exportedDeclarationsCount > 1) { + for (const declaration of declarations) { + if (isNotOverload(declaration)) { diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Cannot_redeclare_exported_variable_0, id)); } } @@ -15407,6 +15558,18 @@ namespace ts { return node.parent && node.parent.kind === SyntaxKind.ExpressionWithTypeArguments; } + function isNodeWithinClass(node: Node, classDeclaration: ClassLikeDeclaration) { + while (true) { + node = getContainingClass(node); + if (!node) { + return false; + } + if (node === classDeclaration) { + return true; + } + } + } + function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide: EntityName): ImportEqualsDeclaration | ExportAssignment { while (nodeOnRightSide.parent.kind === SyntaxKind.QualifiedName) { nodeOnRightSide = nodeOnRightSide.parent; @@ -16290,16 +16453,12 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PrivateKeyword: - let text: string; - if (modifier.kind === SyntaxKind.PublicKeyword) { - text = "public"; - } - else if (modifier.kind === SyntaxKind.ProtectedKeyword) { - text = "protected"; + let text = visibilityToString(modifierToFlag(modifier.kind)); + + if (modifier.kind === SyntaxKind.ProtectedKeyword) { lastProtected = modifier; } - else { - text = "private"; + else if (modifier.kind === SyntaxKind.PrivateKeyword) { lastPrivate = modifier; } @@ -16450,12 +16609,6 @@ namespace ts { if (flags & NodeFlags.Abstract) { return grammarErrorOnNode(lastStatic, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); } - else if (flags & NodeFlags.Protected) { - return grammarErrorOnNode(lastProtected, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); - } - else if (flags & NodeFlags.Private) { - return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); - } else if (flags & NodeFlags.Async) { return grammarErrorOnNode(lastAsync, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index d8bdd2fb52f..1328a2e8484 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1313,7 +1313,7 @@ namespace ts { if (node.kind === SyntaxKind.FunctionDeclaration) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === SyntaxKind.MethodDeclaration) { + else if (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.Constructor) { emitClassMemberDeclarationFlags(node.flags); } if (node.kind === SyntaxKind.FunctionDeclaration) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6978a9ad611..2119d0f0c53 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -687,7 +687,7 @@ "category": "Error", "code": 1218 }, - "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.": { + "Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": { "category": "Error", "code": 1219 }, @@ -723,6 +723,10 @@ "category": "Error", "code": 1227 }, + "A type predicate is only allowed in return type position for functions and methods.": { + "category": "Error", + "code": 1228 + }, "A type predicate cannot reference a rest parameter.": { "category": "Error", "code": 1229 @@ -1699,6 +1703,10 @@ "category": "Error", "code": 2529 }, + "Property '{0}' is incompatible with index signature.": { + "category": "Error", + "code": 2530 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 @@ -1819,6 +1827,22 @@ "category": "Error", "code": 2671 }, + "Cannot assign a '{0}' constructor type to a '{1}' constructor type.": { + "category": "Error", + "code": 2672 + }, + "Constructor of class '{0}' is private and only accessible within the class declaration.": { + "category": "Error", + "code": 2673 + }, + "Constructor of class '{0}' is protected and only accessible within the class declaration.": { + "category": "Error", + "code": 2674 + }, + "Cannot extend a class '{0}'. Class constructor is marked as private.": { + "category": "Error", + "code": 2675 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 @@ -2733,11 +2757,6 @@ "category": "Error", "code": 8016 }, - "'decorators' can only be used in a .ts file.": { - "category": "Error", - "code": 8017 - }, - "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": { "category": "Error", "code": 9002 @@ -2786,4 +2805,4 @@ "category": "Error", "code": 17009 } -} \ No newline at end of file +} diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f3a9e5cbf85..0d3cdfe733e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1940,7 +1940,7 @@ namespace ts { return finishNode(node); } - function parseTypePredicate(lhs: Identifier | ThisTypeNode): TypePredicateNode { + function parseThisTypePredicate(lhs: ThisTypeNode): TypePredicateNode { nextToken(); const node = createNode(SyntaxKind.TypePredicate, lhs.pos) as TypePredicateNode; node.parameterName = lhs; @@ -2365,7 +2365,7 @@ namespace ts { case SyntaxKind.ThisKeyword: { const thisKeyword = parseThisTypeNode(); if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { - return parseTypePredicate(thisKeyword); + return parseThisTypePredicate(thisKeyword); } else { return thisKeyword; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7a2e65ed33b..d41f34df0b3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -533,18 +533,25 @@ namespace ts { } let referencedSourceFile: string; - while (true) { - const searchName = normalizePath(combinePaths(containingDirectory, moduleName)); - referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state); - if (referencedSourceFile) { - break; + if (moduleHasNonRelativeName(moduleName)) { + while (true) { + const searchName = normalizePath(combinePaths(containingDirectory, moduleName)); + referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state); + if (referencedSourceFile) { + break; + } + const parentPath = getDirectoryPath(containingDirectory); + if (parentPath === containingDirectory) { + break; + } + containingDirectory = parentPath; } - const parentPath = getDirectoryPath(containingDirectory); - if (parentPath === containingDirectory) { - break; - } - containingDirectory = parentPath; } + else { + const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); + referencedSourceFile = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state); + } + return referencedSourceFile ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations } @@ -946,13 +953,27 @@ namespace ts { } function emitWorker(program: Program, sourceFile: SourceFile, writeFileCallback: WriteFileCallback, cancellationToken: CancellationToken): EmitResult { + let declarationDiagnostics: Diagnostic[] = []; + + if (options.noEmit) { + return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emitSkipped: true }; + } + // If the noEmitOnError flag is set, then check if we have any errors so far. If so, // immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we // get any preEmit diagnostics, not just the ones if (options.noEmitOnError) { - const preEmitDiagnostics = getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken); - if (preEmitDiagnostics.length > 0) { - return { diagnostics: preEmitDiagnostics, sourceMaps: undefined, emitSkipped: true }; + const diagnostics = program.getOptionsDiagnostics(cancellationToken).concat( + program.getSyntacticDiagnostics(sourceFile, cancellationToken), + program.getGlobalDiagnostics(cancellationToken), + program.getSemanticDiagnostics(sourceFile, cancellationToken)); + + if (diagnostics.length === 0 && program.getCompilerOptions().declaration) { + declarationDiagnostics = program.getDeclarationDiagnostics(/*sourceFile*/ undefined, cancellationToken); + } + + if (diagnostics.length > 0 || declarationDiagnostics.length > 0) { + return { diagnostics, sourceMaps: undefined, emitSkipped: true }; } } @@ -1169,7 +1190,9 @@ namespace ts { diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); return true; case SyntaxKind.Decorator: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.decorators_can_only_be_used_in_a_ts_file)); + if (!options.experimentalDecorators) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning)); + } return true; } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c69bfca1877..e5b85a7391e 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -590,30 +590,21 @@ namespace ts { } } - reportDiagnostics(diagnostics, compilerHost); - - // If the user doesn't want us to emit, then we're done at this point. - if (compilerOptions.noEmit) { - return diagnostics.length - ? ExitStatus.DiagnosticsPresent_OutputsSkipped - : ExitStatus.Success; - } - // Otherwise, emit and report any errors we ran into. const emitOutput = program.emit(); - reportDiagnostics(emitOutput.diagnostics, compilerHost); + diagnostics = diagnostics.concat(emitOutput.diagnostics); - // If the emitter didn't emit anything, then pass that value along. - if (emitOutput.emitSkipped) { + reportDiagnostics(sortAndDeduplicateDiagnostics(diagnostics), compilerHost); + + if (emitOutput.emitSkipped && diagnostics.length > 0) { + // If the emitter didn't emit anything, then pass that value along. return ExitStatus.DiagnosticsPresent_OutputsSkipped; } - - // The emitter emitted something, inform the caller if that happened in the presence - // of diagnostics or not. - if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) { + else if (diagnostics.length > 0) { + // The emitter emitted something, inform the caller if that happened in the presence + // of diagnostics or not. return ExitStatus.DiagnosticsPresent_OutputsGenerated; } - return ExitStatus.Success; } } @@ -719,14 +710,16 @@ namespace ts { else { const compilerOptions = extend(options, defaultInitCompilerOptions); const configurations: any = { - compilerOptions: serializeCompilerOptions(compilerOptions), - exclude: ["node_modules"] + compilerOptions: serializeCompilerOptions(compilerOptions) }; if (fileNames && fileNames.length) { // only set the files property if we have at least one file configurations.files = fileNames; } + else { + configurations.exclude = ["node_modules"]; + } sys.writeFile(file, JSON.stringify(configurations, undefined, 4)); reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* compilerHost */ undefined); diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index ca297c087cf..5460f162935 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, @@ -8,9 +7,9 @@ "sourceMap": true }, "files": [ + "types.ts", "core.ts", "sys.ts", - "types.ts", "diagnosticInformationMap.generated.ts", "scanner.ts", "parser.ts", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index af4045cf643..11273a34bf8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -428,7 +428,6 @@ namespace ts { IntrinsicElement = IntrinsicNamedElement | IntrinsicIndexedElement, } - /* @internal */ export const enum RelationComparisonResult { Succeeded = 1, // Should be truthy @@ -1693,6 +1692,7 @@ namespace ts { export interface EmitResult { emitSkipped: boolean; + /** Contains declaration emit diagnostics */ diagnostics: Diagnostic[]; /* @internal */ sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps } @@ -1761,6 +1761,7 @@ namespace ts { buildSignatureDisplay(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): void; buildParameterDisplay(parameter: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildTypePredicateDisplay(predicate: TypePredicate, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; @@ -1826,22 +1827,24 @@ namespace ts { Identifier } - export interface TypePredicate { + export interface TypePredicateBase { kind: TypePredicateKind; type: Type; } // @kind (TypePredicateKind.This) - export interface ThisTypePredicate extends TypePredicate { + export interface ThisTypePredicate extends TypePredicateBase { _thisTypePredicateBrand: any; } // @kind (TypePredicateKind.Identifier) - export interface IdentifierTypePredicate extends TypePredicate { + export interface IdentifierTypePredicate extends TypePredicateBase { parameterName: string; parameterIndex: number; } + export type TypePredicate = IdentifierTypePredicate | ThisTypePredicate; + /* @internal */ export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; @@ -2049,10 +2052,9 @@ namespace ts { LoopWithCapturedBlockScopedBinding = 0x00010000, // Loop that contains block scoped variable captured in closure CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement - HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super' - ClassWithBodyScopedClassBinding = 0x00100000, // Decorated class that contains a binding to itself inside of the class body. - BodyScopedClassBinding = 0x00200000, // Binding to a decorated class inside of the class's body. - NeedsLoopOutParameter = 0x00400000, // Block scoped binding whose value should be explicitly copied outside of the converted loop + ClassWithBodyScopedClassBinding = 0x00080000, // Decorated class that contains a binding to itself inside of the class body. + BodyScopedClassBinding = 0x00100000, // Binding to a decorated class inside of the class's body. + NeedsLoopOutParameter = 0x00200000, // Block scoped binding whose value should be explicitly copied outside of the converted loop } /* @internal */ @@ -2072,6 +2074,8 @@ namespace ts { importOnRightSide?: Symbol; // for import declarations - import that appear on the right side jsxFlags?: JsxFlags; // flags for knowing what kind of element/attributes we're dealing with resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element + hasSuperCall?: boolean; // recorded result when we try to find super-call. We only try to find one if this flag is undefined, indicating that we haven't made an attempt. + superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing } export const enum TypeFlags { @@ -2106,7 +2110,6 @@ namespace ts { ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 ThisType = 0x02000000, // This type ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties - PredicateType = 0x08000000, // Predicate types are also Boolean types, but should not be considered Intrinsics - there's no way to capture this with flags /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined, @@ -2118,7 +2121,7 @@ namespace ts { UnionOrIntersection = Union | Intersection, StructuredType = ObjectType | Union | Intersection, /* @internal */ - RequiresWidening = ContainsUndefined | ContainsObjectLiteral | PredicateType, + RequiresWidening = ContainsUndefined | ContainsObjectLiteral, /* @internal */ PropagatingFlags = ContainsUndefined | ContainsObjectLiteral | ContainsAnyFunctionType } @@ -2140,11 +2143,6 @@ namespace ts { intrinsicName: string; // Name of intrinsic type } - // Predicate types (TypeFlags.Predicate) - export interface PredicateType extends Type { - predicate: ThisTypePredicate | IdentifierTypePredicate; - } - // String literal types (TypeFlags.StringLiteral) export interface StringLiteralType extends Type { text: string; // Text of string literal @@ -2281,6 +2279,8 @@ namespace ts { erasedSignatureCache?: Signature; // Erased version of signature (deferred) /* @internal */ isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison + /* @internal */ + typePredicate?: TypePredicate; } export const enum IndexKind { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 50005d5c070..7012326fa98 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -748,6 +748,10 @@ namespace ts { return predicate && predicate.kind === TypePredicateKind.Identifier; } + export function isThisTypePredicate(predicate: TypePredicate): predicate is ThisTypePredicate { + return predicate && predicate.kind === TypePredicateKind.This; + } + export function getContainingFunction(node: Node): FunctionLikeDeclaration { while (true) { node = node.parent; diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index 2c8538c61e3..0772210cb15 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 5dcee789243..001071ed88d 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 3830e53697c..5f55c04c9f9 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -16,7 +16,7 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void var program = ts.createProgram(fileNames, options); var emitResult = program.emit(); - var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program); allDiagnostics.forEach(diagnostic => { var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); @@ -45,7 +45,7 @@ var ts = require("typescript"); function compile(fileNames, options) { var program = ts.createProgram(fileNames, options); var emitResult = program.emit(); - var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program); allDiagnostics.forEach(function (diagnostic) { var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); diff --git a/tests/baselines/reference/Protected3.errors.txt b/tests/baselines/reference/Protected3.errors.txt deleted file mode 100644 index 688422a1e0f..00000000000 --- a/tests/baselines/reference/Protected3.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts(2,3): error TS1089: 'protected' modifier cannot appear on a constructor declaration. - - -==== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts (1 errors) ==== - class C { - protected constructor() { } - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. - } \ No newline at end of file diff --git a/tests/baselines/reference/Protected3.symbols b/tests/baselines/reference/Protected3.symbols new file mode 100644 index 00000000000..a9882189902 --- /dev/null +++ b/tests/baselines/reference/Protected3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === +class C { +>C : Symbol(C, Decl(Protected3.ts, 0, 0)) + + protected constructor() { } +} diff --git a/tests/baselines/reference/Protected3.types b/tests/baselines/reference/Protected3.types new file mode 100644 index 00000000000..d3f938a4431 --- /dev/null +++ b/tests/baselines/reference/Protected3.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === +class C { +>C : C + + protected constructor() { } +} diff --git a/tests/baselines/reference/arrayBufferIsViewNarrowsType.types b/tests/baselines/reference/arrayBufferIsViewNarrowsType.types index b9d4f3db81b..129b7d601d8 100644 --- a/tests/baselines/reference/arrayBufferIsViewNarrowsType.types +++ b/tests/baselines/reference/arrayBufferIsViewNarrowsType.types @@ -4,7 +4,7 @@ var obj: Object; >Object : Object if (ArrayBuffer.isView(obj)) { ->ArrayBuffer.isView(obj) : arg is ArrayBufferView +>ArrayBuffer.isView(obj) : boolean >ArrayBuffer.isView : (arg: any) => arg is ArrayBufferView >ArrayBuffer : ArrayBufferConstructor >isView : (arg: any) => arg is ArrayBufferView diff --git a/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt b/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt index eb5020e97f9..e99cac7968c 100644 --- a/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt +++ b/tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.errors.txt @@ -1,10 +1,8 @@ -tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts(15,5): error TS2322: Type '{}' is not assignable to type '{ [n: number]: Foo; }'. - Index signature is missing in type '{}'. tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts(19,5): error TS2322: Type '() => void' is not assignable to type '{ [n: number]: Bar; }'. Index signature is missing in type '() => void'. -==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ==== +==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (1 errors) ==== interface Foo { a } interface Bar { b } @@ -20,9 +18,6 @@ tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignatur var f = () => { }; var v1: { - ~~ -!!! error TS2322: Type '{}' is not assignable to type '{ [n: number]: Foo; }'. -!!! error TS2322: Index signature is missing in type '{}'. [n: number]: Foo } = o; // Should be allowed diff --git a/tests/baselines/reference/badOverloadError.types b/tests/baselines/reference/badOverloadError.types index b8ae583a73c..198582af2db 100644 --- a/tests/baselines/reference/badOverloadError.types +++ b/tests/baselines/reference/badOverloadError.types @@ -6,6 +6,6 @@ function method() { >dictionary : { [index: string]: string; } ><{ [index: string]: string; }>{} : { [index: string]: string; } >index : string ->{} : { [x: string]: undefined; } +>{} : {} } diff --git a/tests/baselines/reference/bestCommonTypeWithContextualTyping.types b/tests/baselines/reference/bestCommonTypeWithContextualTyping.types index 628fe82012a..5baca43b752 100644 --- a/tests/baselines/reference/bestCommonTypeWithContextualTyping.types +++ b/tests/baselines/reference/bestCommonTypeWithContextualTyping.types @@ -36,7 +36,7 @@ var obj: { [s: string]: Contextual } = { s: e }; // { s: Ellement; [s: string]: >obj : { [s: string]: Contextual; } >s : string >Contextual : Contextual ->{ s: e } : { [x: string]: Ellement; s: Ellement; } +>{ s: e } : { s: Ellement; } >s : Ellement >e : Ellement diff --git a/tests/baselines/reference/classConstructorAccessibility.errors.txt b/tests/baselines/reference/classConstructorAccessibility.errors.txt index c22f3593bc5..c79633ba33d 100644 --- a/tests/baselines/reference/classConstructorAccessibility.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility.errors.txt @@ -1,29 +1,30 @@ -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(6,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(10,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(23,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(27,9): error TS1089: 'protected' modifier cannot appear on a constructor declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(15,9): error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. ==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (4 errors) ==== + class C { public constructor(public x: number) { } } class D { - private constructor(public x: number) { } // error - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. + private constructor(public x: number) { } } class E { - protected constructor(public x: number) { } // error - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. + protected constructor(public x: number) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + ~~~~~~~~ +!!! error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. + var e = new E(1); // error + ~~~~~~~~ +!!! error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. module Generic { class C { @@ -31,19 +32,19 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib } class D { - private constructor(public x: T) { } // error - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. + private constructor(public x: T) { } } class E { - protected constructor(public x: T) { } // error - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. + protected constructor(public x: T) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + ~~~~~~~~ +!!! error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. + var e = new E(1); // error + ~~~~~~~~ +!!! error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. } \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility.js b/tests/baselines/reference/classConstructorAccessibility.js index fed96385845..efc3f3c273c 100644 --- a/tests/baselines/reference/classConstructorAccessibility.js +++ b/tests/baselines/reference/classConstructorAccessibility.js @@ -1,19 +1,20 @@ //// [classConstructorAccessibility.ts] + class C { public constructor(public x: number) { } } class D { - private constructor(public x: number) { } // error + private constructor(public x: number) { } } class E { - protected constructor(public x: number) { } // error + protected constructor(public x: number) { } } var c = new C(1); -var d = new D(1); -var e = new E(1); +var d = new D(1); // error +var e = new E(1); // error module Generic { class C { @@ -21,16 +22,16 @@ module Generic { } class D { - private constructor(public x: T) { } // error + private constructor(public x: T) { } } class E { - protected constructor(public x: T) { } // error + protected constructor(public x: T) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + var e = new E(1); // error } @@ -44,18 +45,18 @@ var C = (function () { var D = (function () { function D(x) { this.x = x; - } // error + } return D; }()); var E = (function () { function E(x) { this.x = x; - } // error + } return E; }()); var c = new C(1); -var d = new D(1); -var e = new E(1); +var d = new D(1); // error +var e = new E(1); // error var Generic; (function (Generic) { var C = (function () { @@ -67,16 +68,36 @@ var Generic; var D = (function () { function D(x) { this.x = x; - } // error + } return D; }()); var E = (function () { function E(x) { this.x = x; - } // error + } return E; }()); var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + var e = new E(1); // error })(Generic || (Generic = {})); + + +//// [classConstructorAccessibility.d.ts] +declare class C { + x: number; + constructor(x: number); +} +declare class D { + x: number; + private constructor(x); +} +declare class E { + x: number; + protected constructor(x: number); +} +declare var c: C; +declare var d: any; +declare var e: any; +declare module Generic { +} diff --git a/tests/baselines/reference/classConstructorAccessibility2.errors.txt b/tests/baselines/reference/classConstructorAccessibility2.errors.txt new file mode 100644 index 00000000000..7bd784ac268 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility2.errors.txt @@ -0,0 +1,59 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(26,28): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(29,24): error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,28): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,10): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(37,10): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts (5 errors) ==== + + class BaseA { + public constructor(public x: number) { } + createInstance() { new BaseA(1); } + } + + class BaseB { + protected constructor(public x: number) { } + createInstance() { new BaseB(1); } + } + + class BaseC { + private constructor(public x: number) { } + createInstance() { new BaseC(1); } + } + + class DerivedA extends BaseA { + constructor(public x: number) { super(x); } + createInstance() { new DerivedA(1); } + createBaseInstance() { new BaseA(1); } + } + + class DerivedB extends BaseB { + constructor(public x: number) { super(x); } + createInstance() { new DerivedB(1); } + createBaseInstance() { new BaseB(1); } // error + ~~~~~~~~~~~~ +!!! error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. + } + + class DerivedC extends BaseC { // error + ~~~~~ +!!! error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. + constructor(public x: number) { super(x); } + createInstance() { new DerivedC(1); } + createBaseInstance() { new BaseC(1); } // error + ~~~~~~~~~~~~ +!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. + } + + var ba = new BaseA(1); + var bb = new BaseB(1); // error + ~~~~~~~~~~~~ +!!! error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. + var bc = new BaseC(1); // error + ~~~~~~~~~~~~ +!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. + + var da = new DerivedA(1); + var db = new DerivedB(1); + var dc = new DerivedC(1); \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility2.js b/tests/baselines/reference/classConstructorAccessibility2.js new file mode 100644 index 00000000000..e19589ece45 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility2.js @@ -0,0 +1,148 @@ +//// [classConstructorAccessibility2.ts] + +class BaseA { + public constructor(public x: number) { } + createInstance() { new BaseA(1); } +} + +class BaseB { + protected constructor(public x: number) { } + createInstance() { new BaseB(1); } +} + +class BaseC { + private constructor(public x: number) { } + createInstance() { new BaseC(1); } +} + +class DerivedA extends BaseA { + constructor(public x: number) { super(x); } + createInstance() { new DerivedA(1); } + createBaseInstance() { new BaseA(1); } +} + +class DerivedB extends BaseB { + constructor(public x: number) { super(x); } + createInstance() { new DerivedB(1); } + createBaseInstance() { new BaseB(1); } // error +} + +class DerivedC extends BaseC { // error + constructor(public x: number) { super(x); } + createInstance() { new DerivedC(1); } + createBaseInstance() { new BaseC(1); } // error +} + +var ba = new BaseA(1); +var bb = new BaseB(1); // error +var bc = new BaseC(1); // error + +var da = new DerivedA(1); +var db = new DerivedB(1); +var dc = new DerivedC(1); + +//// [classConstructorAccessibility2.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 BaseA = (function () { + function BaseA(x) { + this.x = x; + } + BaseA.prototype.createInstance = function () { new BaseA(1); }; + return BaseA; +}()); +var BaseB = (function () { + function BaseB(x) { + this.x = x; + } + BaseB.prototype.createInstance = function () { new BaseB(1); }; + return BaseB; +}()); +var BaseC = (function () { + function BaseC(x) { + this.x = x; + } + BaseC.prototype.createInstance = function () { new BaseC(1); }; + return BaseC; +}()); +var DerivedA = (function (_super) { + __extends(DerivedA, _super); + function DerivedA(x) { + _super.call(this, x); + this.x = x; + } + DerivedA.prototype.createInstance = function () { new DerivedA(1); }; + DerivedA.prototype.createBaseInstance = function () { new BaseA(1); }; + return DerivedA; +}(BaseA)); +var DerivedB = (function (_super) { + __extends(DerivedB, _super); + function DerivedB(x) { + _super.call(this, x); + this.x = x; + } + DerivedB.prototype.createInstance = function () { new DerivedB(1); }; + DerivedB.prototype.createBaseInstance = function () { new BaseB(1); }; // error + return DerivedB; +}(BaseB)); +var DerivedC = (function (_super) { + __extends(DerivedC, _super); + function DerivedC(x) { + _super.call(this, x); + this.x = x; + } + DerivedC.prototype.createInstance = function () { new DerivedC(1); }; + DerivedC.prototype.createBaseInstance = function () { new BaseC(1); }; // error + return DerivedC; +}(BaseC)); +var ba = new BaseA(1); +var bb = new BaseB(1); // error +var bc = new BaseC(1); // error +var da = new DerivedA(1); +var db = new DerivedB(1); +var dc = new DerivedC(1); + + +//// [classConstructorAccessibility2.d.ts] +declare class BaseA { + x: number; + constructor(x: number); + createInstance(): void; +} +declare class BaseB { + x: number; + protected constructor(x: number); + createInstance(): void; +} +declare class BaseC { + x: number; + private constructor(x); + createInstance(): void; +} +declare class DerivedA extends BaseA { + x: number; + constructor(x: number); + createInstance(): void; + createBaseInstance(): void; +} +declare class DerivedB extends BaseB { + x: number; + constructor(x: number); + createInstance(): void; + createBaseInstance(): void; +} +declare class DerivedC extends BaseC { + x: number; + constructor(x: number); + createInstance(): void; + createBaseInstance(): void; +} +declare var ba: BaseA; +declare var bb: any; +declare var bc: any; +declare var da: DerivedA; +declare var db: DerivedB; +declare var dc: DerivedC; diff --git a/tests/baselines/reference/classConstructorAccessibility3.errors.txt b/tests/baselines/reference/classConstructorAccessibility3.errors.txt new file mode 100644 index 00000000000..1b96db289dc --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility3.errors.txt @@ -0,0 +1,52 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(21,1): error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Foo'. + Cannot assign a 'protected' constructor type to a 'public' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(22,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'. + Cannot assign a 'private' constructor type to a 'public' constructor type. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts(28,1): error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'. + Cannot assign a 'private' constructor type to a 'protected' constructor type. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts (3 errors) ==== + + class Foo { + constructor(public x: number) { } + } + + class Bar { + public constructor(public x: number) { } + } + + class Baz { + protected constructor(public x: number) { } + } + + class Qux { + private constructor(public x: number) { } + } + + // b is public + let a = Foo; + a = Bar; + a = Baz; // error Baz is protected + ~ +!!! error TS2322: Type 'typeof Baz' is not assignable to type 'typeof Foo'. +!!! error TS2322: Cannot assign a 'protected' constructor type to a 'public' constructor type. + a = Qux; // error Qux is private + ~ +!!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Foo'. +!!! error TS2322: Cannot assign a 'private' constructor type to a 'public' constructor type. + + // b is protected + let b = Baz; + b = Foo; + b = Bar; + b = Qux; // error Qux is private + ~ +!!! error TS2322: Type 'typeof Qux' is not assignable to type 'typeof Baz'. +!!! error TS2322: Cannot assign a 'private' constructor type to a 'protected' constructor type. + + // c is private + let c = Qux; + c = Foo; + c = Bar; + c = Baz; \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility3.js b/tests/baselines/reference/classConstructorAccessibility3.js new file mode 100644 index 00000000000..acc7d38aa55 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility3.js @@ -0,0 +1,98 @@ +//// [classConstructorAccessibility3.ts] + +class Foo { + constructor(public x: number) { } +} + +class Bar { + public constructor(public x: number) { } +} + +class Baz { + protected constructor(public x: number) { } +} + +class Qux { + private constructor(public x: number) { } +} + +// b is public +let a = Foo; +a = Bar; +a = Baz; // error Baz is protected +a = Qux; // error Qux is private + +// b is protected +let b = Baz; +b = Foo; +b = Bar; +b = Qux; // error Qux is private + +// c is private +let c = Qux; +c = Foo; +c = Bar; +c = Baz; + +//// [classConstructorAccessibility3.js] +var Foo = (function () { + function Foo(x) { + this.x = x; + } + return Foo; +}()); +var Bar = (function () { + function Bar(x) { + this.x = x; + } + return Bar; +}()); +var Baz = (function () { + function Baz(x) { + this.x = x; + } + return Baz; +}()); +var Qux = (function () { + function Qux(x) { + this.x = x; + } + return Qux; +}()); +// b is public +var a = Foo; +a = Bar; +a = Baz; // error Baz is protected +a = Qux; // error Qux is private +// b is protected +var b = Baz; +b = Foo; +b = Bar; +b = Qux; // error Qux is private +// c is private +var c = Qux; +c = Foo; +c = Bar; +c = Baz; + + +//// [classConstructorAccessibility3.d.ts] +declare class Foo { + x: number; + constructor(x: number); +} +declare class Bar { + x: number; + constructor(x: number); +} +declare class Baz { + x: number; + protected constructor(x: number); +} +declare class Qux { + x: number; + private constructor(x); +} +declare let a: typeof Foo; +declare let b: typeof Baz; +declare let c: typeof Qux; diff --git a/tests/baselines/reference/classConstructorAccessibility4.js b/tests/baselines/reference/classConstructorAccessibility4.js new file mode 100644 index 00000000000..6342facae21 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility4.js @@ -0,0 +1,93 @@ +//// [classConstructorAccessibility4.ts] + +class A { + private constructor() { } + + method() { + class B { + method() { + new A(); // OK + } + } + + class C extends A { // OK + } + } +} + +class D { + protected constructor() { } + + method() { + class E { + method() { + new D(); // OK + } + } + + class F extends D { // OK + } + } +} + +//// [classConstructorAccessibility4.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.method = function () { + var B = (function () { + function B() { + } + B.prototype.method = function () { + new A(); // OK + }; + return B; + }()); + var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; + }(A)); + }; + return A; +}()); +var D = (function () { + function D() { + } + D.prototype.method = function () { + var E = (function () { + function E() { + } + E.prototype.method = function () { + new D(); // OK + }; + return E; + }()); + var F = (function (_super) { + __extends(F, _super); + function F() { + _super.apply(this, arguments); + } + return F; + }(D)); + }; + return D; +}()); + + +//// [classConstructorAccessibility4.d.ts] +declare class A { + private constructor(); + method(): void; +} +declare class D { + protected constructor(); + method(): void; +} diff --git a/tests/baselines/reference/classConstructorAccessibility4.symbols b/tests/baselines/reference/classConstructorAccessibility4.symbols new file mode 100644 index 00000000000..e3d8301ca68 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility4.symbols @@ -0,0 +1,53 @@ +=== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility4.ts === + +class A { +>A : Symbol(A, Decl(classConstructorAccessibility4.ts, 0, 0)) + + private constructor() { } + + method() { +>method : Symbol(method, Decl(classConstructorAccessibility4.ts, 2, 29)) + + class B { +>B : Symbol(B, Decl(classConstructorAccessibility4.ts, 4, 14)) + + method() { +>method : Symbol(method, Decl(classConstructorAccessibility4.ts, 5, 17)) + + new A(); // OK +>A : Symbol(A, Decl(classConstructorAccessibility4.ts, 0, 0)) + } + } + + class C extends A { // OK +>C : Symbol(C, Decl(classConstructorAccessibility4.ts, 9, 9)) +>A : Symbol(A, Decl(classConstructorAccessibility4.ts, 0, 0)) + } + } +} + +class D { +>D : Symbol(D, Decl(classConstructorAccessibility4.ts, 14, 1)) + + protected constructor() { } + + method() { +>method : Symbol(method, Decl(classConstructorAccessibility4.ts, 17, 31)) + + class E { +>E : Symbol(E, Decl(classConstructorAccessibility4.ts, 19, 14)) + + method() { +>method : Symbol(method, Decl(classConstructorAccessibility4.ts, 20, 17)) + + new D(); // OK +>D : Symbol(D, Decl(classConstructorAccessibility4.ts, 14, 1)) + } + } + + class F extends D { // OK +>F : Symbol(F, Decl(classConstructorAccessibility4.ts, 24, 9)) +>D : Symbol(D, Decl(classConstructorAccessibility4.ts, 14, 1)) + } + } +} diff --git a/tests/baselines/reference/classConstructorAccessibility4.types b/tests/baselines/reference/classConstructorAccessibility4.types new file mode 100644 index 00000000000..1eb5a25e220 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility4.types @@ -0,0 +1,55 @@ +=== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility4.ts === + +class A { +>A : A + + private constructor() { } + + method() { +>method : () => void + + class B { +>B : B + + method() { +>method : () => void + + new A(); // OK +>new A() : A +>A : typeof A + } + } + + class C extends A { // OK +>C : C +>A : A + } + } +} + +class D { +>D : D + + protected constructor() { } + + method() { +>method : () => void + + class E { +>E : E + + method() { +>method : () => void + + new D(); // OK +>new D() : D +>D : typeof D + } + } + + class F extends D { // OK +>F : F +>D : D + } + } +} diff --git a/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt b/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt new file mode 100644 index 00000000000..8882b9f0180 --- /dev/null +++ b/tests/baselines/reference/classConstructorOverloadsAccessibility.errors.txt @@ -0,0 +1,45 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(3,2): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(4,2): error TS2385: Overload signatures must all be public, private or protected. +tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts(12,2): error TS2385: Overload signatures must all be public, private or protected. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts (3 errors) ==== + + class A { + public constructor(a: boolean) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2385: Overload signatures must all be public, private or protected. + protected constructor(a: number) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2385: Overload signatures must all be public, private or protected. + private constructor(a: string) + private constructor() { + + } + } + + class B { + protected constructor(a: number) // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2385: Overload signatures must all be public, private or protected. + constructor(a: string) + constructor() { + + } + } + + class C { + protected constructor(a: number) + protected constructor(a: string) + protected constructor() { + + } + } + + class D { + constructor(a: number) + constructor(a: string) + public constructor() { + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorOverloadsAccessibility.js b/tests/baselines/reference/classConstructorOverloadsAccessibility.js new file mode 100644 index 00000000000..3914c29b785 --- /dev/null +++ b/tests/baselines/reference/classConstructorOverloadsAccessibility.js @@ -0,0 +1,76 @@ +//// [classConstructorOverloadsAccessibility.ts] + +class A { + public constructor(a: boolean) // error + protected constructor(a: number) // error + private constructor(a: string) + private constructor() { + + } +} + +class B { + protected constructor(a: number) // error + constructor(a: string) + constructor() { + + } +} + +class C { + protected constructor(a: number) + protected constructor(a: string) + protected constructor() { + + } +} + +class D { + constructor(a: number) + constructor(a: string) + public constructor() { + + } +} + +//// [classConstructorOverloadsAccessibility.js] +var A = (function () { + function A() { + } + return A; +}()); +var B = (function () { + function B() { + } + return B; +}()); +var C = (function () { + function C() { + } + return C; +}()); +var D = (function () { + function D() { + } + return D; +}()); + + +//// [classConstructorOverloadsAccessibility.d.ts] +declare class A { + constructor(a: boolean); + protected constructor(a: number); + private constructor(a); +} +declare class B { + protected constructor(a: number); + constructor(a: string); +} +declare class C { + protected constructor(a: number); + protected constructor(a: string); +} +declare class D { + constructor(a: number); + constructor(a: string); +} diff --git a/tests/baselines/reference/classExtendsNull.errors.txt b/tests/baselines/reference/classExtendsNull.errors.txt index 7bb44774826..905c90c42fd 100644 --- a/tests/baselines/reference/classExtendsNull.errors.txt +++ b/tests/baselines/reference/classExtendsNull.errors.txt @@ -1,17 +1,14 @@ -tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' +tests/cases/compiler/classExtendsNull.ts(3,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' ==== tests/cases/compiler/classExtendsNull.ts (1 errors) ==== class C extends null { constructor() { - ~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ - return Object.create(null); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~ !!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + return Object.create(null); + } } class D extends null { diff --git a/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt b/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt index fe608b14379..2efaf2e5ae2 100644 --- a/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt +++ b/tests/baselines/reference/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.errors.txt @@ -1,70 +1,54 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(26,12): error TS2365: Operator '<' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(27,12): error TS2365: Operator '<' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(28,12): error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(29,12): error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(31,12): error TS2365: Operator '<' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(33,12): error TS2365: Operator '<' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(34,12): error TS2365: Operator '<' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(37,12): error TS2365: Operator '>' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(38,12): error TS2365: Operator '>' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(39,12): error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(40,12): error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(42,12): error TS2365: Operator '>' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(43,12): error TS2365: Operator '>' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(44,12): error TS2365: Operator '>' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(45,12): error TS2365: Operator '>' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(48,12): error TS2365: Operator '<=' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(49,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(50,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(51,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(53,12): error TS2365: Operator '<=' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(54,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(55,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(56,12): error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(59,12): error TS2365: Operator '>=' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(60,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(61,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(62,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(64,12): error TS2365: Operator '>=' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(65,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(66,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(67,12): error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(70,12): error TS2365: Operator '==' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(71,12): error TS2365: Operator '==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(72,12): error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(73,12): error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(75,12): error TS2365: Operator '==' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(76,12): error TS2365: Operator '==' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(77,12): error TS2365: Operator '==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(78,12): error TS2365: Operator '==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(81,12): error TS2365: Operator '!=' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(82,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(83,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(84,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(86,12): error TS2365: Operator '!=' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(87,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(88,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(89,12): error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(92,12): error TS2365: Operator '===' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(93,12): error TS2365: Operator '===' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(94,12): error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(95,12): error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(97,12): error TS2365: Operator '===' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(98,12): error TS2365: Operator '===' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(99,12): error TS2365: Operator '===' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(100,12): error TS2365: Operator '===' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(103,12): error TS2365: Operator '!==' cannot be applied to types '{ [a: string]: string; }' and '{ [b: string]: number; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(104,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: string]: C; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(105,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(106,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(108,12): error TS2365: Operator '!==' cannot be applied to types '{ [b: string]: number; }' and '{ [a: string]: string; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(109,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: C; }' and '{ [index: string]: Base; }'. tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(110,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts(111,12): error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. -==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts (64 errors) ==== +==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNoRelationshipObjectsOnIndexSignature.ts (48 errors) ==== class Base { public a: string; } @@ -100,8 +84,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r1a4 = a4 < b4; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r1b1 = b1 < a1; ~~~~~~~ @@ -113,8 +95,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r1b4 = b4 < a4; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator > var r2a1 = a1 > b1; @@ -127,8 +107,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r2a4 = a4 > b4; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r2b1 = b1 > a1; ~~~~~~~ @@ -140,8 +118,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~ !!! error TS2365: Operator '>' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r2b4 = b4 > a4; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator <= var r3a1 = a1 <= b1; @@ -154,8 +130,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r3a4 = a4 <= b4; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r3b1 = b1 <= a1; ~~~~~~~~ @@ -167,8 +141,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '<=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r3b4 = b4 <= a4; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator >= var r4a1 = a1 >= b1; @@ -181,8 +153,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r4a4 = a4 >= b4; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r4b1 = b1 >= a1; ~~~~~~~~ @@ -194,8 +164,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '>=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r4b4 = b4 >= a4; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator == var r5a1 = a1 == b1; @@ -208,8 +176,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r5a4 = a4 == b4; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r5b1 = b1 == a1; ~~~~~~~~ @@ -221,8 +187,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r5b4 = b4 == a4; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator != var r6a1 = a1 != b1; @@ -235,8 +199,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r6a4 = a4 != b4; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r6b1 = b1 != a1; ~~~~~~~~ @@ -248,8 +210,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~ !!! error TS2365: Operator '!=' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r6b4 = b4 != a4; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator === var r7a1 = a1 === b1; @@ -262,8 +222,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~~ !!! error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r7a4 = a4 === b4; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r7b1 = b1 === a1; ~~~~~~~~~ @@ -275,8 +233,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~~ !!! error TS2365: Operator '===' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. var r7b4 = b4 === a4; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. // operator !== var r8a1 = a1 !== b1; @@ -289,8 +245,6 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso ~~~~~~~~~ !!! error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Base; }' and '{ [index: number]: C; }'. var r8a4 = a4 !== b4; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: Derived; }' and '{ [index: string]: Base; }'. var r8b1 = b1 !== a1; ~~~~~~~~~ @@ -301,6 +255,4 @@ tests/cases/conformance/expressions/binaryOperators/comparisonOperator/compariso var r8b3 = b3 !== a3; ~~~~~~~~~ !!! error TS2365: Operator '!==' cannot be applied to types '{ [index: number]: C; }' and '{ [index: number]: Base; }'. - var r8b4 = b4 !== a4; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ [index: string]: Base; }' and '{ [index: number]: Derived; }'. \ No newline at end of file + var r8b4 = b4 !== a4; \ No newline at end of file diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types index 92835611c6d..e40422450b4 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types @@ -98,7 +98,7 @@ x2 += E.a; x2 += {}; >x2 += {} : string >x2 : string ->{} : { [x: number]: undefined; } +>{} : {} x2 += null; >x2 += null : string diff --git a/tests/baselines/reference/computedPropertyNames10_ES5.types b/tests/baselines/reference/computedPropertyNames10_ES5.types index 9dea9cfca93..b9d999397ab 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES5.types +++ b/tests/baselines/reference/computedPropertyNames10_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0](): void; [""](): void; } ->{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [0](): void; [""](): void; } +>v : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; } +>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; } [s]() { }, >s : string diff --git a/tests/baselines/reference/computedPropertyNames10_ES6.types b/tests/baselines/reference/computedPropertyNames10_ES6.types index d2faa138980..1883febb39b 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES6.types +++ b/tests/baselines/reference/computedPropertyNames10_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0](): void; [""](): void; } ->{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [0](): void; [""](): void; } +>v : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; } +>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [0](): void; [""](): void; } [s]() { }, >s : string diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.types b/tests/baselines/reference/computedPropertyNames11_ES5.types index ae626ec3cba..e15b46cc6c1 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.types +++ b/tests/baselines/reference/computedPropertyNames11_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { readonly [0]: number; [""]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; } +>v : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; } get [s]() { return 0; }, >s : string diff --git a/tests/baselines/reference/computedPropertyNames11_ES6.types b/tests/baselines/reference/computedPropertyNames11_ES6.types index 06dc26e9843..eb5fc105a7a 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES6.types +++ b/tests/baselines/reference/computedPropertyNames11_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { readonly [0]: number; [""]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; } +>v : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string]: any; [x: number]: any; readonly [0]: number; [""]: any; } get [s]() { return 0; }, >s : string diff --git a/tests/baselines/reference/computedPropertyNames18_ES5.types b/tests/baselines/reference/computedPropertyNames18_ES5.types index c60ab32d3f8..d6808a8edc0 100644 --- a/tests/baselines/reference/computedPropertyNames18_ES5.types +++ b/tests/baselines/reference/computedPropertyNames18_ES5.types @@ -3,8 +3,8 @@ function foo() { >foo : () => void var obj = { ->obj : {} ->{ [this.bar]: 0 } : {} +>obj : { [x: number]: number; } +>{ [this.bar]: 0 } : { [x: number]: number; } [this.bar]: 0 >this.bar : any diff --git a/tests/baselines/reference/computedPropertyNames18_ES6.types b/tests/baselines/reference/computedPropertyNames18_ES6.types index 33a15b6c5a9..11d58e48c69 100644 --- a/tests/baselines/reference/computedPropertyNames18_ES6.types +++ b/tests/baselines/reference/computedPropertyNames18_ES6.types @@ -3,8 +3,8 @@ function foo() { >foo : () => void var obj = { ->obj : {} ->{ [this.bar]: 0 } : {} +>obj : { [x: number]: number; } +>{ [this.bar]: 0 } : { [x: number]: number; } [this.bar]: 0 >this.bar : any diff --git a/tests/baselines/reference/computedPropertyNames1_ES5.types b/tests/baselines/reference/computedPropertyNames1_ES5.types index 6c94c846f30..bcff3b34177 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES5.types +++ b/tests/baselines/reference/computedPropertyNames1_ES5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames1_ES5.ts === var v = { ->v : {} ->{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : {} +>v : { [x: number]: number | string; } +>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: number | string; } get [0 + 1]() { return 0 }, >0 + 1 : number diff --git a/tests/baselines/reference/computedPropertyNames1_ES6.types b/tests/baselines/reference/computedPropertyNames1_ES6.types index 95e5a011ea2..df2237a463f 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES6.types +++ b/tests/baselines/reference/computedPropertyNames1_ES6.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames1_ES6.ts === var v = { ->v : {} ->{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : {} +>v : { [x: number]: number | string; } +>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: number | string; } get [0 + 1]() { return 0 }, >0 + 1 : number diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.types b/tests/baselines/reference/computedPropertyNames20_ES5.types index 91cc2c42963..65ee55be379 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.types +++ b/tests/baselines/reference/computedPropertyNames20_ES5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames20_ES5.ts === var obj = { ->obj : {} ->{ [this.bar]: 0} : {} +>obj : { [x: number]: number; } +>{ [this.bar]: 0} : { [x: number]: number; } [this.bar]: 0 >this.bar : any diff --git a/tests/baselines/reference/computedPropertyNames20_ES6.types b/tests/baselines/reference/computedPropertyNames20_ES6.types index 4ef6f675cce..91e5c8d7843 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES6.types +++ b/tests/baselines/reference/computedPropertyNames20_ES6.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames20_ES6.ts === var obj = { ->obj : {} ->{ [this.bar]: 0} : {} +>obj : { [x: number]: number; } +>{ [this.bar]: 0} : { [x: number]: number; } [this.bar]: 0 >this.bar : any diff --git a/tests/baselines/reference/computedPropertyNames22_ES5.types b/tests/baselines/reference/computedPropertyNames22_ES5.types index ca59250825c..eeec22d2e61 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES5.types +++ b/tests/baselines/reference/computedPropertyNames22_ES5.types @@ -6,8 +6,8 @@ class C { >bar : () => number var obj = { ->obj : {} ->{ [this.bar()]() { } } : {} +>obj : { [x: number]: () => void; } +>{ [this.bar()]() { } } : { [x: number]: () => void; } [this.bar()]() { } >this.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames22_ES6.types b/tests/baselines/reference/computedPropertyNames22_ES6.types index d5fbce29f7d..af9ef9d3a31 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES6.types +++ b/tests/baselines/reference/computedPropertyNames22_ES6.types @@ -6,8 +6,8 @@ class C { >bar : () => number var obj = { ->obj : {} ->{ [this.bar()]() { } } : {} +>obj : { [x: number]: () => void; } +>{ [this.bar()]() { } } : { [x: number]: () => void; } [this.bar()]() { } >this.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames25_ES5.types b/tests/baselines/reference/computedPropertyNames25_ES5.types index 6ca67cce410..f1acc296709 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES5.types +++ b/tests/baselines/reference/computedPropertyNames25_ES5.types @@ -17,8 +17,8 @@ class C extends Base { >foo : () => number var obj = { ->obj : {} ->{ [super.bar()]() { } } : {} +>obj : { [x: number]: () => void; } +>{ [super.bar()]() { } } : { [x: number]: () => void; } [super.bar()]() { } >super.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames25_ES6.types b/tests/baselines/reference/computedPropertyNames25_ES6.types index 1c093ebc59f..26c38013906 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES6.types +++ b/tests/baselines/reference/computedPropertyNames25_ES6.types @@ -17,8 +17,8 @@ class C extends Base { >foo : () => number var obj = { ->obj : {} ->{ [super.bar()]() { } } : {} +>obj : { [x: number]: () => void; } +>{ [super.bar()]() { } } : { [x: number]: () => void; } [super.bar()]() { } >super.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames28_ES5.types b/tests/baselines/reference/computedPropertyNames28_ES5.types index 273dcd426d8..89a2a7ac017 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES5.types +++ b/tests/baselines/reference/computedPropertyNames28_ES5.types @@ -12,8 +12,8 @@ class C extends Base { >super : typeof Base var obj = { ->obj : {} ->{ [(super(), "prop")]() { } } : {} +>obj : { [x: string]: () => void; } +>{ [(super(), "prop")]() { } } : { [x: string]: () => void; } [(super(), "prop")]() { } >(super(), "prop") : string diff --git a/tests/baselines/reference/computedPropertyNames28_ES6.types b/tests/baselines/reference/computedPropertyNames28_ES6.types index a34fb33f6c7..df020c9a5ff 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES6.types +++ b/tests/baselines/reference/computedPropertyNames28_ES6.types @@ -12,8 +12,8 @@ class C extends Base { >super : typeof Base var obj = { ->obj : {} ->{ [(super(), "prop")]() { } } : {} +>obj : { [x: string]: () => void; } +>{ [(super(), "prop")]() { } } : { [x: string]: () => void; } [(super(), "prop")]() { } >(super(), "prop") : string diff --git a/tests/baselines/reference/computedPropertyNames29_ES5.types b/tests/baselines/reference/computedPropertyNames29_ES5.types index f3448f10857..d2f89ef6b18 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES5.types +++ b/tests/baselines/reference/computedPropertyNames29_ES5.types @@ -9,8 +9,8 @@ class C { >() => { var obj = { [this.bar()]() { } // needs capture }; } : () => void var obj = { ->obj : {} ->{ [this.bar()]() { } // needs capture } : {} +>obj : { [x: number]: () => void; } +>{ [this.bar()]() { } // needs capture } : { [x: number]: () => void; } [this.bar()]() { } // needs capture >this.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames29_ES6.types b/tests/baselines/reference/computedPropertyNames29_ES6.types index cd01d37556a..bb324b2b382 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES6.types +++ b/tests/baselines/reference/computedPropertyNames29_ES6.types @@ -9,8 +9,8 @@ class C { >() => { var obj = { [this.bar()]() { } // needs capture }; } : () => void var obj = { ->obj : {} ->{ [this.bar()]() { } // needs capture } : {} +>obj : { [x: number]: () => void; } +>{ [this.bar()]() { } // needs capture } : { [x: number]: () => void; } [this.bar()]() { } // needs capture >this.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames31_ES5.types b/tests/baselines/reference/computedPropertyNames31_ES5.types index 6c0f2572a06..832b2bc067a 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES5.types +++ b/tests/baselines/reference/computedPropertyNames31_ES5.types @@ -20,8 +20,8 @@ class C extends Base { >() => { var obj = { [super.bar()]() { } // needs capture }; } : () => void var obj = { ->obj : {} ->{ [super.bar()]() { } // needs capture } : {} +>obj : { [x: number]: () => void; } +>{ [super.bar()]() { } // needs capture } : { [x: number]: () => void; } [super.bar()]() { } // needs capture >super.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames31_ES6.types b/tests/baselines/reference/computedPropertyNames31_ES6.types index eaddc036812..4f59b1e8c6d 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES6.types +++ b/tests/baselines/reference/computedPropertyNames31_ES6.types @@ -20,8 +20,8 @@ class C extends Base { >() => { var obj = { [super.bar()]() { } // needs capture }; } : () => void var obj = { ->obj : {} ->{ [super.bar()]() { } // needs capture } : {} +>obj : { [x: number]: () => void; } +>{ [super.bar()]() { } // needs capture } : { [x: number]: () => void; } [super.bar()]() { } // needs capture >super.bar() : number diff --git a/tests/baselines/reference/computedPropertyNames33_ES5.types b/tests/baselines/reference/computedPropertyNames33_ES5.types index f44ac3ca769..7031981481f 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES5.types +++ b/tests/baselines/reference/computedPropertyNames33_ES5.types @@ -12,8 +12,8 @@ class C { >bar : () => number var obj = { ->obj : {} ->{ [foo()]() { } } : {} +>obj : { [x: string]: () => void; } +>{ [foo()]() { } } : { [x: string]: () => void; } [foo()]() { } >foo() : string diff --git a/tests/baselines/reference/computedPropertyNames33_ES6.types b/tests/baselines/reference/computedPropertyNames33_ES6.types index 3081337c8bb..3c57daf2ace 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES6.types +++ b/tests/baselines/reference/computedPropertyNames33_ES6.types @@ -12,8 +12,8 @@ class C { >bar : () => number var obj = { ->obj : {} ->{ [foo()]() { } } : {} +>obj : { [x: string]: () => void; } +>{ [foo()]() { } } : { [x: string]: () => void; } [foo()]() { } >foo() : string diff --git a/tests/baselines/reference/computedPropertyNames46_ES5.types b/tests/baselines/reference/computedPropertyNames46_ES5.types index 394b22bd904..b8df0d56e13 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES5.types +++ b/tests/baselines/reference/computedPropertyNames46_ES5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames46_ES5.ts === var o = { ->o : {} ->{ ["" || 0]: 0} : {} +>o : { [x: string]: number; } +>{ ["" || 0]: 0} : { [x: string]: number; } ["" || 0]: 0 >"" || 0 : string | number diff --git a/tests/baselines/reference/computedPropertyNames46_ES6.types b/tests/baselines/reference/computedPropertyNames46_ES6.types index 864fd81321d..a786eca200c 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES6.types +++ b/tests/baselines/reference/computedPropertyNames46_ES6.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames46_ES6.ts === var o = { ->o : {} ->{ ["" || 0]: 0} : {} +>o : { [x: string]: number; } +>{ ["" || 0]: 0} : { [x: string]: number; } ["" || 0]: 0 >"" || 0 : string | number diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.types b/tests/baselines/reference/computedPropertyNames47_ES5.types index 6aa841ffd62..cdc2c3301f6 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.types +++ b/tests/baselines/reference/computedPropertyNames47_ES5.types @@ -8,8 +8,8 @@ enum E2 { x } >x : E2 var o = { ->o : {} ->{ [E1.x || E2.x]: 0} : {} +>o : { [x: number]: number; } +>{ [E1.x || E2.x]: 0} : { [x: number]: number; } [E1.x || E2.x]: 0 >E1.x || E2.x : E1 | E2 diff --git a/tests/baselines/reference/computedPropertyNames47_ES6.types b/tests/baselines/reference/computedPropertyNames47_ES6.types index f038b172ca1..a923e934d66 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES6.types +++ b/tests/baselines/reference/computedPropertyNames47_ES6.types @@ -8,8 +8,8 @@ enum E2 { x } >x : E2 var o = { ->o : {} ->{ [E1.x || E2.x]: 0} : {} +>o : { [x: number]: number; } +>{ [E1.x || E2.x]: 0} : { [x: number]: number; } [E1.x || E2.x]: 0 >E1.x || E2.x : E1 | E2 diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.types b/tests/baselines/reference/computedPropertyNames48_ES5.types index 2b9131a11c8..12752d8abeb 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.types +++ b/tests/baselines/reference/computedPropertyNames48_ES5.types @@ -39,9 +39,9 @@ extractIndexer({ }); // Should return string extractIndexer({ ->extractIndexer({ ["" || 0]: ""}) : any +>extractIndexer({ ["" || 0]: ""}) : string >extractIndexer : (p: { [n: number]: T; }) => T ->{ ["" || 0]: ""} : { [x: number]: undefined; } +>{ ["" || 0]: ""} : { [x: string]: string; } ["" || 0]: "" >"" || 0 : string | number diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.types b/tests/baselines/reference/computedPropertyNames48_ES6.types index 2b803b19bd6..832bc3c7025 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES6.types +++ b/tests/baselines/reference/computedPropertyNames48_ES6.types @@ -39,9 +39,9 @@ extractIndexer({ }); // Should return string extractIndexer({ ->extractIndexer({ ["" || 0]: ""}) : any +>extractIndexer({ ["" || 0]: ""}) : string >extractIndexer : (p: { [n: number]: T; }) => T ->{ ["" || 0]: ""} : { [x: number]: undefined; } +>{ ["" || 0]: ""} : { [x: string]: string; } ["" || 0]: "" >"" || 0 : string | number diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.types b/tests/baselines/reference/computedPropertyNames4_ES5.types index 6984d2e69b8..3c5f884640f 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.types +++ b/tests/baselines/reference/computedPropertyNames4_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0]: number; [""]: number; } ->{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [0]: number; [""]: number; } +>v : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } [s]: 0, >s : string diff --git a/tests/baselines/reference/computedPropertyNames4_ES6.types b/tests/baselines/reference/computedPropertyNames4_ES6.types index 1fece561f5a..335c2415bd0 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES6.types +++ b/tests/baselines/reference/computedPropertyNames4_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0]: number; [""]: number; } ->{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [0]: number; [""]: number; } +>v : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } [s]: 0, >s : string diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.types b/tests/baselines/reference/computedPropertyNames7_ES5.types index 8ebd4d75668..3411198b590 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.types +++ b/tests/baselines/reference/computedPropertyNames7_ES5.types @@ -6,8 +6,8 @@ enum E { >member : E } var v = { ->v : {} ->{ [E.member]: 0} : {} +>v : { [x: number]: number; } +>{ [E.member]: 0} : { [x: number]: number; } [E.member]: 0 >E.member : E diff --git a/tests/baselines/reference/computedPropertyNames7_ES6.types b/tests/baselines/reference/computedPropertyNames7_ES6.types index 3a78b9c0ec6..eb72d546dbc 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES6.types +++ b/tests/baselines/reference/computedPropertyNames7_ES6.types @@ -6,8 +6,8 @@ enum E { >member : E } var v = { ->v : {} ->{ [E.member]: 0} : {} +>v : { [x: number]: number; } +>{ [E.member]: 0} : { [x: number]: number; } [E.member]: 0 >E.member : E diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.types index bea7267d7d1..09cad594624 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.types @@ -14,7 +14,7 @@ interface I { var o: I = { >o : I >I : I ->{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: (y: string) => number; [x: number]: undefined; } +>{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: (y: string) => number; } ["" + 0](y) { return y.length; }, >"" + 0 : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType1_ES6.types index c8d0be6e833..d9e9970ebec 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType1_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType1_ES6.types @@ -14,7 +14,7 @@ interface I { var o: I = { >o : I >I : I ->{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: (y: string) => number; [x: number]: undefined; } +>{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: (y: string) => number; } ["" + 0](y) { return y.length; }, >"" + 0 : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types index 52de216b803..5a5c48f2536 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types @@ -14,7 +14,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: (y: string) => number; [x: number]: (y: string) => number; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: string) => number; } [+"foo"](y) { return y.length; }, >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types index cbbe0edc6a1..330351790ca 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types @@ -14,7 +14,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: (y: string) => number; [x: number]: (y: string) => number; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: string) => number; } [+"foo"](y) { return y.length; }, >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.types index 5f647fb4c1b..faff27c9154 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.types @@ -10,7 +10,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: (y: string) => number; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: string) => number; } [+"foo"](y) { return y.length; }, >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType3_ES6.types index e872df6f1b2..18c32957944 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType3_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType3_ES6.types @@ -10,7 +10,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: (y: string) => number; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: string) => number; } [+"foo"](y) { return y.length; }, >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.types index e5a57363ca0..6f75f1a3633 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.types @@ -12,7 +12,7 @@ interface I { var o: I = { >o : I >I : I ->{ [""+"foo"]: "", [""+"bar"]: 0} : { [x: string]: string | number; [x: number]: undefined; } +>{ [""+"foo"]: "", [""+"bar"]: 0} : { [x: string]: string | number; } [""+"foo"]: "", >""+"foo" : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType4_ES6.types index bdfa569752b..9ee84176237 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType4_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType4_ES6.types @@ -12,7 +12,7 @@ interface I { var o: I = { >o : I >I : I ->{ [""+"foo"]: "", [""+"bar"]: 0} : { [x: string]: string | number; [x: number]: undefined; } +>{ [""+"foo"]: "", [""+"bar"]: 0} : { [x: string]: string | number; } [""+"foo"]: "", >""+"foo" : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.types index e142fe937b9..38594f756ab 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.types @@ -12,7 +12,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"]: "", [+"bar"]: 0} : { [x: string]: string | number; [x: number]: string | number; } +>{ [+"foo"]: "", [+"bar"]: 0} : { [x: number]: string | number; } [+"foo"]: "", >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType5_ES6.types index 7b385b36770..a07b2e8cd95 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType5_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType5_ES6.types @@ -12,7 +12,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"]: "", [+"bar"]: 0} : { [x: string]: string | number; [x: number]: string | number; } +>{ [+"foo"]: "", [+"bar"]: 0} : { [x: number]: string | number; } [+"foo"]: "", >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types index a3a393fba0c..b49724ccded 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types @@ -19,7 +19,7 @@ declare function foo(obj: I): T foo({ >foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types index 4abefe44843..e88959d7cdc 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types @@ -19,7 +19,7 @@ declare function foo(obj: I): T foo({ >foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index ae1004c9819..083388ba975 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -19,7 +19,7 @@ declare function foo(obj: I): T foo({ >foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index e98e0fb8941..bc6ae72fb4f 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -19,7 +19,7 @@ declare function foo(obj: I): T foo({ >foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt index 3376243e370..ee36609095a 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8_ES5.ts(6,5): error TS2322: Type '{ [x: string]: string | number; [x: number]: undefined; }' is not assignable to type 'I'. +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8_ES5.ts(6,5): error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. Index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -12,7 +12,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ -!!! error TS2322: Type '{ [x: string]: string | number; [x: number]: undefined; }' is not assignable to type 'I'. +!!! error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt index e4540337ed4..1048fd2e119 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8_ES6.ts(6,5): error TS2322: Type '{ [x: string]: string | number; [x: number]: undefined; }' is not assignable to type 'I'. +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8_ES6.ts(6,5): error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. Index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -12,7 +12,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ -!!! error TS2322: Type '{ [x: string]: string | number; [x: number]: undefined; }' is not assignable to type 'I'. +!!! error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt index d4085a37e60..e76b3a704dc 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES5.ts(6,5): error TS2322: Type '{ [x: string]: string | number; [x: number]: string | number; }' is not assignable to type 'I'. +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES5.ts(6,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. Index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -12,7 +12,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ -!!! error TS2322: Type '{ [x: string]: string | number; [x: number]: string | number; }' is not assignable to type 'I'. +!!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt index eca1360c26f..468ad400c26 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES6.ts(6,5): error TS2322: Type '{ [x: string]: string | number; [x: number]: string | number; }' is not assignable to type 'I'. +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES6.ts(6,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. Index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -12,7 +12,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ -!!! error TS2322: Type '{ [x: string]: string | number; [x: number]: string | number; }' is not assignable to type 'I'. +!!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js index e77eb79dc70..f04ea61379d 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js @@ -26,4 +26,6 @@ var _a; //// [computedPropertyNamesDeclarationEmit5_ES5.d.ts] -declare var v: {}; +declare var v: { + [x: string]: any; +}; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.types b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.types index 62faa5c2716..0653059b535 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5_ES5.ts === var v = { ->v : {} ->{ ["" + ""]: 0, ["" + ""]() { }, get ["" + ""]() { return 0; }, set ["" + ""](x) { }} : {} +>v : { [x: string]: any; } +>{ ["" + ""]: 0, ["" + ""]() { }, get ["" + ""]() { return 0; }, set ["" + ""](x) { }} : { [x: string]: any; } ["" + ""]: 0, >"" + "" : string diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.js index e19ac43656e..de1f8c65d7f 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.js @@ -16,4 +16,6 @@ var v = { //// [computedPropertyNamesDeclarationEmit5_ES6.d.ts] -declare var v: {}; +declare var v: { + [x: string]: any; +}; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.types b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.types index 3eb313d2687..45d1e74f24a 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES6.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5_ES6.ts === var v = { ->v : {} ->{ ["" + ""]: 0, ["" + ""]() { }, get ["" + ""]() { return 0; }, set ["" + ""](x) { }} : {} +>v : { [x: string]: any; } +>{ ["" + ""]: 0, ["" + ""]() { }, get ["" + ""]() { return 0; }, set ["" + ""](x) { }} : { [x: string]: any; } ["" + ""]: 0, >"" + "" : string diff --git a/tests/baselines/reference/constEnumPropertyAccess1.types b/tests/baselines/reference/constEnumPropertyAccess1.types index 5ed2b932bd0..f0e00fe7717 100644 --- a/tests/baselines/reference/constEnumPropertyAccess1.types +++ b/tests/baselines/reference/constEnumPropertyAccess1.types @@ -35,7 +35,7 @@ var o: { >idx : number } = { ->{ 1: true } : { [x: number]: boolean; 1: boolean; } +>{ 1: true } : { 1: boolean; } 1: true >true : boolean diff --git a/tests/baselines/reference/contextualTypeAny.errors.txt b/tests/baselines/reference/contextualTypeAny.errors.txt new file mode 100644 index 00000000000..09970be986d --- /dev/null +++ b/tests/baselines/reference/contextualTypeAny.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/contextualTypeAny.ts(3,5): error TS2322: Type '{ p: string; q: any; }' is not assignable to type '{ [s: string]: number; }'. + Property 'p' is incompatible with index signature. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/contextualTypeAny.ts (1 errors) ==== + var x: any; + + var obj: { [s: string]: number } = { p: "", q: x }; + ~~~ +!!! error TS2322: Type '{ p: string; q: any; }' is not assignable to type '{ [s: string]: number; }'. +!!! error TS2322: Property 'p' is incompatible with index signature. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + + var arr: number[] = ["", x]; \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeAny.symbols b/tests/baselines/reference/contextualTypeAny.symbols deleted file mode 100644 index 5132c948a2e..00000000000 --- a/tests/baselines/reference/contextualTypeAny.symbols +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/contextualTypeAny.ts === -var x: any; ->x : Symbol(x, Decl(contextualTypeAny.ts, 0, 3)) - -var obj: { [s: string]: number } = { p: "", q: x }; ->obj : Symbol(obj, Decl(contextualTypeAny.ts, 2, 3)) ->s : Symbol(s, Decl(contextualTypeAny.ts, 2, 12)) ->p : Symbol(p, Decl(contextualTypeAny.ts, 2, 36)) ->q : Symbol(q, Decl(contextualTypeAny.ts, 2, 43)) ->x : Symbol(x, Decl(contextualTypeAny.ts, 0, 3)) - -var arr: number[] = ["", x]; ->arr : Symbol(arr, Decl(contextualTypeAny.ts, 4, 3)) ->x : Symbol(x, Decl(contextualTypeAny.ts, 0, 3)) - diff --git a/tests/baselines/reference/contextualTypeAny.types b/tests/baselines/reference/contextualTypeAny.types deleted file mode 100644 index cace92d6567..00000000000 --- a/tests/baselines/reference/contextualTypeAny.types +++ /dev/null @@ -1,19 +0,0 @@ -=== tests/cases/compiler/contextualTypeAny.ts === -var x: any; ->x : any - -var obj: { [s: string]: number } = { p: "", q: x }; ->obj : { [s: string]: number; } ->s : string ->{ p: "", q: x } : { [x: string]: any; p: string; q: any; } ->p : string ->"" : string ->q : any ->x : any - -var arr: number[] = ["", x]; ->arr : number[] ->["", x] : any[] ->"" : string ->x : any - diff --git a/tests/baselines/reference/contextualTypeArrayReturnType.types b/tests/baselines/reference/contextualTypeArrayReturnType.types index f270b33f568..6c91fd7b8b9 100644 --- a/tests/baselines/reference/contextualTypeArrayReturnType.types +++ b/tests/baselines/reference/contextualTypeArrayReturnType.types @@ -26,18 +26,18 @@ interface Transform3D { var style: IBookStyle = { >style : IBookStyle >IBookStyle : IBookStyle ->{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { [x: string]: any; 'ry': any; }[]; } +>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { 'ry': any; }[]; } initialLeftPageTransforms: (width: number) => { ->initialLeftPageTransforms : (width: number) => { [x: string]: any; 'ry': any; }[] ->(width: number) => { return [ {'ry': null } ]; } : (width: number) => { [x: string]: any; 'ry': any; }[] +>initialLeftPageTransforms : (width: number) => { 'ry': any; }[] +>(width: number) => { return [ {'ry': null } ]; } : (width: number) => { 'ry': any; }[] >width : number return [ ->[ {'ry': null } ] : { [x: string]: null; 'ry': null; }[] +>[ {'ry': null } ] : { 'ry': null; }[] {'ry': null } ->{'ry': null } : { [x: string]: null; 'ry': null; } +>{'ry': null } : { 'ry': null; } >null : null ]; diff --git a/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types b/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types index 2f24ad08227..965e4d21d99 100644 --- a/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types +++ b/tests/baselines/reference/contextualTypeWithUnionTypeIndexSignatures.types @@ -69,7 +69,7 @@ var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { z: a => a }; >x : IWithNoStringIndexSignature | IWithStringIndexSignature1 >IWithNoStringIndexSignature : IWithNoStringIndexSignature >IWithStringIndexSignature1 : IWithStringIndexSignature1 ->{ z: a => a } : { [x: string]: (a: number) => number; z: (a: number) => number; } +>{ z: a => a } : { z: (a: number) => number; } >z : (a: number) => number >a => a : (a: number) => number >a : number @@ -79,7 +79,7 @@ var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { foo: a => a >x : IWithNoStringIndexSignature | IWithStringIndexSignature1 >IWithNoStringIndexSignature : IWithNoStringIndexSignature >IWithStringIndexSignature1 : IWithStringIndexSignature1 ->{ foo: a => a } : { [x: string]: (a: any) => any; foo: (a: any) => any; } +>{ foo: a => a } : { foo: (a: any) => any; } >foo : (a: any) => any >a => a : (a: any) => any >a : any @@ -89,7 +89,7 @@ var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { foo: "hello" >x : IWithNoStringIndexSignature | IWithStringIndexSignature1 >IWithNoStringIndexSignature : IWithNoStringIndexSignature >IWithStringIndexSignature1 : IWithStringIndexSignature1 ->{ foo: "hello" } : { [x: string]: string; foo: string; } +>{ foo: "hello" } : { foo: string; } >foo : string >"hello" : string @@ -97,7 +97,7 @@ var x2: IWithStringIndexSignature1 | IWithStringIndexSignature2 = { z: a => a.to >x2 : IWithStringIndexSignature1 | IWithStringIndexSignature2 >IWithStringIndexSignature1 : IWithStringIndexSignature1 >IWithStringIndexSignature2 : IWithStringIndexSignature2 ->{ z: a => a.toString() } : { [x: string]: (a: number) => string; z: (a: number) => string; } +>{ z: a => a.toString() } : { z: (a: number) => string; } >z : (a: number) => string >a => a.toString() : (a: number) => string >a : number @@ -110,7 +110,7 @@ var x2: IWithStringIndexSignature1 | IWithStringIndexSignature2 = { z: a => a }; >x2 : IWithStringIndexSignature1 | IWithStringIndexSignature2 >IWithStringIndexSignature1 : IWithStringIndexSignature1 >IWithStringIndexSignature2 : IWithStringIndexSignature2 ->{ z: a => a } : { [x: string]: (a: number) => number; z: (a: number) => number; } +>{ z: a => a } : { z: (a: number) => number; } >z : (a: number) => number >a => a : (a: number) => number >a : number @@ -124,7 +124,7 @@ var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 1: a => a } >x3 : IWithNoNumberIndexSignature | IWithNumberIndexSignature1 >IWithNoNumberIndexSignature : IWithNoNumberIndexSignature >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 ->{ 1: a => a } : { [x: number]: (a: number) => number; 1: (a: number) => number; } +>{ 1: a => a } : { 1: (a: number) => number; } >a => a : (a: number) => number >a : number >a : number @@ -133,7 +133,7 @@ var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 0: a => a } >x3 : IWithNoNumberIndexSignature | IWithNumberIndexSignature1 >IWithNoNumberIndexSignature : IWithNoNumberIndexSignature >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 ->{ 0: a => a } : { [x: number]: (a: any) => any; 0: (a: any) => any; } +>{ 0: a => a } : { 0: (a: any) => any; } >a => a : (a: any) => any >a : any >a : any @@ -142,14 +142,14 @@ var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 0: "hello" >x3 : IWithNoNumberIndexSignature | IWithNumberIndexSignature1 >IWithNoNumberIndexSignature : IWithNoNumberIndexSignature >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 ->{ 0: "hello" } : { [x: number]: string; 0: string; } +>{ 0: "hello" } : { 0: string; } >"hello" : string var x4: IWithNumberIndexSignature1 | IWithNumberIndexSignature2 = { 1: a => a.toString() }; // a should be number >x4 : IWithNumberIndexSignature1 | IWithNumberIndexSignature2 >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 >IWithNumberIndexSignature2 : IWithNumberIndexSignature2 ->{ 1: a => a.toString() } : { [x: number]: (a: number) => string; 1: (a: number) => string; } +>{ 1: a => a.toString() } : { 1: (a: number) => string; } >a => a.toString() : (a: number) => string >a : number >a.toString() : string @@ -161,7 +161,7 @@ var x4: IWithNumberIndexSignature1 | IWithNumberIndexSignature2 = { 1: a => a }; >x4 : IWithNumberIndexSignature1 | IWithNumberIndexSignature2 >IWithNumberIndexSignature1 : IWithNumberIndexSignature1 >IWithNumberIndexSignature2 : IWithNumberIndexSignature2 ->{ 1: a => a } : { [x: number]: (a: number) => number; 1: (a: number) => number; } +>{ 1: a => a } : { 1: (a: number) => number; } >a => a : (a: number) => number >a : number >a : number diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt b/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt deleted file mode 100644 index ac8063a4378..00000000000 --- a/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/compiler/contextualTypingOfObjectLiterals.ts(4,1): error TS2322: Type '{ x: string; }' is not assignable to type '{ [x: string]: string; }'. - Index signature is missing in type '{ x: string; }'. -tests/cases/compiler/contextualTypingOfObjectLiterals.ts(10,3): error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. - Index signature is missing in type '{ x: string; }'. - - -==== tests/cases/compiler/contextualTypingOfObjectLiterals.ts (2 errors) ==== - var obj1: { [x: string]: string; }; - var obj2 = {x: ""}; - obj1 = {}; // Ok - obj1 = obj2; // Error - indexer doesn't match - ~~~~ -!!! error TS2322: Type '{ x: string; }' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signature is missing in type '{ x: string; }'. - - function f(x: { [s: string]: string }) { } - - f({}); // Ok - f(obj1); // Ok - f(obj2); // Error - indexer doesn't match - ~~~~ -!!! error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. -!!! error TS2345: Index signature is missing in type '{ x: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.symbols b/tests/baselines/reference/contextualTypingOfObjectLiterals.symbols new file mode 100644 index 00000000000..afa34cfe481 --- /dev/null +++ b/tests/baselines/reference/contextualTypingOfObjectLiterals.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/contextualTypingOfObjectLiterals.ts === +var obj1: { [x: string]: string; }; +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) +>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 0, 13)) + +var obj2 = {x: ""}; +>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3)) +>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 1, 12)) + +obj1 = {}; // Ok +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) + +obj1 = obj2; // Error - indexer doesn't match +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) +>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3)) + +function f(x: { [s: string]: string }) { } +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) +>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 5, 11)) +>s : Symbol(s, Decl(contextualTypingOfObjectLiterals.ts, 5, 17)) + +f({}); // Ok +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) + +f(obj1); // Ok +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) +>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3)) + +f(obj2); // Error - indexer doesn't match +>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12)) +>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3)) + diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.types b/tests/baselines/reference/contextualTypingOfObjectLiterals.types new file mode 100644 index 00000000000..a99fb2f39af --- /dev/null +++ b/tests/baselines/reference/contextualTypingOfObjectLiterals.types @@ -0,0 +1,41 @@ +=== tests/cases/compiler/contextualTypingOfObjectLiterals.ts === +var obj1: { [x: string]: string; }; +>obj1 : { [x: string]: string; } +>x : string + +var obj2 = {x: ""}; +>obj2 : { x: string; } +>{x: ""} : { x: string; } +>x : string +>"" : string + +obj1 = {}; // Ok +>obj1 = {} : {} +>obj1 : { [x: string]: string; } +>{} : {} + +obj1 = obj2; // Error - indexer doesn't match +>obj1 = obj2 : { x: string; } +>obj1 : { [x: string]: string; } +>obj2 : { x: string; } + +function f(x: { [s: string]: string }) { } +>f : (x: { [s: string]: string; }) => void +>x : { [s: string]: string; } +>s : string + +f({}); // Ok +>f({}) : void +>f : (x: { [s: string]: string; }) => void +>{} : {} + +f(obj1); // Ok +>f(obj1) : void +>f : (x: { [s: string]: string; }) => void +>obj1 : { [x: string]: string; } + +f(obj2); // Error - indexer doesn't match +>f(obj2) : void +>f : (x: { [s: string]: string; }) => void +>obj2 : { x: string; } + diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicates01.js b/tests/baselines/reference/declarationEmitIdentifierPredicates01.js new file mode 100644 index 00000000000..73141eb9af9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitIdentifierPredicates01.js @@ -0,0 +1,16 @@ +//// [declarationEmitIdentifierPredicates01.ts] + +export function f(x: any): x is number { + return typeof x === "number"; +} + +//// [declarationEmitIdentifierPredicates01.js] +"use strict"; +function f(x) { + return typeof x === "number"; +} +exports.f = f; + + +//// [declarationEmitIdentifierPredicates01.d.ts] +export declare function f(x: any): x is number; diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicates01.symbols b/tests/baselines/reference/declarationEmitIdentifierPredicates01.symbols new file mode 100644 index 00000000000..eb8b1151ceb --- /dev/null +++ b/tests/baselines/reference/declarationEmitIdentifierPredicates01.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts === + +export function f(x: any): x is number { +>f : Symbol(f, Decl(declarationEmitIdentifierPredicates01.ts, 0, 0)) +>x : Symbol(x, Decl(declarationEmitIdentifierPredicates01.ts, 1, 18)) +>x : Symbol(x, Decl(declarationEmitIdentifierPredicates01.ts, 1, 18)) + + return typeof x === "number"; +>x : Symbol(x, Decl(declarationEmitIdentifierPredicates01.ts, 1, 18)) +} diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicates01.types b/tests/baselines/reference/declarationEmitIdentifierPredicates01.types new file mode 100644 index 00000000000..7d8a5668265 --- /dev/null +++ b/tests/baselines/reference/declarationEmitIdentifierPredicates01.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts === + +export function f(x: any): x is number { +>f : (x: any) => x is number +>x : any +>x : any + + return typeof x === "number"; +>typeof x === "number" : boolean +>typeof x : string +>x : any +>"number" : string +} diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.errors.txt b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.errors.txt new file mode 100644 index 00000000000..e9084c45490 --- /dev/null +++ b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts(6,33): error TS4060: Return type of exported function has or is using private name 'I'. + + +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts (1 errors) ==== + + interface I { + a: number; + } + + export function f(x: any): x is I { + ~ +!!! error TS4060: Return type of exported function has or is using private name 'I'. + return typeof x.a === "number"; + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js new file mode 100644 index 00000000000..234542d8d99 --- /dev/null +++ b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js @@ -0,0 +1,16 @@ +//// [declarationEmitIdentifierPredicatesWithPrivateName01.ts] + +interface I { + a: number; +} + +export function f(x: any): x is I { + return typeof x.a === "number"; +} + +//// [declarationEmitIdentifierPredicatesWithPrivateName01.js] +"use strict"; +function f(x) { + return typeof x.a === "number"; +} +exports.f = f; diff --git a/tests/baselines/reference/declarationEmitThisPredicates01.js b/tests/baselines/reference/declarationEmitThisPredicates01.js new file mode 100644 index 00000000000..d05b5c46dad --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicates01.js @@ -0,0 +1,43 @@ +//// [declarationEmitThisPredicates01.ts] + +export class C { + m(): this is D { + return this instanceof D; + } +} + +export class D extends C { +} + +//// [declarationEmitThisPredicates01.js] +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C = (function () { + function C() { + } + C.prototype.m = function () { + return this instanceof D; + }; + return C; +}()); +exports.C = C; +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.apply(this, arguments); + } + return D; +}(C)); +exports.D = D; + + +//// [declarationEmitThisPredicates01.d.ts] +export declare class C { + m(): this is D; +} +export declare class D extends C { +} diff --git a/tests/baselines/reference/declarationEmitThisPredicates01.symbols b/tests/baselines/reference/declarationEmitThisPredicates01.symbols new file mode 100644 index 00000000000..d57f937d6c5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicates01.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates01.ts === + +export class C { +>C : Symbol(C, Decl(declarationEmitThisPredicates01.ts, 0, 0)) + + m(): this is D { +>m : Symbol(m, Decl(declarationEmitThisPredicates01.ts, 1, 16)) +>D : Symbol(D, Decl(declarationEmitThisPredicates01.ts, 5, 1)) + + return this instanceof D; +>this : Symbol(C, Decl(declarationEmitThisPredicates01.ts, 0, 0)) +>D : Symbol(D, Decl(declarationEmitThisPredicates01.ts, 5, 1)) + } +} + +export class D extends C { +>D : Symbol(D, Decl(declarationEmitThisPredicates01.ts, 5, 1)) +>C : Symbol(C, Decl(declarationEmitThisPredicates01.ts, 0, 0)) +} diff --git a/tests/baselines/reference/declarationEmitThisPredicates01.types b/tests/baselines/reference/declarationEmitThisPredicates01.types new file mode 100644 index 00000000000..9d801a40965 --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicates01.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates01.ts === + +export class C { +>C : C + + m(): this is D { +>m : () => this is D +>D : D + + return this instanceof D; +>this instanceof D : boolean +>this : this +>D : typeof D + } +} + +export class D extends C { +>D : D +>C : C +} diff --git a/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt b/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt new file mode 100644 index 00000000000..4d95cf01136 --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicates02.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts(9,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface. + + +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts (1 errors) ==== + + export interface Foo { + a: string; + b: number; + c: boolean; + } + + export const obj = { + m(): this is Foo { + ~~~~ +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. + let dis = this as Foo; + return dis.a != null && dis.b != null && dis.c != null; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitThisPredicates02.js b/tests/baselines/reference/declarationEmitThisPredicates02.js new file mode 100644 index 00000000000..e938a615b6d --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicates02.js @@ -0,0 +1,34 @@ +//// [declarationEmitThisPredicates02.ts] + +export interface Foo { + a: string; + b: number; + c: boolean; +} + +export const obj = { + m(): this is Foo { + let dis = this as Foo; + return dis.a != null && dis.b != null && dis.c != null; + } +} + +//// [declarationEmitThisPredicates02.js] +"use strict"; +exports.obj = { + m: function () { + var dis = this; + return dis.a != null && dis.b != null && dis.c != null; + } +}; + + +//// [declarationEmitThisPredicates02.d.ts] +export interface Foo { + a: string; + b: number; + c: boolean; +} +export declare const obj: { + m(): this is Foo; +}; diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.errors.txt b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.errors.txt new file mode 100644 index 00000000000..67c76283f80 --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts(3,18): error TS4055: Return type of public method from exported class has or is using private name 'D'. + + +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts (1 errors) ==== + + export class C { + m(): this is D { + ~ +!!! error TS4055: Return type of public method from exported class has or is using private name 'D'. + return this instanceof D; + } + } + + class D extends C { + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js new file mode 100644 index 00000000000..e34dcc9810f --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js @@ -0,0 +1,34 @@ +//// [declarationEmitThisPredicatesWithPrivateName01.ts] + +export class C { + m(): this is D { + return this instanceof D; + } +} + +class D extends C { +} + +//// [declarationEmitThisPredicatesWithPrivateName01.js] +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C = (function () { + function C() { + } + C.prototype.m = function () { + return this instanceof D; + }; + return C; +}()); +exports.C = C; +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.apply(this, arguments); + } + return D; +}(C)); diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt new file mode 100644 index 00000000000..86c0f478133 --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(8,14): error TS4025: Exported variable 'obj' has or is using private name 'Foo'. +tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(9,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface. + + +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (2 errors) ==== + + interface Foo { + a: string; + b: number; + c: boolean; + } + + export const obj = { + ~~~ +!!! error TS4025: Exported variable 'obj' has or is using private name 'Foo'. + m(): this is Foo { + ~~~~ +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. + let dis = this as Foo; + return dis.a != null && dis.b != null && dis.c != null; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js new file mode 100644 index 00000000000..df0d5b7903a --- /dev/null +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js @@ -0,0 +1,23 @@ +//// [declarationEmitThisPredicatesWithPrivateName02.ts] + +interface Foo { + a: string; + b: number; + c: boolean; +} + +export const obj = { + m(): this is Foo { + let dis = this as Foo; + return dis.a != null && dis.b != null && dis.c != null; + } +} + +//// [declarationEmitThisPredicatesWithPrivateName02.js] +"use strict"; +exports.obj = { + m: function () { + var dis = this; + return dis.a != null && dis.b != null && dis.c != null; + } +}; diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 7c4671022ea..517eaafe4ab 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -11,8 +11,8 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,13): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(62,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{}' is not an array type. +tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ 0: number; 1: number; }' is not an array type. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature. @@ -122,10 +122,10 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): function f9() { var [a, b] = {}; // Error, not array type ~~~~~~ -!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type. +!!! error TS2461: Type '{}' is not an array type. var [c, d] = { 0: 10, 1: 20 }; // Error, not array type ~~~~~~ -!!! error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type. +!!! error TS2461: Type '{ 0: number; 1: number; }' is not an array type. var [e, f] = [10, 20]; } diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types index 476b5bee0cc..cb6052d93fd 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -69,7 +69,7 @@ function foo(): F { >F : F return { ->{ 1: true } : { [x: number]: boolean; 1: boolean; } +>{ 1: true } : { 1: boolean; } 1: true >true : boolean @@ -82,7 +82,7 @@ function bar(): F { >F : F return { ->{ 2: true } : { [x: number]: boolean; 2: boolean; } +>{ 2: true } : { 2: boolean; } 2: true >true : boolean @@ -114,7 +114,7 @@ function foo1(): F1 { >F1 : F1 return { ->{ "prop1": 2 } : { [x: string]: number; "prop1": number; } +>{ "prop1": 2 } : { "prop1": number; } "prop1": 2 >2 : number diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types index 7a7f631eddf..2d77c20f65b 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -69,7 +69,7 @@ function foo(): F { >F : F return { ->{ 1: true } : { [x: number]: boolean; 1: boolean; } +>{ 1: true } : { 1: boolean; } 1: true >true : boolean @@ -82,7 +82,7 @@ function bar(): F { >F : F return { ->{ 2: true } : { [x: number]: boolean; 2: boolean; } +>{ 2: true } : { 2: boolean; } 2: true >true : boolean @@ -114,7 +114,7 @@ function foo1(): F1 { >F1 : F1 return { ->{ "prop1": 2 } : { [x: string]: number; "prop1": number; } +>{ "prop1": 2 } : { "prop1": number; } "prop1": 2 >2 : number diff --git a/tests/baselines/reference/exportRedeclarationTypeAliases.js b/tests/baselines/reference/exportRedeclarationTypeAliases.js new file mode 100644 index 00000000000..b1e2e200634 --- /dev/null +++ b/tests/baselines/reference/exportRedeclarationTypeAliases.js @@ -0,0 +1,9 @@ +//// [exportRedeclarationTypeAliases.ts] +export type Foo = number; +export function Foo(): number; +export function Foo(): any {} + +//// [exportRedeclarationTypeAliases.js] +"use strict"; +function Foo() { } +exports.Foo = Foo; diff --git a/tests/baselines/reference/exportRedeclarationTypeAliases.symbols b/tests/baselines/reference/exportRedeclarationTypeAliases.symbols new file mode 100644 index 00000000000..6561692e307 --- /dev/null +++ b/tests/baselines/reference/exportRedeclarationTypeAliases.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/exportRedeclarationTypeAliases.ts === +export type Foo = number; +>Foo : Symbol(Foo, Decl(exportRedeclarationTypeAliases.ts, 0, 0), Decl(exportRedeclarationTypeAliases.ts, 0, 25), Decl(exportRedeclarationTypeAliases.ts, 1, 30)) + +export function Foo(): number; +>Foo : Symbol(Foo, Decl(exportRedeclarationTypeAliases.ts, 0, 0), Decl(exportRedeclarationTypeAliases.ts, 0, 25), Decl(exportRedeclarationTypeAliases.ts, 1, 30)) + +export function Foo(): any {} +>Foo : Symbol(Foo, Decl(exportRedeclarationTypeAliases.ts, 0, 0), Decl(exportRedeclarationTypeAliases.ts, 0, 25), Decl(exportRedeclarationTypeAliases.ts, 1, 30)) + diff --git a/tests/baselines/reference/exportRedeclarationTypeAliases.types b/tests/baselines/reference/exportRedeclarationTypeAliases.types new file mode 100644 index 00000000000..f5c987373b6 --- /dev/null +++ b/tests/baselines/reference/exportRedeclarationTypeAliases.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/exportRedeclarationTypeAliases.ts === +export type Foo = number; +>Foo : number + +export function Foo(): number; +>Foo : () => number + +export function Foo(): any {} +>Foo : () => number + diff --git a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types index e1bfd195698..9825a75a220 100644 --- a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types +++ b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types @@ -26,7 +26,7 @@ var moduleMap: { [key: string]: IHasVisualizationModel } = { >moduleMap : { [key: string]: IHasVisualizationModel; } >key : string >IHasVisualizationModel : IHasVisualizationModel ->{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: typeof moduleA; "moduleA": typeof moduleA; "moduleB": typeof moduleB; } +>{ "moduleA": moduleA, "moduleB": moduleB} : { "moduleA": typeof moduleA; "moduleB": typeof moduleB; } "moduleA": moduleA, >moduleA : typeof moduleA diff --git a/tests/baselines/reference/generatorTypeCheck39.errors.txt b/tests/baselines/reference/generatorTypeCheck39.errors.txt index ae24837f712..aabb5a47a35 100644 --- a/tests/baselines/reference/generatorTypeCheck39.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck39.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): erro !!! error TS1163: A 'yield' expression is only allowed in a generator body. class C { ~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. x = yield 0; ~~~~~ !!! error TS1163: A 'yield' expression is only allowed in a generator body. diff --git a/tests/baselines/reference/generatorTypeCheck41.types b/tests/baselines/reference/generatorTypeCheck41.types index 926aef95ce5..0bed082dc43 100644 --- a/tests/baselines/reference/generatorTypeCheck41.types +++ b/tests/baselines/reference/generatorTypeCheck41.types @@ -3,8 +3,8 @@ function* g() { >g : () => IterableIterator let x = { ->x : {} ->{ [yield 0]: 0 } : {} +>x : { [x: number]: number; } +>{ [yield 0]: 0 } : { [x: number]: number; } [yield 0]: 0 >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck42.types b/tests/baselines/reference/generatorTypeCheck42.types index 855c4697f40..7538b8f2499 100644 --- a/tests/baselines/reference/generatorTypeCheck42.types +++ b/tests/baselines/reference/generatorTypeCheck42.types @@ -3,8 +3,8 @@ function* g() { >g : () => IterableIterator let x = { ->x : {} ->{ [yield 0]() { } } : {} +>x : { [x: number]: () => void; } +>{ [yield 0]() { } } : { [x: number]: () => void; } [yield 0]() { >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck43.types b/tests/baselines/reference/generatorTypeCheck43.types index 50fc7e30c86..a132dfcb015 100644 --- a/tests/baselines/reference/generatorTypeCheck43.types +++ b/tests/baselines/reference/generatorTypeCheck43.types @@ -3,8 +3,8 @@ function* g() { >g : () => IterableIterator let x = { ->x : {} ->{ *[yield 0]() { } } : {} +>x : { [x: number]: () => IterableIterator; } +>{ *[yield 0]() { } } : { [x: number]: () => IterableIterator; } *[yield 0]() { >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck44.types b/tests/baselines/reference/generatorTypeCheck44.types index 2fc67f90556..5c432e41cbe 100644 --- a/tests/baselines/reference/generatorTypeCheck44.types +++ b/tests/baselines/reference/generatorTypeCheck44.types @@ -3,8 +3,8 @@ function* g() { >g : () => IterableIterator let x = { ->x : {} ->{ get [yield 0]() { return 0; } } : {} +>x : { [x: number]: number; } +>{ get [yield 0]() { return 0; } } : { [x: number]: number; } get [yield 0]() { >yield 0 : any diff --git a/tests/baselines/reference/generatorTypeCheck59.errors.txt b/tests/baselines/reference/generatorTypeCheck59.errors.txt index d8179803821..cba90154701 100644 --- a/tests/baselines/reference/generatorTypeCheck59.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck59.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. ==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts (2 errors) ==== @@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error !!! error TS1163: A 'yield' expression is only allowed in a generator body. m() { } ~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. }; } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck61.errors.txt b/tests/baselines/reference/generatorTypeCheck61.errors.txt index b38e96d31ce..ccc99f7ffbd 100644 --- a/tests/baselines/reference/generatorTypeCheck61.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck61.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(2,7): error TS1163: A 'yield' expression is only allowed in a generator body. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. ==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts (2 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): erro !!! error TS1163: A 'yield' expression is only allowed in a generator body. class C {}; ~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. } \ No newline at end of file diff --git a/tests/baselines/reference/genericBaseClassLiteralProperty2.types b/tests/baselines/reference/genericBaseClassLiteralProperty2.types index d7d512165f0..3e320824925 100644 --- a/tests/baselines/reference/genericBaseClassLiteralProperty2.types +++ b/tests/baselines/reference/genericBaseClassLiteralProperty2.types @@ -14,11 +14,11 @@ class BaseCollection2 { constructor() { this._itemsByKey = {}; ->this._itemsByKey = {} : { [x: string]: undefined; } +>this._itemsByKey = {} : {} >this._itemsByKey : { [key: string]: TItem; } >this : this >_itemsByKey : { [key: string]: TItem; } ->{} : { [x: string]: undefined; } +>{} : {} } } diff --git a/tests/baselines/reference/genericCallWithTupleType.errors.txt b/tests/baselines/reference/genericCallWithTupleType.errors.txt index d03f8d5e68a..bcf580320e5 100644 --- a/tests/baselines/reference/genericCallWithTupleType.errors.txt +++ b/tests/baselines/reference/genericCallWithTupleType.errors.txt @@ -9,9 +9,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]'. Types of property '0' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{ [x: number]: undefined; }, {}]' is not assignable to type '[string, number]'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]'. Types of property '0' are incompatible. - Type '{ [x: number]: undefined; }' is not assignable to type 'string'. + Type '{}' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]'. Property '1' is missing in type '[{}]'. @@ -55,9 +55,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup !!! error TS2322: Type 'number' is not assignable to type 'string'. i1.tuple1 = [{}, {}]; ~~~~~~~~~ -!!! error TS2322: Type '[{ [x: number]: undefined; }, {}]' is not assignable to type '[string, number]'. +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]'. !!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type '{ [x: number]: undefined; }' is not assignable to type 'string'. +!!! error TS2322: Type '{}' is not assignable to type 'string'. i2.tuple1 = [{}]; ~~~~~~~~~ !!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]'. diff --git a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types index 337993dc2a6..a316773e5c8 100644 --- a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types +++ b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types @@ -8,7 +8,7 @@ class LazyArray { ><{ [objectId: string]: T; }>{} : { [objectId: string]: T; } >objectId : string >T : T ->{} : { [x: string]: undefined; } +>{} : {} array() { >array : () => { [objectId: string]: T; } diff --git a/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt b/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt index 1e66f26d0d2..493fc13db04 100644 --- a/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt +++ b/tests/baselines/reference/implicitAnyInAmbientDeclaration.errors.txt @@ -1,10 +1,9 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(3,9): error TS7008: Member 'publicMember' implicitly has an 'any' type. tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(6,16): error TS7010: 'publicFunction', which lacks return-type annotation, implicitly has an 'any' return type. tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(6,31): error TS7006: Parameter 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(8,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. -==== tests/cases/compiler/implicitAnyInAmbientDeclaration.ts (4 errors) ==== +==== tests/cases/compiler/implicitAnyInAmbientDeclaration.ts (3 errors) ==== module Test { declare class C { public publicMember; // this should be an error @@ -19,7 +18,5 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration.ts(8,9): error TS1089: 'pri !!! error TS7006: Parameter 'x' implicitly has an 'any' type. private privateFunction(privateParam); // this should not be an error private constructor(privateParam); - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } } \ No newline at end of file diff --git a/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt b/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt index 54fe39e2efe..03de82c731d 100644 --- a/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt +++ b/tests/baselines/reference/implicitAnyInAmbientDeclaration2.d.errors.txt @@ -4,11 +4,10 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(2,13): error TS7005: tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(4,5): error TS7008: Member 'publicMember' implicitly has an 'any' type. tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(7,12): error TS7010: 'publicFunction', which lacks return-type annotation, implicitly has an 'any' return type. tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(7,27): error TS7006: Parameter 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(9,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(13,24): error TS7006: Parameter 'publicConsParam' implicitly has an 'any' type. -==== tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts (8 errors) ==== +==== tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts (7 errors) ==== declare function foo(x); // this should be an error ~~~ !!! error TS7010: 'foo', which lacks return-type annotation, implicitly has an 'any' return type. @@ -30,8 +29,6 @@ tests/cases/compiler/implicitAnyInAmbientDeclaration2.d.ts(13,24): error TS7006: !!! error TS7006: Parameter 'x' implicitly has an 'any' type. private privateFunction(privateParam); // this should not be an error private constructor(privateParam); // this should not be an error - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } declare class D { diff --git a/tests/baselines/reference/implicitIndexSignatures.js b/tests/baselines/reference/implicitIndexSignatures.js new file mode 100644 index 00000000000..6403f1f1543 --- /dev/null +++ b/tests/baselines/reference/implicitIndexSignatures.js @@ -0,0 +1,85 @@ +//// [implicitIndexSignatures.ts] +type StringMap = { [x: string]: string }; + +const empty1 = {}; +let empty2: {}; +const names1 = { a: "foo", b: "bar" }; +let names2: { a: string, b: string }; +let map: StringMap; +map = { x: "xxx", y: "yyy" }; +map = empty1; +map = empty2; +map = names1; +map = names2; + +declare function getStringIndexValue(map: { [x: string]: T }): T; +declare function getNumberIndexValue(map: { [x: number]: T }): T; + +function f1() { + const o1 = { a: 1, b: 2 }; + let o2: { a: number, b: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f2() { + const o1 = { a: "1", b: "2" }; + let o2: { a: string, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f3() { + const o1 = { a: 1, b: "2" }; + let o2: { a: number, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f4() { + const o1 = { 0: "0", 1: "1", count: 2 }; + let o2: { 0: string, 1: string, count: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); + const v3 = getNumberIndexValue(o1); + const v4 = getNumberIndexValue(o2); +} + + +//// [implicitIndexSignatures.js] +var empty1 = {}; +var empty2; +var names1 = { a: "foo", b: "bar" }; +var names2; +var map; +map = { x: "xxx", y: "yyy" }; +map = empty1; +map = empty2; +map = names1; +map = names2; +function f1() { + var o1 = { a: 1, b: 2 }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); +} +function f2() { + var o1 = { a: "1", b: "2" }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); +} +function f3() { + var o1 = { a: 1, b: "2" }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); +} +function f4() { + var o1 = { 0: "0", 1: "1", count: 2 }; + var o2; + var v1 = getStringIndexValue(o1); + var v2 = getStringIndexValue(o2); + var v3 = getNumberIndexValue(o1); + var v4 = getNumberIndexValue(o2); +} diff --git a/tests/baselines/reference/implicitIndexSignatures.symbols b/tests/baselines/reference/implicitIndexSignatures.symbols new file mode 100644 index 00000000000..a014e7e942c --- /dev/null +++ b/tests/baselines/reference/implicitIndexSignatures.symbols @@ -0,0 +1,166 @@ +=== tests/cases/compiler/implicitIndexSignatures.ts === +type StringMap = { [x: string]: string }; +>StringMap : Symbol(StringMap, Decl(implicitIndexSignatures.ts, 0, 0)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 0, 20)) + +const empty1 = {}; +>empty1 : Symbol(empty1, Decl(implicitIndexSignatures.ts, 2, 5)) + +let empty2: {}; +>empty2 : Symbol(empty2, Decl(implicitIndexSignatures.ts, 3, 3)) + +const names1 = { a: "foo", b: "bar" }; +>names1 : Symbol(names1, Decl(implicitIndexSignatures.ts, 4, 5)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 4, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 4, 26)) + +let names2: { a: string, b: string }; +>names2 : Symbol(names2, Decl(implicitIndexSignatures.ts, 5, 3)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 5, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 5, 24)) + +let map: StringMap; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>StringMap : Symbol(StringMap, Decl(implicitIndexSignatures.ts, 0, 0)) + +map = { x: "xxx", y: "yyy" }; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 7, 7)) +>y : Symbol(y, Decl(implicitIndexSignatures.ts, 7, 17)) + +map = empty1; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>empty1 : Symbol(empty1, Decl(implicitIndexSignatures.ts, 2, 5)) + +map = empty2; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>empty2 : Symbol(empty2, Decl(implicitIndexSignatures.ts, 3, 3)) + +map = names1; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>names1 : Symbol(names1, Decl(implicitIndexSignatures.ts, 4, 5)) + +map = names2; +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 6, 3)) +>names2 : Symbol(names2, Decl(implicitIndexSignatures.ts, 5, 3)) + +declare function getStringIndexValue(map: { [x: string]: T }): T; +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37)) +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 13, 40)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 13, 48)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 13, 37)) + +declare function getNumberIndexValue(map: { [x: number]: T }): T; +>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37)) +>map : Symbol(map, Decl(implicitIndexSignatures.ts, 14, 40)) +>x : Symbol(x, Decl(implicitIndexSignatures.ts, 14, 48)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37)) +>T : Symbol(T, Decl(implicitIndexSignatures.ts, 14, 37)) + +function f1() { +>f1 : Symbol(f1, Decl(implicitIndexSignatures.ts, 14, 68)) + + const o1 = { a: 1, b: 2 }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 17, 9)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 17, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 17, 22)) + + let o2: { a: number, b: number }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 18, 7)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 18, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 18, 24)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 19, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 17, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 20, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 18, 7)) +} + +function f2() { +>f2 : Symbol(f2, Decl(implicitIndexSignatures.ts, 21, 1)) + + const o1 = { a: "1", b: "2" }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 24, 9)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 24, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 24, 24)) + + let o2: { a: string, b: string }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 25, 7)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 25, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 25, 24)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 26, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 24, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 27, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 25, 7)) +} + +function f3() { +>f3 : Symbol(f3, Decl(implicitIndexSignatures.ts, 28, 1)) + + const o1 = { a: 1, b: "2" }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 31, 9)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 31, 16)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 31, 22)) + + let o2: { a: number, b: string }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 32, 7)) +>a : Symbol(a, Decl(implicitIndexSignatures.ts, 32, 13)) +>b : Symbol(b, Decl(implicitIndexSignatures.ts, 32, 24)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 33, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 31, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 34, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 32, 7)) +} + +function f4() { +>f4 : Symbol(f4, Decl(implicitIndexSignatures.ts, 35, 1)) + + const o1 = { 0: "0", 1: "1", count: 2 }; +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9)) +>count : Symbol(count, Decl(implicitIndexSignatures.ts, 38, 32)) + + let o2: { 0: string, 1: string, count: number }; +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7)) +>count : Symbol(count, Decl(implicitIndexSignatures.ts, 39, 35)) + + const v1 = getStringIndexValue(o1); +>v1 : Symbol(v1, Decl(implicitIndexSignatures.ts, 40, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9)) + + const v2 = getStringIndexValue(o2); +>v2 : Symbol(v2, Decl(implicitIndexSignatures.ts, 41, 9)) +>getStringIndexValue : Symbol(getStringIndexValue, Decl(implicitIndexSignatures.ts, 11, 13)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7)) + + const v3 = getNumberIndexValue(o1); +>v3 : Symbol(v3, Decl(implicitIndexSignatures.ts, 42, 9)) +>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68)) +>o1 : Symbol(o1, Decl(implicitIndexSignatures.ts, 38, 9)) + + const v4 = getNumberIndexValue(o2); +>v4 : Symbol(v4, Decl(implicitIndexSignatures.ts, 43, 9)) +>getNumberIndexValue : Symbol(getNumberIndexValue, Decl(implicitIndexSignatures.ts, 13, 68)) +>o2 : Symbol(o2, Decl(implicitIndexSignatures.ts, 39, 7)) +} + diff --git a/tests/baselines/reference/implicitIndexSignatures.types b/tests/baselines/reference/implicitIndexSignatures.types new file mode 100644 index 00000000000..7d335c00491 --- /dev/null +++ b/tests/baselines/reference/implicitIndexSignatures.types @@ -0,0 +1,201 @@ +=== tests/cases/compiler/implicitIndexSignatures.ts === +type StringMap = { [x: string]: string }; +>StringMap : { [x: string]: string; } +>x : string + +const empty1 = {}; +>empty1 : {} +>{} : {} + +let empty2: {}; +>empty2 : {} + +const names1 = { a: "foo", b: "bar" }; +>names1 : { a: string; b: string; } +>{ a: "foo", b: "bar" } : { a: string; b: string; } +>a : string +>"foo" : string +>b : string +>"bar" : string + +let names2: { a: string, b: string }; +>names2 : { a: string; b: string; } +>a : string +>b : string + +let map: StringMap; +>map : { [x: string]: string; } +>StringMap : { [x: string]: string; } + +map = { x: "xxx", y: "yyy" }; +>map = { x: "xxx", y: "yyy" } : { x: string; y: string; } +>map : { [x: string]: string; } +>{ x: "xxx", y: "yyy" } : { x: string; y: string; } +>x : string +>"xxx" : string +>y : string +>"yyy" : string + +map = empty1; +>map = empty1 : {} +>map : { [x: string]: string; } +>empty1 : {} + +map = empty2; +>map = empty2 : {} +>map : { [x: string]: string; } +>empty2 : {} + +map = names1; +>map = names1 : { a: string; b: string; } +>map : { [x: string]: string; } +>names1 : { a: string; b: string; } + +map = names2; +>map = names2 : { a: string; b: string; } +>map : { [x: string]: string; } +>names2 : { a: string; b: string; } + +declare function getStringIndexValue(map: { [x: string]: T }): T; +>getStringIndexValue : (map: { [x: string]: T; }) => T +>T : T +>map : { [x: string]: T; } +>x : string +>T : T +>T : T + +declare function getNumberIndexValue(map: { [x: number]: T }): T; +>getNumberIndexValue : (map: { [x: number]: T; }) => T +>T : T +>map : { [x: number]: T; } +>x : number +>T : T +>T : T + +function f1() { +>f1 : () => void + + const o1 = { a: 1, b: 2 }; +>o1 : { a: number; b: number; } +>{ a: 1, b: 2 } : { a: number; b: number; } +>a : number +>1 : number +>b : number +>2 : number + + let o2: { a: number, b: number }; +>o2 : { a: number; b: number; } +>a : number +>b : number + + const v1 = getStringIndexValue(o1); +>v1 : number +>getStringIndexValue(o1) : number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { a: number; b: number; } + + const v2 = getStringIndexValue(o2); +>v2 : number +>getStringIndexValue(o2) : number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { a: number; b: number; } +} + +function f2() { +>f2 : () => void + + const o1 = { a: "1", b: "2" }; +>o1 : { a: string; b: string; } +>{ a: "1", b: "2" } : { a: string; b: string; } +>a : string +>"1" : string +>b : string +>"2" : string + + let o2: { a: string, b: string }; +>o2 : { a: string; b: string; } +>a : string +>b : string + + const v1 = getStringIndexValue(o1); +>v1 : string +>getStringIndexValue(o1) : string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { a: string; b: string; } + + const v2 = getStringIndexValue(o2); +>v2 : string +>getStringIndexValue(o2) : string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { a: string; b: string; } +} + +function f3() { +>f3 : () => void + + const o1 = { a: 1, b: "2" }; +>o1 : { a: number; b: string; } +>{ a: 1, b: "2" } : { a: number; b: string; } +>a : number +>1 : number +>b : string +>"2" : string + + let o2: { a: number, b: string }; +>o2 : { a: number; b: string; } +>a : number +>b : string + + const v1 = getStringIndexValue(o1); +>v1 : number | string +>getStringIndexValue(o1) : number | string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { a: number; b: string; } + + const v2 = getStringIndexValue(o2); +>v2 : number | string +>getStringIndexValue(o2) : number | string +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { a: number; b: string; } +} + +function f4() { +>f4 : () => void + + const o1 = { 0: "0", 1: "1", count: 2 }; +>o1 : { 0: string; 1: string; count: number; } +>{ 0: "0", 1: "1", count: 2 } : { 0: string; 1: string; count: number; } +>"0" : string +>"1" : string +>count : number +>2 : number + + let o2: { 0: string, 1: string, count: number }; +>o2 : { 0: string; 1: string; count: number; } +>count : number + + const v1 = getStringIndexValue(o1); +>v1 : string | number +>getStringIndexValue(o1) : string | number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o1 : { 0: string; 1: string; count: number; } + + const v2 = getStringIndexValue(o2); +>v2 : string | number +>getStringIndexValue(o2) : string | number +>getStringIndexValue : (map: { [x: string]: T; }) => T +>o2 : { 0: string; 1: string; count: number; } + + const v3 = getNumberIndexValue(o1); +>v3 : string +>getNumberIndexValue(o1) : string +>getNumberIndexValue : (map: { [x: number]: T; }) => T +>o1 : { 0: string; 1: string; count: number; } + + const v4 = getNumberIndexValue(o2); +>v4 : string +>getNumberIndexValue(o2) : string +>getNumberIndexValue : (map: { [x: number]: T; }) => T +>o2 : { 0: string; 1: string; count: number; } +} + diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.types b/tests/baselines/reference/indexSignaturesInferentialTyping.types index 328dbc18e4f..8545a7d4ca9 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.types +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.types @@ -21,15 +21,15 @@ var x1 = foo({ 0: 0, 1: 1 }); // type should be number >x1 : number >foo({ 0: 0, 1: 1 }) : number >foo : (items: { [index: number]: T; }) => T ->{ 0: 0, 1: 1 } : { [x: number]: number; 0: number; 1: number; } +>{ 0: 0, 1: 1 } : { 0: number; 1: number; } >0 : number >1 : number var x2 = foo({ zero: 0, one: 1 }); ->x2 : any ->foo({ zero: 0, one: 1 }) : any +>x2 : {} +>foo({ zero: 0, one: 1 }) : {} >foo : (items: { [index: number]: T; }) => T ->{ zero: 0, one: 1 } : { [x: number]: undefined; zero: number; one: number; } +>{ zero: 0, one: 1 } : { zero: number; one: number; } >zero : number >0 : number >one : number @@ -39,7 +39,7 @@ var x3 = bar({ 0: 0, 1: 1 }); >x3 : number >bar({ 0: 0, 1: 1 }) : number >bar : (items: { [index: string]: T; }) => T ->{ 0: 0, 1: 1 } : { [x: string]: number; 0: number; 1: number; } +>{ 0: 0, 1: 1 } : { 0: number; 1: number; } >0 : number >1 : number @@ -47,7 +47,7 @@ var x4 = bar({ zero: 0, one: 1 }); // type should be number >x4 : number >bar({ zero: 0, one: 1 }) : number >bar : (items: { [index: string]: T; }) => T ->{ zero: 0, one: 1 } : { [x: string]: number; zero: number; one: number; } +>{ zero: 0, one: 1 } : { zero: number; one: number; } >zero : number >0 : number >one : number diff --git a/tests/baselines/reference/indexer.types b/tests/baselines/reference/indexer.types index a0142bb9383..f24c90f6ea1 100644 --- a/tests/baselines/reference/indexer.types +++ b/tests/baselines/reference/indexer.types @@ -17,7 +17,7 @@ interface JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >"a" : string diff --git a/tests/baselines/reference/indexer2.types b/tests/baselines/reference/indexer2.types index 7f1ccd41cb5..ff82707edd3 100644 --- a/tests/baselines/reference/indexer2.types +++ b/tests/baselines/reference/indexer2.types @@ -17,5 +17,5 @@ var directChildrenMap = {}; >directChildrenMap : IDirectChildrenMap >{} : IDirectChildrenMap >IDirectChildrenMap : IDirectChildrenMap ->{} : { [x: number]: undefined; } +>{} : {} diff --git a/tests/baselines/reference/indexer3.types b/tests/baselines/reference/indexer3.types index 8f0582f782a..28bcd9cab0c 100644 --- a/tests/baselines/reference/indexer3.types +++ b/tests/baselines/reference/indexer3.types @@ -3,7 +3,7 @@ var dateMap: { [x: string]: Date; } = {} >dateMap : { [x: string]: Date; } >x : string >Date : Date ->{} : { [x: string]: undefined; } +>{} : {} var r: Date = dateMap["hello"] // result type includes indexer using BCT >r : Date diff --git a/tests/baselines/reference/indexerA.types b/tests/baselines/reference/indexerA.types index c6ff81b3a26..ee6351eae33 100644 --- a/tests/baselines/reference/indexerA.types +++ b/tests/baselines/reference/indexerA.types @@ -17,7 +17,7 @@ class JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >"a" : string diff --git a/tests/baselines/reference/indexerAssignability.errors.txt b/tests/baselines/reference/indexerAssignability.errors.txt deleted file mode 100644 index 44c2184517e..00000000000 --- a/tests/baselines/reference/indexerAssignability.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/compiler/indexerAssignability.ts(5,1): error TS2322: Type '{ [n: number]: string; }' is not assignable to type '{ [s: string]: string; }'. - Index signature is missing in type '{ [n: number]: string; }'. -tests/cases/compiler/indexerAssignability.ts(6,1): error TS2322: Type '{}' is not assignable to type '{ [s: string]: string; }'. - Index signature is missing in type '{}'. -tests/cases/compiler/indexerAssignability.ts(8,1): error TS2322: Type '{}' is not assignable to type '{ [n: number]: string; }'. - Index signature is missing in type '{}'. - - -==== tests/cases/compiler/indexerAssignability.ts (3 errors) ==== - var a: { [s: string]: string; }; - var b: { [n: number]: string; }; - var c: {}; - - a = b; - ~ -!!! error TS2322: Type '{ [n: number]: string; }' is not assignable to type '{ [s: string]: string; }'. -!!! error TS2322: Index signature is missing in type '{ [n: number]: string; }'. - a = c; - ~ -!!! error TS2322: Type '{}' is not assignable to type '{ [s: string]: string; }'. -!!! error TS2322: Index signature is missing in type '{}'. - b = a; - b = c; - ~ -!!! error TS2322: Type '{}' is not assignable to type '{ [n: number]: string; }'. -!!! error TS2322: Index signature is missing in type '{}'. - c = a; - c = b; \ No newline at end of file diff --git a/tests/baselines/reference/indexerAssignability.symbols b/tests/baselines/reference/indexerAssignability.symbols new file mode 100644 index 00000000000..379a2885e2c --- /dev/null +++ b/tests/baselines/reference/indexerAssignability.symbols @@ -0,0 +1,36 @@ +=== tests/cases/compiler/indexerAssignability.ts === +var a: { [s: string]: string; }; +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) +>s : Symbol(s, Decl(indexerAssignability.ts, 0, 10)) + +var b: { [n: number]: string; }; +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) +>n : Symbol(n, Decl(indexerAssignability.ts, 1, 10)) + +var c: {}; +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) + +a = b; +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) + +a = c; +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) + +b = a; +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) + +b = c; +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) + +c = a; +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) +>a : Symbol(a, Decl(indexerAssignability.ts, 0, 3)) + +c = b; +>c : Symbol(c, Decl(indexerAssignability.ts, 2, 3)) +>b : Symbol(b, Decl(indexerAssignability.ts, 1, 3)) + diff --git a/tests/baselines/reference/indexerAssignability.types b/tests/baselines/reference/indexerAssignability.types new file mode 100644 index 00000000000..bd301b59224 --- /dev/null +++ b/tests/baselines/reference/indexerAssignability.types @@ -0,0 +1,42 @@ +=== tests/cases/compiler/indexerAssignability.ts === +var a: { [s: string]: string; }; +>a : { [s: string]: string; } +>s : string + +var b: { [n: number]: string; }; +>b : { [n: number]: string; } +>n : number + +var c: {}; +>c : {} + +a = b; +>a = b : { [n: number]: string; } +>a : { [s: string]: string; } +>b : { [n: number]: string; } + +a = c; +>a = c : {} +>a : { [s: string]: string; } +>c : {} + +b = a; +>b = a : { [s: string]: string; } +>b : { [n: number]: string; } +>a : { [s: string]: string; } + +b = c; +>b = c : {} +>b : { [n: number]: string; } +>c : {} + +c = a; +>c = a : { [s: string]: string; } +>c : {} +>a : { [s: string]: string; } + +c = b; +>c = b : { [n: number]: string; } +>c : {} +>b : { [n: number]: string; } + diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types index be937410cef..f70305739b8 100644 --- a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types @@ -30,13 +30,13 @@ foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } } >foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }) : string >foo : (x: T, y: Int, z: Int) => T >"" : string ->{ method(p1) { return p1.length } } : { [x: string]: (p1: string) => number; method(p1: string): number; } +>{ method(p1) { return p1.length } } : { method(p1: string): number; } >method : (p1: string) => number >p1 : string >p1.length : number >p1 : string >length : number ->{ method(p2) { return undefined } } : { [x: string]: (p2: number) => any; method(p2: number): any; } +>{ method(p2) { return undefined } } : { method(p2: number): any; } >method : (p2: number) => any >p2 : number >undefined : undefined diff --git a/tests/baselines/reference/inferentialTypingUsingApparentType3.types b/tests/baselines/reference/inferentialTypingUsingApparentType3.types index 9e0a4ceaea6..e375fe981e8 100644 --- a/tests/baselines/reference/inferentialTypingUsingApparentType3.types +++ b/tests/baselines/reference/inferentialTypingUsingApparentType3.types @@ -49,10 +49,10 @@ class ObjectField }> { } var person = new ObjectField({ ->person : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> ->new ObjectField({ id: new NumberField(), name: new CharField()}) : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> +>person : ObjectField<{}, { id: NumberField; name: CharField; }> +>new ObjectField({ id: new NumberField(), name: new CharField()}) : ObjectField<{}, { id: NumberField; name: CharField; }> >ObjectField : typeof ObjectField ->{ id: new NumberField(), name: new CharField()} : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } +>{ id: new NumberField(), name: new CharField()} : { id: NumberField; name: CharField; } id: new NumberField(), >id : NumberField @@ -68,8 +68,8 @@ var person = new ObjectField({ person.fields.id; >person.fields.id : NumberField ->person.fields : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } ->person : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> ->fields : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } +>person.fields : { id: NumberField; name: CharField; } +>person : ObjectField<{}, { id: NumberField; name: CharField; }> +>fields : { id: NumberField; name: CharField; } >id : NumberField diff --git a/tests/baselines/reference/interfaceContextualType.types b/tests/baselines/reference/interfaceContextualType.types index e827f9a9d9b..0e835a2f1f9 100644 --- a/tests/baselines/reference/interfaceContextualType.types +++ b/tests/baselines/reference/interfaceContextualType.types @@ -27,11 +27,11 @@ class Bug { >ok : () => void this.values = {}; ->this.values = {} : { [x: string]: undefined; } +>this.values = {} : {} >this.values : IMap >this : this >values : IMap ->{} : { [x: string]: undefined; } +>{} : {} this.values['comments'] = { italic: true }; >this.values['comments'] = { italic: true } : { italic: boolean; } @@ -48,11 +48,11 @@ class Bug { >shouldBeOK : () => void this.values = { ->this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } +>this.values = { comments: { italic: true } } : { comments: { italic: boolean; }; } >this.values : IMap >this : this >values : IMap ->{ comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } +>{ comments: { italic: true } } : { comments: { italic: boolean; }; } comments: { italic: true } >comments : { italic: boolean; } diff --git a/tests/baselines/reference/isArray.types b/tests/baselines/reference/isArray.types index de54e9d064c..bc452b12bef 100644 --- a/tests/baselines/reference/isArray.types +++ b/tests/baselines/reference/isArray.types @@ -4,7 +4,7 @@ var maybeArray: number | number[]; if (Array.isArray(maybeArray)) { ->Array.isArray(maybeArray) : arg is any[] +>Array.isArray(maybeArray) : boolean >Array.isArray : (arg: any) => arg is any[] >Array : ArrayConstructor >isArray : (arg: any) => arg is any[] diff --git a/tests/baselines/reference/jsFileCompilationDecoratorSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationDecoratorSyntax.errors.txt deleted file mode 100644 index a39d2e1665c..00000000000 --- a/tests/baselines/reference/jsFileCompilationDecoratorSyntax.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. -tests/cases/compiler/a.js(1,1): error TS8017: 'decorators' can only be used in a .ts file. - - -!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. -==== tests/cases/compiler/a.js (1 errors) ==== - @internal class C { } - ~~~~~~~~~ -!!! error TS8017: 'decorators' can only be used in a .ts file. \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationDecoratorSyntax.symbols b/tests/baselines/reference/jsFileCompilationDecoratorSyntax.symbols new file mode 100644 index 00000000000..02973b43147 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationDecoratorSyntax.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/a.js === +@internal class C { } +>C : Symbol(C, Decl(a.js, 0, 0)) + diff --git a/tests/baselines/reference/jsFileCompilationDecoratorSyntax.types b/tests/baselines/reference/jsFileCompilationDecoratorSyntax.types new file mode 100644 index 00000000000..ee1f14129d5 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationDecoratorSyntax.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/a.js === +@internal class C { } +>internal : any +>C : C + diff --git a/tests/baselines/reference/noErrorsInCallback.errors.txt b/tests/baselines/reference/noErrorsInCallback.errors.txt index 90fdbbd77a5..f0bfe00199e 100644 --- a/tests/baselines/reference/noErrorsInCallback.errors.txt +++ b/tests/baselines/reference/noErrorsInCallback.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/noErrorsInCallback.ts(4,19): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. -tests/cases/compiler/noErrorsInCallback.ts(6,23): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. +tests/cases/compiler/noErrorsInCallback.ts(4,19): error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. +tests/cases/compiler/noErrorsInCallback.ts(6,23): error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. ==== tests/cases/compiler/noErrorsInCallback.ts (2 errors) ==== @@ -8,10 +8,10 @@ tests/cases/compiler/noErrorsInCallback.ts(6,23): error TS2345: Argument of type } var one = new Bar({}); // Error ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. [].forEach(() => { var two = new Bar({}); // No error? ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'string'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. }); \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types index b7b21bf8f92..d82b37e0f9e 100644 --- a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types +++ b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types @@ -87,7 +87,7 @@ interface MyMap { var m: MyMap = { >m : MyMap >MyMap : MyMap ->{ "0": 0, "1": 1, "2": 2, "Okay that's enough for today.": NaN} : { [x: string]: number; "0": number; "1": number; "2": number; "Okay that's enough for today.": number; } +>{ "0": 0, "1": 1, "2": 2, "Okay that's enough for today.": NaN} : { "0": number; "1": number; "2": number; "Okay that's enough for today.": number; } "0": 0, >0 : number diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 35673eb3072..bb01b2fe125 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -5,10 +5,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. - Index signatures are incompatible. - Type 'string | number' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. + Property '2.0' is incompatible with index signature. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -108,10 +107,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. -!!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. +!!! error TS2322: Property '2.0' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index ff18160e9a5..332b356c732 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,10 +1,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: A | number; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. - Index signatures are incompatible. - Type 'A | number' is not assignable to type 'A'. - Type 'number' is not assignable to type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. + Property '3.0' is incompatible with index signature. + Type 'number' is not assignable to type 'A'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (4 errors) ==== @@ -54,10 +53,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: A } = { ~ -!!! error TS2322: Type '{ [x: number]: A | number; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. -!!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'A | number' is not assignable to type 'A'. -!!! error TS2322: Type 'number' is not assignable to type 'A'. +!!! error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. +!!! error TS2322: Property '3.0' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), diff --git a/tests/baselines/reference/numericIndexerConstraint2.errors.txt b/tests/baselines/reference/numericIndexerConstraint2.errors.txt index 385efbcead2..5c0337acc32 100644 --- a/tests/baselines/reference/numericIndexerConstraint2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstraint2.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/numericIndexerConstraint2.ts(4,1): error TS2322: Type '{ one: number; }' is not assignable to type '{ [index: string]: Foo; }'. - Index signature is missing in type '{ one: number; }'. + Property 'one' is incompatible with index signature. + Type 'number' is not assignable to type 'Foo'. ==== tests/cases/compiler/numericIndexerConstraint2.ts (1 errors) ==== @@ -9,4 +10,5 @@ tests/cases/compiler/numericIndexerConstraint2.ts(4,1): error TS2322: Type '{ on x = a; ~ !!! error TS2322: Type '{ one: number; }' is not assignable to type '{ [index: string]: Foo; }'. -!!! error TS2322: Index signature is missing in type '{ one: number; }'. \ No newline at end of file +!!! error TS2322: Property 'one' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexerConstraint4.types b/tests/baselines/reference/numericIndexerConstraint4.types index 97e72b5088d..c8af4d54a9a 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.types +++ b/tests/baselines/reference/numericIndexerConstraint4.types @@ -22,7 +22,7 @@ var x: { >A : A } = { data: new B() } ->{ data: new B() } : { [x: number]: undefined; data: B; } +>{ data: new B() } : { data: B; } >data : B >new B() : B >B : typeof B diff --git a/tests/baselines/reference/numericIndexerConstraint5.errors.txt b/tests/baselines/reference/numericIndexerConstraint5.errors.txt index 98acc65eeb7..cb888de08c4 100644 --- a/tests/baselines/reference/numericIndexerConstraint5.errors.txt +++ b/tests/baselines/reference/numericIndexerConstraint5.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/numericIndexerConstraint5.ts(2,5): error TS2322: Type '{ 0: Date; name: string; }' is not assignable to type '{ [name: number]: string; }'. - Index signature is missing in type '{ 0: Date; name: string; }'. + Property '0' is incompatible with index signature. + Type 'Date' is not assignable to type 'string'. ==== tests/cases/compiler/numericIndexerConstraint5.ts (1 errors) ==== @@ -7,4 +8,5 @@ tests/cases/compiler/numericIndexerConstraint5.ts(2,5): error TS2322: Type '{ 0: var z: { [name: number]: string } = x; ~ !!! error TS2322: Type '{ 0: Date; name: string; }' is not assignable to type '{ [name: number]: string; }'. -!!! error TS2322: Index signature is missing in type '{ 0: Date; name: string; }'. \ No newline at end of file +!!! error TS2322: Property '0' is incompatible with index signature. +!!! error TS2322: Type 'Date' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexingResults.types b/tests/baselines/reference/numericIndexingResults.types index 560bbdc74a8..9a060b388e3 100644 --- a/tests/baselines/reference/numericIndexingResults.types +++ b/tests/baselines/reference/numericIndexingResults.types @@ -151,7 +151,7 @@ var r6 = a[3]; var b: { [x: number]: string } = { 1: '', "2": '' } >b : { [x: number]: string; } >x : number ->{ 1: '', "2": '' } : { [x: number]: string; 1: string; "2": string; } +>{ 1: '', "2": '' } : { 1: string; "2": string; } >'' : string >'' : string @@ -194,7 +194,7 @@ var r6 = b[3]; var b2: { [x: number]: string; 1: string; "2": string; } = { 1: '', "2": '' } >b2 : { [x: number]: string; 1: string; "2": string; } >x : number ->{ 1: '', "2": '' } : { [x: number]: string; 1: string; "2": string; } +>{ 1: '', "2": '' } : { 1: string; "2": string; } >'' : string >'' : string diff --git a/tests/baselines/reference/objectIndexer.types b/tests/baselines/reference/objectIndexer.types index 3dcd7bcb77e..b11c475a386 100644 --- a/tests/baselines/reference/objectIndexer.types +++ b/tests/baselines/reference/objectIndexer.types @@ -23,11 +23,11 @@ class Emitter { constructor () { this.listeners = {}; ->this.listeners = {} : { [x: string]: undefined; } +>this.listeners = {} : {} >this.listeners : IMap >this : this >listeners : IMap ->{} : { [x: string]: undefined; } +>{} : {} } } diff --git a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt index f825c416311..9d5ff7ea0a2 100644 --- a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt @@ -1,10 +1,13 @@ -tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. - Index signatures are incompatible. +tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. + Property '0' is incompatible with index signature. Type 'A' is not assignable to type 'B'. Property 'y' is missing in type 'A'. +tests/cases/compiler/objectLiteralIndexerErrors.ts(14,1): error TS2322: Type '{ 0: A; x: any; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. + Property '0' is incompatible with index signature. + Type 'A' is not assignable to type 'B'. -==== tests/cases/compiler/objectLiteralIndexerErrors.ts (1 errors) ==== +==== tests/cases/compiler/objectLiteralIndexerErrors.ts (2 errors) ==== interface A { x: number; } @@ -19,8 +22,12 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ var o1: { [s: string]: A;[n: number]: B; } = { x: b, 0: a }; // both indexers are A ~~ -!!! error TS2322: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. +!!! error TS2322: Property '0' is incompatible with index signature. !!! error TS2322: Type 'A' is not assignable to type 'B'. !!! error TS2322: Property 'y' is missing in type 'A'. - o1 = { x: c, 0: a }; // string indexer is any, number indexer is A \ No newline at end of file + o1 = { x: c, 0: a }; // string indexer is any, number indexer is A + ~~ +!!! error TS2322: Type '{ 0: A; x: any; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. +!!! error TS2322: Property '0' is incompatible with index signature. +!!! error TS2322: Type 'A' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types index a49f76d02e9..b0ddd9f60d0 100644 --- a/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types +++ b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types @@ -9,7 +9,7 @@ interface I { var x: I = { >x : I >I : I ->{ p: null} : { [x: string]: null; p: null; } +>{ p: null} : { p: null; } p: null >p : null diff --git a/tests/baselines/reference/objectLiteralIndexers.types b/tests/baselines/reference/objectLiteralIndexers.types index d5add00ebaf..9e3aa4bac49 100644 --- a/tests/baselines/reference/objectLiteralIndexers.types +++ b/tests/baselines/reference/objectLiteralIndexers.types @@ -31,23 +31,23 @@ var o1: { [s: string]: A;[n: number]: B; } = { x: a, 0: b }; // string indexer i >A : A >n : number >B : B ->{ x: a, 0: b } : { [x: string]: A; [x: number]: B; 0: B; x: A; } +>{ x: a, 0: b } : { 0: B; x: A; } >x : A >a : A >b : B o1 = { x: b, 0: c }; // both indexers are any ->o1 = { x: b, 0: c } : { [x: string]: any; [x: number]: any; 0: any; x: B; } +>o1 = { x: b, 0: c } : { 0: any; x: B; } >o1 : { [s: string]: A; [n: number]: B; } ->{ x: b, 0: c } : { [x: string]: any; [x: number]: any; 0: any; x: B; } +>{ x: b, 0: c } : { 0: any; x: B; } >x : B >b : B >c : any o1 = { x: c, 0: b }; // string indexer is any, number indexer is B ->o1 = { x: c, 0: b } : { [x: string]: any; [x: number]: B; 0: B; x: any; } +>o1 = { x: c, 0: b } : { 0: B; x: any; } >o1 : { [s: string]: A; [n: number]: B; } ->{ x: c, 0: b } : { [x: string]: any; [x: number]: B; 0: B; x: any; } +>{ x: c, 0: b } : { 0: B; x: any; } >x : any >c : any >b : B diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types index 2284d06ffbd..c5de5c7b9b4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: undefined; foo: string; } +>{ foo: '' } : { foo: string; } >foo : string >'' : string diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types index 1a580297b1b..17fc6a07a00 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types @@ -64,7 +64,7 @@ var b: { [x: number]: Derived; } = { foo: null }; >b : { [x: number]: Derived; } >x : number >Derived : Derived ->{ foo: null } : { [x: number]: undefined; foo: Derived; } +>{ foo: null } : { foo: Derived; } >foo : Derived >null : Derived >Derived : Derived diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types index ae384bbb4db..99e6b8c8632 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: undefined; foo: string; } +>{ foo: '' } : { foo: string; } >foo : string >'' : string diff --git a/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types b/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types index a7eeb672504..8393eaf68a0 100644 --- a/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types +++ b/tests/baselines/reference/objectTypesIdentityWithStringIndexers.types @@ -50,7 +50,7 @@ var a: { var b: { [x: string]: string; } = { foo: '' }; >b : { [x: string]: string; } >x : string ->{ foo: '' } : { [x: string]: string; foo: string; } +>{ foo: '' } : { foo: string; } >foo : string >'' : string diff --git a/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types index d1394252117..814d0c91814 100644 --- a/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithStringIndexers2.types @@ -64,7 +64,7 @@ var b: { [x: string]: Derived; } = { foo: null }; >b : { [x: string]: Derived; } >x : string >Derived : Derived ->{ foo: null } : { [x: string]: Derived; foo: Derived; } +>{ foo: null } : { foo: Derived; } >foo : Derived >null : Derived >Derived : Derived diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.types b/tests/baselines/reference/operatorsAndIntersectionTypes.types index 70611776fc1..6b5987d3a69 100644 --- a/tests/baselines/reference/operatorsAndIntersectionTypes.types +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.types @@ -28,7 +28,7 @@ function createSerialNo() { let map1: { [x: string]: number } = {}; >map1 : { [x: string]: number; } >x : string ->{} : { [x: string]: undefined; } +>{} : {} let guid = createGuid(); >guid : string & { $Guid: any; } @@ -45,7 +45,7 @@ map1[guid] = 123; // Can with tagged string let map2: { [x: number]: string } = {}; >map2 : { [x: number]: string; } >x : number ->{} : { [x: number]: undefined; } +>{} : {} let serialNo = createSerialNo(); >serialNo : number & { $SerialNo: any; } diff --git a/tests/baselines/reference/parserConstructorDeclaration5.errors.txt b/tests/baselines/reference/parserConstructorDeclaration5.errors.txt deleted file mode 100644 index 4589ad95a32..00000000000 --- a/tests/baselines/reference/parserConstructorDeclaration5.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts(2,3): error TS1089: 'private' modifier cannot appear on a constructor declaration. - - -==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts (1 errors) ==== - class C { - private constructor() { } - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorDeclaration5.symbols b/tests/baselines/reference/parserConstructorDeclaration5.symbols new file mode 100644 index 00000000000..6eb3d32a0f0 --- /dev/null +++ b/tests/baselines/reference/parserConstructorDeclaration5.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts === +class C { +>C : Symbol(C, Decl(parserConstructorDeclaration5.ts, 0, 0)) + + private constructor() { } +} diff --git a/tests/baselines/reference/parserConstructorDeclaration5.types b/tests/baselines/reference/parserConstructorDeclaration5.types new file mode 100644 index 00000000000..ae5d2c44b49 --- /dev/null +++ b/tests/baselines/reference/parserConstructorDeclaration5.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration5.ts === +class C { +>C : C + + private constructor() { } +} diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index c35bc25fe71..666be34d10c 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -8,16 +8,15 @@ tests/cases/compiler/protectedMembers.ts(48,1): error TS2445: Property 'sx' is p tests/cases/compiler/protectedMembers.ts(49,1): error TS2445: Property 'sf' is protected and only accessible within class 'C2' and its subclasses. tests/cases/compiler/protectedMembers.ts(68,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. tests/cases/compiler/protectedMembers.ts(69,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. -tests/cases/compiler/protectedMembers.ts(86,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. -tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'B1' is not assignable to type 'A1'. +tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not assignable to type 'A1'. Property 'x' is protected but type 'B1' is not a class derived from 'A1'. -tests/cases/compiler/protectedMembers.ts(99,1): error TS2322: Type 'A1' is not assignable to type 'B1'. +tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'. Property 'x' is protected in type 'A1' but public in type 'B1'. -tests/cases/compiler/protectedMembers.ts(112,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. +tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Property 'x' is protected in type 'B3' but public in type 'A3'. -==== tests/cases/compiler/protectedMembers.ts (14 errors) ==== +==== tests/cases/compiler/protectedMembers.ts (13 errors) ==== // Class with protected members class C1 { protected x: number; @@ -122,10 +121,7 @@ tests/cases/compiler/protectedMembers.ts(112,7): error TS2415: Class 'B3' incorr } class CC { - // Error, constructor cannot be protected protected constructor() { - ~~~~~~~~~ -!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. } } diff --git a/tests/baselines/reference/protectedMembers.js b/tests/baselines/reference/protectedMembers.js index e541f697f44..dcc68e0c946 100644 --- a/tests/baselines/reference/protectedMembers.js +++ b/tests/baselines/reference/protectedMembers.js @@ -83,7 +83,6 @@ interface E extends C { } class CC { - // Error, constructor cannot be protected protected constructor() { } } @@ -214,7 +213,6 @@ var D = (function (_super) { return D; }(C)); var CC = (function () { - // Error, constructor cannot be protected function CC() { } return CC; diff --git a/tests/baselines/reference/relativeNamesInClassicResolution.errors.txt b/tests/baselines/reference/relativeNamesInClassicResolution.errors.txt new file mode 100644 index 00000000000..65a42775331 --- /dev/null +++ b/tests/baselines/reference/relativeNamesInClassicResolution.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/somefolder/a.ts(2,17): error TS2307: Cannot find module './b'. + + +==== tests/cases/compiler/somefolder/a.ts (1 errors) ==== + + import {x} from "./b" + ~~~~~ +!!! error TS2307: Cannot find module './b'. + +==== tests/cases/compiler/b.ts (0 errors) ==== + export let x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/relativeNamesInClassicResolution.js b/tests/baselines/reference/relativeNamesInClassicResolution.js new file mode 100644 index 00000000000..a6c5a06ea3d --- /dev/null +++ b/tests/baselines/reference/relativeNamesInClassicResolution.js @@ -0,0 +1,18 @@ +//// [tests/cases/compiler/relativeNamesInClassicResolution.ts] //// + +//// [a.ts] + +import {x} from "./b" + +//// [b.ts] +export let x = 1; + +//// [a.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [b.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); diff --git a/tests/baselines/reference/restElementWithNullInitializer.errors.txt b/tests/baselines/reference/restElementWithNullInitializer.errors.txt index 7beb7b9a642..4658acc5ff4 100644 --- a/tests/baselines/reference/restElementWithNullInitializer.errors.txt +++ b/tests/baselines/reference/restElementWithNullInitializer.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(1,15): error TS2461: Type 'null' is not an array type. tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(4,15): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15): error TS2461: Type '{ [x: number]: undefined; }' is not an array type. +tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15): error TS2461: Type '{}' is not an array type. ==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (3 errors) ==== @@ -16,7 +16,7 @@ tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15 function foo3([...r] = {}) { ~~~~~~ -!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type. +!!! error TS2461: Type '{}' is not an array type. } function foo4([...r] = []) { diff --git a/tests/baselines/reference/stringIndexerAssignments1.errors.txt b/tests/baselines/reference/stringIndexerAssignments1.errors.txt index 908371bc7dd..ac99b239779 100644 --- a/tests/baselines/reference/stringIndexerAssignments1.errors.txt +++ b/tests/baselines/reference/stringIndexerAssignments1.errors.txt @@ -1,18 +1,13 @@ -tests/cases/compiler/stringIndexerAssignments1.ts(4,1): error TS2322: Type '{ one: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. - Index signature is missing in type '{ one: string; }'. tests/cases/compiler/stringIndexerAssignments1.ts(5,1): error TS2322: Type '{ one: number; two: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. Types of property 'one' are incompatible. Type 'number' is not assignable to type 'string'. -==== tests/cases/compiler/stringIndexerAssignments1.ts (2 errors) ==== +==== tests/cases/compiler/stringIndexerAssignments1.ts (1 errors) ==== var x: { [index: string]: string; one: string; }; var a: { one: string; }; var b: { one: number; two: string; }; x = a; - ~ -!!! error TS2322: Type '{ one: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. -!!! error TS2322: Index signature is missing in type '{ one: string; }'. x = b; // error ~ !!! error TS2322: Type '{ one: number; two: string; }' is not assignable to type '{ [index: string]: string; one: string; }'. diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index 08881be2a86..8f4bbe2025a 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -22,10 +22,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | (() => void) | MyString; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. - Index signatures are incompatible. - Type 'string | number | (() => void) | MyString' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. + Property '2.0' is incompatible with index signature. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -158,10 +157,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: string | number | (() => void) | MyString; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'string | number | (() => void) | MyString' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. +!!! error TS2322: Property '2.0' is incompatible with index signature. +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt index faef7905453..dacfb1a522d 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. - Index signatures are incompatible. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. + Property 'a' is incompatible with index signature. Type 'typeof A' is not assignable to type 'A'. Property 'foo' is missing in type 'typeof A'. @@ -60,8 +60,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: A } = { ~ -!!! error TS2322: Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. +!!! error TS2322: Property 'a' is incompatible with index signature. !!! error TS2322: Type 'typeof A' is not assignable to type 'A'. !!! error TS2322: Property 'foo' is missing in type 'typeof A'. a: A, diff --git a/tests/baselines/reference/stringIndexingResults.types b/tests/baselines/reference/stringIndexingResults.types index 9f613312e5a..1fdc580b1a2 100644 --- a/tests/baselines/reference/stringIndexingResults.types +++ b/tests/baselines/reference/stringIndexingResults.types @@ -95,7 +95,7 @@ var r9 = a[1]; var b: { [x: string]: string } = { y: '' } >b : { [x: string]: string; } >x : string ->{ y: '' } : { [x: string]: string; y: string; } +>{ y: '' } : { y: string; } >y : string >'' : string diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.types b/tests/baselines/reference/stringLiteralCheckedInIf02.types index f91eea03097..79f4c6a223a 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf02.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.types @@ -31,7 +31,7 @@ function f(foo: T) { >T : ("a" | "b")[] | "a" | "b" if (isS(foo)) { ->isS(foo) : t is "a" | "b" +>isS(foo) : boolean >isS : (t: ("a" | "b")[] | "a" | "b") => t is "a" | "b" >foo : ("a" | "b")[] | "a" | "b" diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.types b/tests/baselines/reference/stringLiteralTypesAsTags01.types index 6966ede5482..a7f403e76ec 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.types @@ -88,7 +88,7 @@ let x: A = { } if (hasKind(x, "A")) { ->hasKind(x, "A") : entity is A +>hasKind(x, "A") : boolean >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" @@ -105,7 +105,7 @@ else { if (!hasKind(x, "B")) { >!hasKind(x, "B") : boolean ->hasKind(x, "B") : entity is B +>hasKind(x, "B") : boolean >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" diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.types b/tests/baselines/reference/stringLiteralTypesAsTags02.types index 0b8ea0faf67..edad220b086 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags02.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.types @@ -82,7 +82,7 @@ let x: A = { } if (hasKind(x, "A")) { ->hasKind(x, "A") : entity is A +>hasKind(x, "A") : boolean >hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } >x : A >"A" : "A" @@ -99,7 +99,7 @@ else { if (!hasKind(x, "B")) { >!hasKind(x, "B") : boolean ->hasKind(x, "B") : entity is B +>hasKind(x, "B") : boolean >hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } >x : A >"B" : "B" diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.types b/tests/baselines/reference/stringLiteralTypesAsTags03.types index a1d83a1c058..25816659388 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags03.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.types @@ -85,7 +85,7 @@ let x: A = { } if (hasKind(x, "A")) { ->hasKind(x, "A") : entity is A +>hasKind(x, "A") : boolean >hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } >x : A >"A" : "A" @@ -102,7 +102,7 @@ else { if (!hasKind(x, "B")) { >!hasKind(x, "B") : boolean ->hasKind(x, "B") : entity is B +>hasKind(x, "B") : boolean >hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } >x : A >"B" : "B" diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types index 43c8271b76b..41da80afd30 100644 --- a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types @@ -36,7 +36,7 @@ var x: Kind = "A"; >"A" : "A" if (kindIs(x, "A")) { ->kindIs(x, "A") : kind is "A" +>kindIs(x, "A") : boolean >kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } >x : "A" | "B" >"A" : "A" @@ -53,7 +53,7 @@ else { if (!kindIs(x, "B")) { >!kindIs(x, "B") : boolean ->kindIs(x, "B") : kind is "B" +>kindIs(x, "B") : boolean >kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } >x : "A" | "B" >"B" : "B" diff --git a/tests/baselines/reference/superCallBeforeThisAccessing1.js b/tests/baselines/reference/superCallBeforeThisAccessing1.js new file mode 100644 index 00000000000..1fc7ab39c91 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing1.js @@ -0,0 +1,40 @@ +//// [superCallBeforeThisAccessing1.ts] +declare var Factory: any + +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + super(i); + var s = { + t: this._t + } + var i = Factory.create(s); + } +} + + +//// [superCallBeforeThisAccessing1.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 Base = (function () { + function Base(c) { + } + return Base; +}()); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.call(this, i); + var s = { + t: this._t + }; + var i = Factory.create(s); + } + return D; +}(Base)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing1.symbols b/tests/baselines/reference/superCallBeforeThisAccessing1.symbols new file mode 100644 index 00000000000..5a153728a73 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing1.symbols @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing1.ts === +declare var Factory: any +>Factory : Symbol(Factory, Decl(superCallBeforeThisAccessing1.ts, 0, 11)) + +class Base { +>Base : Symbol(Base, Decl(superCallBeforeThisAccessing1.ts, 0, 24)) + + constructor(c) { } +>c : Symbol(c, Decl(superCallBeforeThisAccessing1.ts, 3, 16)) +} +class D extends Base { +>D : Symbol(D, Decl(superCallBeforeThisAccessing1.ts, 4, 1)) +>Base : Symbol(Base, Decl(superCallBeforeThisAccessing1.ts, 0, 24)) + + private _t; +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing1.ts, 5, 22)) + + constructor() { + super(i); +>super : Symbol(Base, Decl(superCallBeforeThisAccessing1.ts, 0, 24)) +>i : Symbol(i, Decl(superCallBeforeThisAccessing1.ts, 12, 11)) + + var s = { +>s : Symbol(s, Decl(superCallBeforeThisAccessing1.ts, 9, 11)) + + t: this._t +>t : Symbol(t, Decl(superCallBeforeThisAccessing1.ts, 9, 17)) +>this._t : Symbol(_t, Decl(superCallBeforeThisAccessing1.ts, 5, 22)) +>this : Symbol(D, Decl(superCallBeforeThisAccessing1.ts, 4, 1)) +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing1.ts, 5, 22)) + } + var i = Factory.create(s); +>i : Symbol(i, Decl(superCallBeforeThisAccessing1.ts, 12, 11)) +>Factory : Symbol(Factory, Decl(superCallBeforeThisAccessing1.ts, 0, 11)) +>s : Symbol(s, Decl(superCallBeforeThisAccessing1.ts, 9, 11)) + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing1.types b/tests/baselines/reference/superCallBeforeThisAccessing1.types new file mode 100644 index 00000000000..e947653584a --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing1.types @@ -0,0 +1,43 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing1.ts === +declare var Factory: any +>Factory : any + +class Base { +>Base : Base + + constructor(c) { } +>c : any +} +class D extends Base { +>D : D +>Base : Base + + private _t; +>_t : any + + constructor() { + super(i); +>super(i) : void +>super : typeof Base +>i : any + + var s = { +>s : { t: any; } +>{ t: this._t } : { t: any; } + + t: this._t +>t : any +>this._t : any +>this : this +>_t : any + } + var i = Factory.create(s); +>i : any +>Factory.create(s) : any +>Factory.create : any +>Factory : any +>create : any +>s : { t: any; } + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing2.js b/tests/baselines/reference/superCallBeforeThisAccessing2.js new file mode 100644 index 00000000000..e5acf06bbfd --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing2.js @@ -0,0 +1,31 @@ +//// [superCallBeforeThisAccessing2.ts] +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + super(() => { this._t }); // no error. only check when this is directly accessing in constructor + } +} + + +//// [superCallBeforeThisAccessing2.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 Base = (function () { + function Base(c) { + } + return Base; +}()); +var D = (function (_super) { + __extends(D, _super); + function D() { + var _this = this; + _super.call(this, function () { _this._t; }); // no error. only check when this is directly accessing in constructor + } + return D; +}(Base)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing2.symbols b/tests/baselines/reference/superCallBeforeThisAccessing2.symbols new file mode 100644 index 00000000000..2df2e62354a --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing2.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing2.ts === +class Base { +>Base : Symbol(Base, Decl(superCallBeforeThisAccessing2.ts, 0, 0)) + + constructor(c) { } +>c : Symbol(c, Decl(superCallBeforeThisAccessing2.ts, 1, 16)) +} +class D extends Base { +>D : Symbol(D, Decl(superCallBeforeThisAccessing2.ts, 2, 1)) +>Base : Symbol(Base, Decl(superCallBeforeThisAccessing2.ts, 0, 0)) + + private _t; +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing2.ts, 3, 22)) + + constructor() { + super(() => { this._t }); // no error. only check when this is directly accessing in constructor +>super : Symbol(Base, Decl(superCallBeforeThisAccessing2.ts, 0, 0)) +>this._t : Symbol(_t, Decl(superCallBeforeThisAccessing2.ts, 3, 22)) +>this : Symbol(D, Decl(superCallBeforeThisAccessing2.ts, 2, 1)) +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing2.ts, 3, 22)) + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing2.types b/tests/baselines/reference/superCallBeforeThisAccessing2.types new file mode 100644 index 00000000000..cf0f54b6246 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing2.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing2.ts === +class Base { +>Base : Base + + constructor(c) { } +>c : any +} +class D extends Base { +>D : D +>Base : Base + + private _t; +>_t : any + + constructor() { + super(() => { this._t }); // no error. only check when this is directly accessing in constructor +>super(() => { this._t }) : void +>super : typeof Base +>() => { this._t } : () => void +>this._t : any +>this : this +>_t : any + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing3.errors.txt b/tests/baselines/reference/superCallBeforeThisAccessing3.errors.txt new file mode 100644 index 00000000000..90b9b034263 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing3.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing3.ts(9,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing3.ts (1 errors) ==== + class Base { + constructor(c) { } + } + class D extends Base { + private _t; + constructor() { + let x = () => { this._t }; + x(); // no error; we only check super is called before this when the container is a constructor + this._t; // error + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(undefined); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/superCallBeforeThisAccessing3.js b/tests/baselines/reference/superCallBeforeThisAccessing3.js new file mode 100644 index 00000000000..101d74e4bc7 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing3.js @@ -0,0 +1,37 @@ +//// [superCallBeforeThisAccessing3.ts] +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + let x = () => { this._t }; + x(); // no error; we only check super is called before this when the container is a constructor + this._t; // error + super(undefined); + } +} + + +//// [superCallBeforeThisAccessing3.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 Base = (function () { + function Base(c) { + } + return Base; +}()); +var D = (function (_super) { + __extends(D, _super); + function D() { + var _this = this; + var x = function () { _this._t; }; + x(); // no error; we only check super is called before this when the container is a constructor + this._t; // error + _super.call(this, undefined); + } + return D; +}(Base)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt b/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt new file mode 100644 index 00000000000..91c3e7763f6 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing4.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(5,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(12,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + + +==== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts (2 errors) ==== + class D extends null { + private _t; + constructor() { + this._t; + super(); + ~~~~~~~ +!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + } + } + + class E extends null { + private _t; + constructor() { + super(); + ~~~~~~~ +!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + this._t; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallBeforeThisAccessing4.js b/tests/baselines/reference/superCallBeforeThisAccessing4.js new file mode 100644 index 00000000000..9c3c5ab60c4 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing4.js @@ -0,0 +1,39 @@ +//// [superCallBeforeThisAccessing4.ts] +class D extends null { + private _t; + constructor() { + this._t; + super(); + } +} + +class E extends null { + private _t; + constructor() { + super(); + this._t; + } +} + +//// [superCallBeforeThisAccessing4.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 D = (function (_super) { + __extends(D, _super); + function D() { + this._t; + _super.call(this); + } + return D; +}(null)); +var E = (function (_super) { + __extends(E, _super); + function E() { + _super.call(this); + this._t; + } + return E; +}(null)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing5.js b/tests/baselines/reference/superCallBeforeThisAccessing5.js new file mode 100644 index 00000000000..3281a3f8b55 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing5.js @@ -0,0 +1,22 @@ +//// [superCallBeforeThisAccessing5.ts] +class D extends null { + private _t; + constructor() { + this._t; // No error + } +} + + +//// [superCallBeforeThisAccessing5.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 D = (function (_super) { + __extends(D, _super); + function D() { + this._t; // No error + } + return D; +}(null)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing5.symbols b/tests/baselines/reference/superCallBeforeThisAccessing5.symbols new file mode 100644 index 00000000000..a7628e3b8df --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing5.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing5.ts === +class D extends null { +>D : Symbol(D, Decl(superCallBeforeThisAccessing5.ts, 0, 0)) + + private _t; +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing5.ts, 0, 22)) + + constructor() { + this._t; // No error +>this._t : Symbol(_t, Decl(superCallBeforeThisAccessing5.ts, 0, 22)) +>this : Symbol(D, Decl(superCallBeforeThisAccessing5.ts, 0, 0)) +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing5.ts, 0, 22)) + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing5.types b/tests/baselines/reference/superCallBeforeThisAccessing5.types new file mode 100644 index 00000000000..2c0fc33c4dc --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing5.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing5.ts === +class D extends null { +>D : D +>null : null + + private _t; +>_t : any + + constructor() { + this._t; // No error +>this._t : any +>this : this +>_t : any + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing6.errors.txt b/tests/baselines/reference/superCallBeforeThisAccessing6.errors.txt new file mode 100644 index 00000000000..346b2d58bec --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing6.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing6.ts(7,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing6.ts (1 errors) ==== + class Base { + constructor(c) { } + } + class D extends Base { + private _t; + constructor() { + super(this); + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/superCallBeforeThisAccessing6.js b/tests/baselines/reference/superCallBeforeThisAccessing6.js new file mode 100644 index 00000000000..746ce9f2791 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing6.js @@ -0,0 +1,30 @@ +//// [superCallBeforeThisAccessing6.ts] +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + super(this); + } +} + + +//// [superCallBeforeThisAccessing6.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 Base = (function () { + function Base(c) { + } + return Base; +}()); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.call(this, this); + } + return D; +}(Base)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing7.errors.txt b/tests/baselines/reference/superCallBeforeThisAccessing7.errors.txt new file mode 100644 index 00000000000..4e374fd96ea --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing7.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing7.ts(8,16): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing7.ts (1 errors) ==== + class Base { + constructor(c) { } + } + class D extends Base { + private _t; + constructor() { + let x = { + j: this._t, + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + } + super(undefined); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/superCallBeforeThisAccessing7.js b/tests/baselines/reference/superCallBeforeThisAccessing7.js new file mode 100644 index 00000000000..c3aa1655cf7 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing7.js @@ -0,0 +1,36 @@ +//// [superCallBeforeThisAccessing7.ts] +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + let x = { + j: this._t, + } + super(undefined); + } +} + + +//// [superCallBeforeThisAccessing7.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 Base = (function () { + function Base(c) { + } + return Base; +}()); +var D = (function (_super) { + __extends(D, _super); + function D() { + var x = { + j: this._t + }; + _super.call(this, undefined); + } + return D; +}(Base)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing8.js b/tests/baselines/reference/superCallBeforeThisAccessing8.js new file mode 100644 index 00000000000..0865c4305a5 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing8.js @@ -0,0 +1,36 @@ +//// [superCallBeforeThisAccessing8.ts] +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + let x = { + k: super(undefined), + j: this._t, // no error + } + } +} + + +//// [superCallBeforeThisAccessing8.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 Base = (function () { + function Base(c) { + } + return Base; +}()); +var D = (function (_super) { + __extends(D, _super); + function D() { + var x = { + k: _super.call(this, undefined), + j: this._t + }; + } + return D; +}(Base)); diff --git a/tests/baselines/reference/superCallBeforeThisAccessing8.symbols b/tests/baselines/reference/superCallBeforeThisAccessing8.symbols new file mode 100644 index 00000000000..65341ee9fe3 --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing8.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing8.ts === +class Base { +>Base : Symbol(Base, Decl(superCallBeforeThisAccessing8.ts, 0, 0)) + + constructor(c) { } +>c : Symbol(c, Decl(superCallBeforeThisAccessing8.ts, 1, 16)) +} +class D extends Base { +>D : Symbol(D, Decl(superCallBeforeThisAccessing8.ts, 2, 1)) +>Base : Symbol(Base, Decl(superCallBeforeThisAccessing8.ts, 0, 0)) + + private _t; +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing8.ts, 3, 22)) + + constructor() { + let x = { +>x : Symbol(x, Decl(superCallBeforeThisAccessing8.ts, 6, 11)) + + k: super(undefined), +>k : Symbol(k, Decl(superCallBeforeThisAccessing8.ts, 6, 17)) +>super : Symbol(Base, Decl(superCallBeforeThisAccessing8.ts, 0, 0)) +>undefined : Symbol(undefined) + + j: this._t, // no error +>j : Symbol(j, Decl(superCallBeforeThisAccessing8.ts, 7, 32)) +>this._t : Symbol(_t, Decl(superCallBeforeThisAccessing8.ts, 3, 22)) +>this : Symbol(D, Decl(superCallBeforeThisAccessing8.ts, 2, 1)) +>_t : Symbol(_t, Decl(superCallBeforeThisAccessing8.ts, 3, 22)) + } + } +} + diff --git a/tests/baselines/reference/superCallBeforeThisAccessing8.types b/tests/baselines/reference/superCallBeforeThisAccessing8.types new file mode 100644 index 00000000000..dd92d924ceb --- /dev/null +++ b/tests/baselines/reference/superCallBeforeThisAccessing8.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing8.ts === +class Base { +>Base : Base + + constructor(c) { } +>c : any +} +class D extends Base { +>D : D +>Base : Base + + private _t; +>_t : any + + constructor() { + let x = { +>x : { k: void; j: any; } +>{ k: super(undefined), j: this._t, // no error } : { k: void; j: any; } + + k: super(undefined), +>k : void +>super(undefined) : void +>super : typeof Base +>undefined : undefined + + j: this._t, // no error +>j : any +>this._t : any +>this : this +>_t : any + } + } +} + diff --git a/tests/baselines/reference/symbolProperty1.types b/tests/baselines/reference/symbolProperty1.types index f39d98853d2..667e51fda8a 100644 --- a/tests/baselines/reference/symbolProperty1.types +++ b/tests/baselines/reference/symbolProperty1.types @@ -3,8 +3,8 @@ var s: symbol; >s : symbol var x = { ->x : {} ->{ [s]: 0, [s]() { }, get [s]() { return 0; }} : {} +>x : { [x: string]: number | (() => void); } +>{ [s]: 0, [s]() { }, get [s]() { return 0; }} : { [x: string]: number | (() => void); } [s]: 0, >s : symbol diff --git a/tests/baselines/reference/symbolProperty2.types b/tests/baselines/reference/symbolProperty2.types index df49130520a..7584c6461e8 100644 --- a/tests/baselines/reference/symbolProperty2.types +++ b/tests/baselines/reference/symbolProperty2.types @@ -5,8 +5,8 @@ var s = Symbol(); >Symbol : SymbolConstructor var x = { ->x : {} ->{ [s]: 0, [s]() { }, get [s]() { return 0; }} : {} +>x : { [x: string]: number | (() => void); } +>{ [s]: 0, [s]() { }, get [s]() { return 0; }} : { [x: string]: number | (() => void); } [s]: 0, >s : symbol diff --git a/tests/baselines/reference/symbolProperty4.types b/tests/baselines/reference/symbolProperty4.types index 93b4417b8ae..7bcf3f23397 100644 --- a/tests/baselines/reference/symbolProperty4.types +++ b/tests/baselines/reference/symbolProperty4.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/Symbols/symbolProperty4.ts === var x = { ->x : {} ->{ [Symbol()]: 0, [Symbol()]() { }, get [Symbol()]() { return 0; }} : {} +>x : { [x: string]: number | (() => void); } +>{ [Symbol()]: 0, [Symbol()]() { }, get [Symbol()]() { return 0; }} : { [x: string]: number | (() => void); } [Symbol()]: 0, >Symbol() : symbol diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index e6910840d39..94ab5028647 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{ [x: number]: undefined; }'. +tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{}'. ==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2 f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{}'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt index e8bf38c1048..1201c82f4d0 100644 --- a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{ [x: number]: undefined; }'. +tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{}'. ==== tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{}'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index ac30556a235..f410d408482 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{ [x: number]: undefined; }'. +tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{}'. ==== tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error T f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{}'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardFunction.types b/tests/baselines/reference/typeGuardFunction.types index 9bab1e7ca2c..50a5fcaf324 100644 --- a/tests/baselines/reference/typeGuardFunction.types +++ b/tests/baselines/reference/typeGuardFunction.types @@ -54,7 +54,7 @@ var b: B; // Basic if (isC(a)) { ->isC(a) : p1 is C +>isC(a) : boolean >isC : (p1: any) => p1 is C >a : A @@ -70,7 +70,7 @@ var subType: C; >C : C if(isA(subType)) { ->isA(subType) : p1 is A +>isA(subType) : boolean >isA : (p1: any) => p1 is A >subType : C @@ -87,7 +87,7 @@ var union: A | B; >B : B if(isA(union)) { ->isA(union) : p1 is A +>isA(union) : boolean >isA : (p1: any) => p1 is A >union : A | B @@ -118,7 +118,7 @@ declare function isC_multipleParams(p1, p2): p1 is C; >C : C if (isC_multipleParams(a, 0)) { ->isC_multipleParams(a, 0) : p1 is C +>isC_multipleParams(a, 0) : boolean >isC_multipleParams : (p1: any, p2: any) => p1 is C >a : A >0 : number @@ -197,7 +197,7 @@ declare function acceptingBoolean(a: boolean); acceptingBoolean(isA(a)); >acceptingBoolean(isA(a)) : any >acceptingBoolean : (a: boolean) => any ->isA(a) : p1 is A +>isA(a) : boolean >isA : (p1: any) => p1 is A >a : A @@ -223,8 +223,8 @@ let union2: C | B; let union3: boolean | B = isA(union2) || union2; >union3 : boolean | B >B : B ->isA(union2) || union2 : p1 is A | B ->isA(union2) : p1 is A +>isA(union2) || union2 : boolean | B +>isA(union2) : boolean >isA : (p1: any) => p1 is A >union2 : C | B >union2 : B diff --git a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt index 9ecad007672..8e4bf651518 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt +++ b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(2,7): error TS2300: Duplicate identifier 'A'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(15,12): error TS2322: Type 'string' is not assignable to type 'x is A'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(15,12): error TS2322: Type 'string' is not assignable to type 'boolean'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,55): error TS2304: Cannot find name 'x'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,57): error TS1144: '{' or ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(18,57): error TS2304: Cannot find name 'is'. @@ -43,9 +43,13 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,22) tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,22): error TS2304: Cannot find name 'is'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,25): error TS1005: ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,27): error TS1005: ';' expected. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(104,25): error TS1228: A type predicate is only allowed in return type position for functions and methods. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(105,16): error TS2322: Type 'boolean' is not assignable to type 'D'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(105,16): error TS2409: Return type of constructor signature must be assignable to the instance type of the class +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(107,20): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(110,20): error TS1228: A type predicate is only allowed in return type position for functions and methods. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(111,16): error TS2408: Setters cannot return a value. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(116,18): error TS1228: A type predicate is only allowed in return type position for functions and methods. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,22): error TS2304: Cannot find name 'p1'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,25): error TS1005: ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(120,25): error TS2304: Cannot find name 'is'. @@ -57,7 +61,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(133,34 tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39): error TS1230: A type predicate cannot reference element 'p1' in a binding pattern. -==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (50 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts (54 errors) ==== class A { ~ @@ -76,7 +80,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 function hasANonBooleanReturnStatement(x): x is A { return ''; ~~ -!!! error TS2322: Type 'string' is not assignable to type 'x is A'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. } function hasTypeGuardTypeInsideTypeGuardType(x): x is x is A { @@ -245,6 +249,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 // Non-compatiable type predicate positions for signature declarations class D { constructor(p1: A): p1 is C { + ~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; ~~~~ !!! error TS2322: Type 'boolean' is not assignable to type 'D'. @@ -252,9 +258,13 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 !!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class } get m1(p1: A): p1 is C { + ~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; } set m2(p1: A): p1 is C { + ~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return true; ~~~~ !!! error TS2408: Setters cannot return a value. @@ -263,6 +273,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 interface I1 { new (p1: A): p1 is C; + ~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. } interface I2 { diff --git a/tests/baselines/reference/typeGuardFunctionGenerics.types b/tests/baselines/reference/typeGuardFunctionGenerics.types index 1f2ad2b69be..c4655e71f0c 100644 --- a/tests/baselines/reference/typeGuardFunctionGenerics.types +++ b/tests/baselines/reference/typeGuardFunctionGenerics.types @@ -100,7 +100,7 @@ let test1: boolean = funA(isB); >isB : (p1: any) => p1 is B if (funB(retC, a)) { ->funB(retC, a) : p2 is C +>funB(retC, a) : boolean >funB : (p1: (p1: any) => T, p2: any) => p2 is T >retC : (x: any) => C >a : A @@ -118,7 +118,7 @@ let test2: B = funC(isB); >isB : (p1: any) => p1 is B if (funD(isC, a)) { ->funD(isC, a) : p2 is C +>funD(isC, a) : boolean >funD : (p1: (p1: any) => p1 is T, p2: any) => p2 is T >isC : (p1: any) => p1 is C >a : A diff --git a/tests/baselines/reference/typeGuardFunctionOfFormThis.types b/tests/baselines/reference/typeGuardFunctionOfFormThis.types index e91c77dd07a..6b21fea3457 100644 --- a/tests/baselines/reference/typeGuardFunctionOfFormThis.types +++ b/tests/baselines/reference/typeGuardFunctionOfFormThis.types @@ -45,7 +45,7 @@ let a: RoyalGuard = new FollowerGuard(); >FollowerGuard : typeof FollowerGuard if (a.isLeader()) { ->a.isLeader() : this is LeadGuard +>a.isLeader() : boolean >a.isLeader : () => this is LeadGuard >a : RoyalGuard >isLeader : () => this is LeadGuard @@ -57,7 +57,7 @@ if (a.isLeader()) { >lead : () => void } else if (a.isFollower()) { ->a.isFollower() : this is FollowerGuard +>a.isFollower() : boolean >a.isFollower : () => this is FollowerGuard >a : RoyalGuard >isFollower : () => this is FollowerGuard @@ -78,7 +78,7 @@ let b: GuardInterface; >GuardInterface : GuardInterface if (b.isLeader()) { ->b.isLeader() : this is LeadGuard +>b.isLeader() : boolean >b.isLeader : () => this is LeadGuard >b : GuardInterface >isLeader : () => this is LeadGuard @@ -90,7 +90,7 @@ if (b.isLeader()) { >lead : () => void } else if (b.isFollower()) { ->b.isFollower() : this is FollowerGuard +>b.isFollower() : boolean >b.isFollower : () => this is FollowerGuard >b : GuardInterface >isFollower : () => this is FollowerGuard @@ -103,8 +103,8 @@ else if (b.isFollower()) { } if (((a.isLeader)())) { ->((a.isLeader)()) : this is LeadGuard ->(a.isLeader)() : this is LeadGuard +>((a.isLeader)()) : boolean +>(a.isLeader)() : boolean >(a.isLeader) : () => this is LeadGuard >a.isLeader : () => this is LeadGuard >a : RoyalGuard @@ -117,8 +117,8 @@ if (((a.isLeader)())) { >lead : () => void } else if (((a).isFollower())) { ->((a).isFollower()) : this is FollowerGuard ->(a).isFollower() : this is FollowerGuard +>((a).isFollower()) : boolean +>(a).isFollower() : boolean >(a).isFollower : () => this is FollowerGuard >(a) : RoyalGuard >a : RoyalGuard @@ -132,8 +132,8 @@ else if (((a).isFollower())) { } if (((a["isLeader"])())) { ->((a["isLeader"])()) : this is LeadGuard ->(a["isLeader"])() : this is LeadGuard +>((a["isLeader"])()) : boolean +>(a["isLeader"])() : boolean >(a["isLeader"]) : () => this is LeadGuard >a["isLeader"] : () => this is LeadGuard >a : RoyalGuard @@ -146,8 +146,8 @@ if (((a["isLeader"])())) { >lead : () => void } else if (((a)["isFollower"]())) { ->((a)["isFollower"]()) : this is FollowerGuard ->(a)["isFollower"]() : this is FollowerGuard +>((a)["isFollower"]()) : boolean +>(a)["isFollower"]() : boolean >(a)["isFollower"] : () => this is FollowerGuard >(a) : RoyalGuard >a : RoyalGuard @@ -166,7 +166,7 @@ var holder2 = {a}; >a : RoyalGuard if (holder2.a.isLeader()) { ->holder2.a.isLeader() : this is LeadGuard +>holder2.a.isLeader() : boolean >holder2.a.isLeader : () => this is LeadGuard >holder2.a : RoyalGuard >holder2 : { a: RoyalGuard; } @@ -232,7 +232,7 @@ let guard = new ArrowGuard(); >ArrowGuard : typeof ArrowGuard if (guard.isElite()) { ->guard.isElite() : this is ArrowElite +>guard.isElite() : boolean >guard.isElite : () => this is ArrowElite >guard : ArrowGuard >isElite : () => this is ArrowElite @@ -244,7 +244,7 @@ if (guard.isElite()) { >defend : () => void } else if (guard.isMedic()) { ->guard.isMedic() : this is ArrowMedic +>guard.isMedic() : boolean >guard.isMedic : () => this is ArrowMedic >guard : ArrowGuard >isMedic : () => this is ArrowMedic @@ -297,7 +297,7 @@ let crate: Crate<{}>; >Crate : Crate if (crate.isSundries()) { ->crate.isSundries() : this is Crate +>crate.isSundries() : boolean >crate.isSundries : () => this is Crate >crate : Crate<{}> >isSundries : () => this is Crate @@ -312,7 +312,7 @@ if (crate.isSundries()) { >true : boolean } else if (crate.isSupplies()) { ->crate.isSupplies() : this is Crate +>crate.isSupplies() : boolean >crate.isSupplies : () => this is Crate >crate : Crate<{}> >isSupplies : () => this is Crate @@ -405,7 +405,7 @@ a.isFollower = mimic.isFollower; >isFollower : () => this is MimicFollower if (mimic.isFollower()) { ->mimic.isFollower() : this is MimicFollower +>mimic.isFollower() : boolean >mimic.isFollower : () => this is MimicFollower >mimic : MimicGuard >isFollower : () => this is MimicFollower diff --git a/tests/baselines/reference/typeGuardOfFormFunctionEquality.js b/tests/baselines/reference/typeGuardOfFormFunctionEquality.js new file mode 100644 index 00000000000..c15c1a739a9 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormFunctionEquality.js @@ -0,0 +1,26 @@ +//// [typeGuardOfFormFunctionEquality.ts] +declare function isString1(a: number, b: Object): b is string; + +declare function isString2(a: Object): a is string; + +switch (isString1(0, "")) { + case isString2(""): + default: +} + +var x = isString1(0, "") === isString2(""); + +function isString3(a: number, b: number, c: Object): c is string { + return isString1(0, c); +} + + +//// [typeGuardOfFormFunctionEquality.js] +switch (isString1(0, "")) { + case isString2(""): + default: +} +var x = isString1(0, "") === isString2(""); +function isString3(a, b, c) { + return isString1(0, c); +} diff --git a/tests/baselines/reference/typeGuardOfFormFunctionEquality.symbols b/tests/baselines/reference/typeGuardOfFormFunctionEquality.symbols new file mode 100644 index 00000000000..f1384050176 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormFunctionEquality.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormFunctionEquality.ts === +declare function isString1(a: number, b: Object): b is string; +>isString1 : Symbol(isString1, Decl(typeGuardOfFormFunctionEquality.ts, 0, 0)) +>a : Symbol(a, Decl(typeGuardOfFormFunctionEquality.ts, 0, 27)) +>b : Symbol(b, Decl(typeGuardOfFormFunctionEquality.ts, 0, 37)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(typeGuardOfFormFunctionEquality.ts, 0, 37)) + +declare function isString2(a: Object): a is string; +>isString2 : Symbol(isString2, Decl(typeGuardOfFormFunctionEquality.ts, 0, 62)) +>a : Symbol(a, Decl(typeGuardOfFormFunctionEquality.ts, 2, 27)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(typeGuardOfFormFunctionEquality.ts, 2, 27)) + +switch (isString1(0, "")) { +>isString1 : Symbol(isString1, Decl(typeGuardOfFormFunctionEquality.ts, 0, 0)) + + case isString2(""): +>isString2 : Symbol(isString2, Decl(typeGuardOfFormFunctionEquality.ts, 0, 62)) + + default: +} + +var x = isString1(0, "") === isString2(""); +>x : Symbol(x, Decl(typeGuardOfFormFunctionEquality.ts, 9, 3)) +>isString1 : Symbol(isString1, Decl(typeGuardOfFormFunctionEquality.ts, 0, 0)) +>isString2 : Symbol(isString2, Decl(typeGuardOfFormFunctionEquality.ts, 0, 62)) + +function isString3(a: number, b: number, c: Object): c is string { +>isString3 : Symbol(isString3, Decl(typeGuardOfFormFunctionEquality.ts, 9, 43)) +>a : Symbol(a, Decl(typeGuardOfFormFunctionEquality.ts, 11, 19)) +>b : Symbol(b, Decl(typeGuardOfFormFunctionEquality.ts, 11, 29)) +>c : Symbol(c, Decl(typeGuardOfFormFunctionEquality.ts, 11, 40)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>c : Symbol(c, Decl(typeGuardOfFormFunctionEquality.ts, 11, 40)) + + return isString1(0, c); +>isString1 : Symbol(isString1, Decl(typeGuardOfFormFunctionEquality.ts, 0, 0)) +>c : Symbol(c, Decl(typeGuardOfFormFunctionEquality.ts, 11, 40)) +} + diff --git a/tests/baselines/reference/typeGuardOfFormFunctionEquality.types b/tests/baselines/reference/typeGuardOfFormFunctionEquality.types new file mode 100644 index 00000000000..55f2e2aac0e --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormFunctionEquality.types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormFunctionEquality.ts === +declare function isString1(a: number, b: Object): b is string; +>isString1 : (a: number, b: Object) => b is string +>a : number +>b : Object +>Object : Object +>b : any + +declare function isString2(a: Object): a is string; +>isString2 : (a: Object) => a is string +>a : Object +>Object : Object +>a : any + +switch (isString1(0, "")) { +>isString1(0, "") : boolean +>isString1 : (a: number, b: Object) => b is string +>0 : number +>"" : string + + case isString2(""): +>isString2("") : boolean +>isString2 : (a: Object) => a is string +>"" : string + + default: +} + +var x = isString1(0, "") === isString2(""); +>x : boolean +>isString1(0, "") === isString2("") : boolean +>isString1(0, "") : boolean +>isString1 : (a: number, b: Object) => b is string +>0 : number +>"" : string +>isString2("") : boolean +>isString2 : (a: Object) => a is string +>"" : string + +function isString3(a: number, b: number, c: Object): c is string { +>isString3 : (a: number, b: number, c: Object) => c is string +>a : number +>b : number +>c : Object +>Object : Object +>c : any + + return isString1(0, c); +>isString1(0, c) : boolean +>isString1 : (a: number, b: Object) => b is string +>0 : number +>c : Object +} + diff --git a/tests/baselines/reference/typeGuardOfFormIsType.types b/tests/baselines/reference/typeGuardOfFormIsType.types index aa8f8cc7d60..e2059be7b63 100644 --- a/tests/baselines/reference/typeGuardOfFormIsType.types +++ b/tests/baselines/reference/typeGuardOfFormIsType.types @@ -67,7 +67,7 @@ str = isC1(c1Orc2) && c1Orc2.p1; // C1 >str = isC1(c1Orc2) && c1Orc2.p1 : string >str : string >isC1(c1Orc2) && c1Orc2.p1 : string ->isC1(c1Orc2) : x is C1 +>isC1(c1Orc2) : boolean >isC1 : (x: any) => x is C1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string @@ -78,7 +78,7 @@ num = isC2(c1Orc2) && c1Orc2.p2; // C2 >num = isC2(c1Orc2) && c1Orc2.p2 : number >num : number >isC2(c1Orc2) && c1Orc2.p2 : number ->isC2(c1Orc2) : x is C2 +>isC2(c1Orc2) : boolean >isC2 : (x: any) => x is C2 >c1Orc2 : C1 | C2 >c1Orc2.p2 : number @@ -89,7 +89,7 @@ str = isD1(c1Orc2) && c1Orc2.p1; // D1 >str = isD1(c1Orc2) && c1Orc2.p1 : string >str : string >isD1(c1Orc2) && c1Orc2.p1 : string ->isD1(c1Orc2) : x is D1 +>isD1(c1Orc2) : boolean >isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string @@ -100,7 +100,7 @@ num = isD1(c1Orc2) && c1Orc2.p3; // D1 >num = isD1(c1Orc2) && c1Orc2.p3 : number >num : number >isD1(c1Orc2) && c1Orc2.p3 : number ->isD1(c1Orc2) : x is D1 +>isD1(c1Orc2) : boolean >isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p3 : number @@ -116,7 +116,7 @@ num = isC2(c2Ord1) && c2Ord1.p2; // C2 >num = isC2(c2Ord1) && c2Ord1.p2 : number >num : number >isC2(c2Ord1) && c2Ord1.p2 : number ->isC2(c2Ord1) : x is C2 +>isC2(c2Ord1) : boolean >isC2 : (x: any) => x is C2 >c2Ord1 : C2 | D1 >c2Ord1.p2 : number @@ -127,7 +127,7 @@ num = isD1(c2Ord1) && c2Ord1.p3; // D1 >num = isD1(c2Ord1) && c2Ord1.p3 : number >num : number >isD1(c2Ord1) && c2Ord1.p3 : number ->isD1(c2Ord1) : x is D1 +>isD1(c2Ord1) : boolean >isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p3 : number @@ -138,7 +138,7 @@ str = isD1(c2Ord1) && c2Ord1.p1; // D1 >str = isD1(c2Ord1) && c2Ord1.p1 : string >str : string >isD1(c2Ord1) && c2Ord1.p1 : string ->isD1(c2Ord1) : x is D1 +>isD1(c2Ord1) : boolean >isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p1 : string @@ -150,7 +150,7 @@ var r2: C2 | D1 = isC1(c2Ord1) && c2Ord1; // C2 | D1 >C2 : C2 >D1 : D1 >isC1(c2Ord1) && c2Ord1 : D1 ->isC1(c2Ord1) : x is C1 +>isC1(c2Ord1) : boolean >isC1 : (x: any) => x is C1 >c2Ord1 : C2 | D1 >c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types index 4e28e6a4d38..ea169e95413 100644 --- a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types +++ b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types @@ -98,7 +98,7 @@ str = isC1(c1Orc2) && c1Orc2.p1; // C1 >str = isC1(c1Orc2) && c1Orc2.p1 : string >str : string >isC1(c1Orc2) && c1Orc2.p1 : string ->isC1(c1Orc2) : x is C1 +>isC1(c1Orc2) : boolean >isC1 : (x: any) => x is C1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string @@ -109,7 +109,7 @@ num = isC2(c1Orc2) && c1Orc2.p2; // C2 >num = isC2(c1Orc2) && c1Orc2.p2 : number >num : number >isC2(c1Orc2) && c1Orc2.p2 : number ->isC2(c1Orc2) : x is C2 +>isC2(c1Orc2) : boolean >isC2 : (x: any) => x is C2 >c1Orc2 : C1 | C2 >c1Orc2.p2 : number @@ -120,7 +120,7 @@ str = isD1(c1Orc2) && c1Orc2.p1; // D1 >str = isD1(c1Orc2) && c1Orc2.p1 : string >str : string >isD1(c1Orc2) && c1Orc2.p1 : string ->isD1(c1Orc2) : x is D1 +>isD1(c1Orc2) : boolean >isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string @@ -131,7 +131,7 @@ num = isD1(c1Orc2) && c1Orc2.p3; // D1 >num = isD1(c1Orc2) && c1Orc2.p3 : number >num : number >isD1(c1Orc2) && c1Orc2.p3 : number ->isD1(c1Orc2) : x is D1 +>isD1(c1Orc2) : boolean >isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p3 : number @@ -147,7 +147,7 @@ num = isC2(c2Ord1) && c2Ord1.p2; // C2 >num = isC2(c2Ord1) && c2Ord1.p2 : number >num : number >isC2(c2Ord1) && c2Ord1.p2 : number ->isC2(c2Ord1) : x is C2 +>isC2(c2Ord1) : boolean >isC2 : (x: any) => x is C2 >c2Ord1 : C2 | D1 >c2Ord1.p2 : number @@ -158,7 +158,7 @@ num = isD1(c2Ord1) && c2Ord1.p3; // D1 >num = isD1(c2Ord1) && c2Ord1.p3 : number >num : number >isD1(c2Ord1) && c2Ord1.p3 : number ->isD1(c2Ord1) : x is D1 +>isD1(c2Ord1) : boolean >isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p3 : number @@ -169,7 +169,7 @@ str = isD1(c2Ord1) && c2Ord1.p1; // D1 >str = isD1(c2Ord1) && c2Ord1.p1 : string >str : string >isD1(c2Ord1) && c2Ord1.p1 : string ->isD1(c2Ord1) : x is D1 +>isD1(c2Ord1) : boolean >isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p1 : string @@ -181,7 +181,7 @@ var r2: C2 | D1 = isC1(c2Ord1) && c2Ord1; // C2 | D1 >C2 : C2 >D1 : D1 >isC1(c2Ord1) && c2Ord1 : D1 ->isC1(c2Ord1) : x is C1 +>isC1(c2Ord1) : boolean >isC1 : (x: any) => x is C1 >c2Ord1 : C2 | D1 >c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardOfFormThisMember.errors.txt b/tests/baselines/reference/typeGuardOfFormThisMember.errors.txt new file mode 100644 index 00000000000..21dc896fbd9 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormThisMember.errors.txt @@ -0,0 +1,130 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(4,10): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(5,17): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(11,22): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(14,16): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(34,8): error TS2339: Property 'content' does not exist on type 'FileSystemObject'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(36,9): error TS2339: Property 'host' does not exist on type 'FileSystemObject'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(37,9): error TS2339: Property 'content' does not exist on type 'FileSystemObject'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(41,8): error TS2339: Property 'children' does not exist on type 'FileSystemObject'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(44,8): error TS2339: Property 'host' does not exist on type 'FileSystemObject'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(57,13): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(58,15): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(63,9): error TS2339: Property 'lead' does not exist on type 'GenericGuard'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(66,9): error TS2339: Property 'follow' does not exist on type 'GenericGuard'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(70,19): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts(79,11): error TS2339: Property 'do' does not exist on type 'SpecificGuard'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts (15 errors) ==== + // There's a 'File' class in the stdlib, wrap with a namespace to avoid collision + namespace Test { + export class FileSystemObject { + isFSO: this is FileSystemObject; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + get isFile(): this is File { + ~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + return this instanceof File; + } + set isFile(param) { + // noop + } + get isDirectory(): this is Directory { + ~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + return this instanceof Directory; + } + isNetworked: this is (Networked & this); + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + constructor(public path: string) {} + } + + export class File extends FileSystemObject { + constructor(path: string, public content: string) { super(path); } + } + export class Directory extends FileSystemObject { + children: FileSystemObject[]; + } + export interface Networked { + host: string; + } + + let file: FileSystemObject = new File("foo/bar.txt", "foo"); + file.isNetworked = false; + file.isFSO = file.isFile; + file.isFile = true; + let x = file.isFile; + if (file.isFile) { + file.content; + ~~~~~~~ +!!! error TS2339: Property 'content' does not exist on type 'FileSystemObject'. + if (file.isNetworked) { + file.host; + ~~~~ +!!! error TS2339: Property 'host' does not exist on type 'FileSystemObject'. + file.content; + ~~~~~~~ +!!! error TS2339: Property 'content' does not exist on type 'FileSystemObject'. + } + } + else if (file.isDirectory) { + file.children; + ~~~~~~~~ +!!! error TS2339: Property 'children' does not exist on type 'FileSystemObject'. + } + else if (file.isNetworked) { + file.host; + ~~~~ +!!! error TS2339: Property 'host' does not exist on type 'FileSystemObject'. + } + + interface GenericLeadGuard extends GenericGuard { + lead(): void; + } + + interface GenericFollowerGuard extends GenericGuard { + follow(): void; + } + + interface GenericGuard { + target: T; + isLeader: this is (GenericLeadGuard); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + isFollower: this is GenericFollowerGuard; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + } + + let guard: GenericGuard; + if (guard.isLeader) { + guard.lead(); + ~~~~ +!!! error TS2339: Property 'lead' does not exist on type 'GenericGuard'. + } + else if (guard.isFollower) { + guard.follow(); + ~~~~~~ +!!! error TS2339: Property 'follow' does not exist on type 'GenericGuard'. + } + + interface SpecificGuard { + isMoreSpecific: this is MoreSpecificGuard; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. + } + + interface MoreSpecificGuard extends SpecificGuard { + do(): void; + } + + let general: SpecificGuard; + if (general.isMoreSpecific) { + general.do(); + ~~ +!!! error TS2339: Property 'do' does not exist on type 'SpecificGuard'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardOfFormThisMember.symbols b/tests/baselines/reference/typeGuardOfFormThisMember.symbols deleted file mode 100644 index 50e15b68ca4..00000000000 --- a/tests/baselines/reference/typeGuardOfFormThisMember.symbols +++ /dev/null @@ -1,240 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts === -// There's a 'File' class in the stdlib, wrap with a namespace to avoid collision -namespace Test { ->Test : Symbol(Test, Decl(typeGuardOfFormThisMember.ts, 0, 0)) - - export class FileSystemObject { ->FileSystemObject : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) - - isFSO: this is FileSystemObject; ->isFSO : Symbol(isFSO, Decl(typeGuardOfFormThisMember.ts, 2, 32)) ->FileSystemObject : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) - - get isFile(): this is File { ->isFile : Symbol(isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) ->File : Symbol(File, Decl(typeGuardOfFormThisMember.ts, 15, 2)) - - return this instanceof File; ->this : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) ->File : Symbol(File, Decl(typeGuardOfFormThisMember.ts, 15, 2)) - } - set isFile(param) { ->isFile : Symbol(isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) ->param : Symbol(param, Decl(typeGuardOfFormThisMember.ts, 7, 13)) - - // noop - } - get isDirectory(): this is Directory { ->isDirectory : Symbol(isDirectory, Decl(typeGuardOfFormThisMember.ts, 9, 3)) ->Directory : Symbol(Directory, Decl(typeGuardOfFormThisMember.ts, 19, 2)) - - return this instanceof Directory; ->this : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) ->Directory : Symbol(Directory, Decl(typeGuardOfFormThisMember.ts, 19, 2)) - } - isNetworked: this is (Networked & this); ->isNetworked : Symbol(isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) ->Networked : Symbol(Networked, Decl(typeGuardOfFormThisMember.ts, 22, 2)) - - constructor(public path: string) {} ->path : Symbol(path, Decl(typeGuardOfFormThisMember.ts, 14, 14)) - } - - export class File extends FileSystemObject { ->File : Symbol(File, Decl(typeGuardOfFormThisMember.ts, 15, 2)) ->FileSystemObject : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) - - constructor(path: string, public content: string) { super(path); } ->path : Symbol(path, Decl(typeGuardOfFormThisMember.ts, 18, 14)) ->content : Symbol(content, Decl(typeGuardOfFormThisMember.ts, 18, 27)) ->super : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) ->path : Symbol(path, Decl(typeGuardOfFormThisMember.ts, 18, 14)) - } - export class Directory extends FileSystemObject { ->Directory : Symbol(Directory, Decl(typeGuardOfFormThisMember.ts, 19, 2)) ->FileSystemObject : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) - - children: FileSystemObject[]; ->children : Symbol(children, Decl(typeGuardOfFormThisMember.ts, 20, 50)) ->FileSystemObject : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) - } - export interface Networked { ->Networked : Symbol(Networked, Decl(typeGuardOfFormThisMember.ts, 22, 2)) - - host: string; ->host : Symbol(host, Decl(typeGuardOfFormThisMember.ts, 23, 29)) - } - - let file: FileSystemObject = new File("foo/bar.txt", "foo"); ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->FileSystemObject : Symbol(FileSystemObject, Decl(typeGuardOfFormThisMember.ts, 1, 16)) ->File : Symbol(File, Decl(typeGuardOfFormThisMember.ts, 15, 2)) - - file.isNetworked = false; ->file.isNetworked : Symbol(FileSystemObject.isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isNetworked : Symbol(FileSystemObject.isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) - - file.isFSO = file.isFile; ->file.isFSO : Symbol(FileSystemObject.isFSO, Decl(typeGuardOfFormThisMember.ts, 2, 32)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isFSO : Symbol(FileSystemObject.isFSO, Decl(typeGuardOfFormThisMember.ts, 2, 32)) ->file.isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) - - file.isFile = true; ->file.isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) - - let x = file.isFile; ->x : Symbol(x, Decl(typeGuardOfFormThisMember.ts, 31, 4)) ->file.isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) - - if (file.isFile) { ->file.isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isFile : Symbol(FileSystemObject.isFile, Decl(typeGuardOfFormThisMember.ts, 3, 34), Decl(typeGuardOfFormThisMember.ts, 6, 3)) - - file.content; ->file.content : Symbol(File.content, Decl(typeGuardOfFormThisMember.ts, 18, 27)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->content : Symbol(File.content, Decl(typeGuardOfFormThisMember.ts, 18, 27)) - - if (file.isNetworked) { ->file.isNetworked : Symbol(FileSystemObject.isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isNetworked : Symbol(FileSystemObject.isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) - - file.host; ->file.host : Symbol(Networked.host, Decl(typeGuardOfFormThisMember.ts, 23, 29)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->host : Symbol(Networked.host, Decl(typeGuardOfFormThisMember.ts, 23, 29)) - - file.content; ->file.content : Symbol(File.content, Decl(typeGuardOfFormThisMember.ts, 18, 27)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->content : Symbol(File.content, Decl(typeGuardOfFormThisMember.ts, 18, 27)) - } - } - else if (file.isDirectory) { ->file.isDirectory : Symbol(FileSystemObject.isDirectory, Decl(typeGuardOfFormThisMember.ts, 9, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isDirectory : Symbol(FileSystemObject.isDirectory, Decl(typeGuardOfFormThisMember.ts, 9, 3)) - - file.children; ->file.children : Symbol(Directory.children, Decl(typeGuardOfFormThisMember.ts, 20, 50)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->children : Symbol(Directory.children, Decl(typeGuardOfFormThisMember.ts, 20, 50)) - } - else if (file.isNetworked) { ->file.isNetworked : Symbol(FileSystemObject.isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->isNetworked : Symbol(FileSystemObject.isNetworked, Decl(typeGuardOfFormThisMember.ts, 12, 3)) - - file.host; ->file.host : Symbol(Networked.host, Decl(typeGuardOfFormThisMember.ts, 23, 29)) ->file : Symbol(file, Decl(typeGuardOfFormThisMember.ts, 27, 4)) ->host : Symbol(Networked.host, Decl(typeGuardOfFormThisMember.ts, 23, 29)) - } - - interface GenericLeadGuard extends GenericGuard { ->GenericLeadGuard : Symbol(GenericLeadGuard, Decl(typeGuardOfFormThisMember.ts, 44, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 46, 28)) ->GenericGuard : Symbol(GenericGuard, Decl(typeGuardOfFormThisMember.ts, 52, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 46, 28)) - - lead(): void; ->lead : Symbol(lead, Decl(typeGuardOfFormThisMember.ts, 46, 56)) - } - - interface GenericFollowerGuard extends GenericGuard { ->GenericFollowerGuard : Symbol(GenericFollowerGuard, Decl(typeGuardOfFormThisMember.ts, 48, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 50, 32)) ->GenericGuard : Symbol(GenericGuard, Decl(typeGuardOfFormThisMember.ts, 52, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 50, 32)) - - follow(): void; ->follow : Symbol(follow, Decl(typeGuardOfFormThisMember.ts, 50, 60)) - } - - interface GenericGuard { ->GenericGuard : Symbol(GenericGuard, Decl(typeGuardOfFormThisMember.ts, 52, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 54, 24)) - - target: T; ->target : Symbol(target, Decl(typeGuardOfFormThisMember.ts, 54, 28)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 54, 24)) - - isLeader: this is (GenericLeadGuard); ->isLeader : Symbol(isLeader, Decl(typeGuardOfFormThisMember.ts, 55, 12)) ->GenericLeadGuard : Symbol(GenericLeadGuard, Decl(typeGuardOfFormThisMember.ts, 44, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 54, 24)) - - isFollower: this is GenericFollowerGuard; ->isFollower : Symbol(isFollower, Decl(typeGuardOfFormThisMember.ts, 56, 42)) ->GenericFollowerGuard : Symbol(GenericFollowerGuard, Decl(typeGuardOfFormThisMember.ts, 48, 2)) ->T : Symbol(T, Decl(typeGuardOfFormThisMember.ts, 54, 24)) - } - - let guard: GenericGuard; ->guard : Symbol(guard, Decl(typeGuardOfFormThisMember.ts, 60, 4)) ->GenericGuard : Symbol(GenericGuard, Decl(typeGuardOfFormThisMember.ts, 52, 2)) ->File : Symbol(File, Decl(typeGuardOfFormThisMember.ts, 15, 2)) - - if (guard.isLeader) { ->guard.isLeader : Symbol(GenericGuard.isLeader, Decl(typeGuardOfFormThisMember.ts, 55, 12)) ->guard : Symbol(guard, Decl(typeGuardOfFormThisMember.ts, 60, 4)) ->isLeader : Symbol(GenericGuard.isLeader, Decl(typeGuardOfFormThisMember.ts, 55, 12)) - - guard.lead(); ->guard.lead : Symbol(GenericLeadGuard.lead, Decl(typeGuardOfFormThisMember.ts, 46, 56)) ->guard : Symbol(guard, Decl(typeGuardOfFormThisMember.ts, 60, 4)) ->lead : Symbol(GenericLeadGuard.lead, Decl(typeGuardOfFormThisMember.ts, 46, 56)) - } - else if (guard.isFollower) { ->guard.isFollower : Symbol(GenericGuard.isFollower, Decl(typeGuardOfFormThisMember.ts, 56, 42)) ->guard : Symbol(guard, Decl(typeGuardOfFormThisMember.ts, 60, 4)) ->isFollower : Symbol(GenericGuard.isFollower, Decl(typeGuardOfFormThisMember.ts, 56, 42)) - - guard.follow(); ->guard.follow : Symbol(GenericFollowerGuard.follow, Decl(typeGuardOfFormThisMember.ts, 50, 60)) ->guard : Symbol(guard, Decl(typeGuardOfFormThisMember.ts, 60, 4)) ->follow : Symbol(GenericFollowerGuard.follow, Decl(typeGuardOfFormThisMember.ts, 50, 60)) - } - - interface SpecificGuard { ->SpecificGuard : Symbol(SpecificGuard, Decl(typeGuardOfFormThisMember.ts, 66, 2)) - - isMoreSpecific: this is MoreSpecificGuard; ->isMoreSpecific : Symbol(isMoreSpecific, Decl(typeGuardOfFormThisMember.ts, 68, 26)) ->MoreSpecificGuard : Symbol(MoreSpecificGuard, Decl(typeGuardOfFormThisMember.ts, 70, 2)) - } - - interface MoreSpecificGuard extends SpecificGuard { ->MoreSpecificGuard : Symbol(MoreSpecificGuard, Decl(typeGuardOfFormThisMember.ts, 70, 2)) ->SpecificGuard : Symbol(SpecificGuard, Decl(typeGuardOfFormThisMember.ts, 66, 2)) - - do(): void; ->do : Symbol(do, Decl(typeGuardOfFormThisMember.ts, 72, 52)) - } - - let general: SpecificGuard; ->general : Symbol(general, Decl(typeGuardOfFormThisMember.ts, 76, 4)) ->SpecificGuard : Symbol(SpecificGuard, Decl(typeGuardOfFormThisMember.ts, 66, 2)) - - if (general.isMoreSpecific) { ->general.isMoreSpecific : Symbol(SpecificGuard.isMoreSpecific, Decl(typeGuardOfFormThisMember.ts, 68, 26)) ->general : Symbol(general, Decl(typeGuardOfFormThisMember.ts, 76, 4)) ->isMoreSpecific : Symbol(SpecificGuard.isMoreSpecific, Decl(typeGuardOfFormThisMember.ts, 68, 26)) - - general.do(); ->general.do : Symbol(MoreSpecificGuard.do, Decl(typeGuardOfFormThisMember.ts, 72, 52)) ->general : Symbol(general, Decl(typeGuardOfFormThisMember.ts, 76, 4)) ->do : Symbol(MoreSpecificGuard.do, Decl(typeGuardOfFormThisMember.ts, 72, 52)) - } -} - diff --git a/tests/baselines/reference/typeGuardOfFormThisMember.types b/tests/baselines/reference/typeGuardOfFormThisMember.types deleted file mode 100644 index 68343947fb4..00000000000 --- a/tests/baselines/reference/typeGuardOfFormThisMember.types +++ /dev/null @@ -1,254 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts === -// There's a 'File' class in the stdlib, wrap with a namespace to avoid collision -namespace Test { ->Test : typeof Test - - export class FileSystemObject { ->FileSystemObject : FileSystemObject - - isFSO: this is FileSystemObject; ->isFSO : this is FileSystemObject ->FileSystemObject : FileSystemObject - - get isFile(): this is File { ->isFile : this is File ->File : File - - return this instanceof File; ->this instanceof File : boolean ->this : this ->File : typeof File - } - set isFile(param) { ->isFile : this is File ->param : boolean - - // noop - } - get isDirectory(): this is Directory { ->isDirectory : this is Directory ->Directory : Directory - - return this instanceof Directory; ->this instanceof Directory : boolean ->this : this ->Directory : typeof Directory - } - isNetworked: this is (Networked & this); ->isNetworked : this is Networked & this ->Networked : Networked - - constructor(public path: string) {} ->path : string - } - - export class File extends FileSystemObject { ->File : File ->FileSystemObject : FileSystemObject - - constructor(path: string, public content: string) { super(path); } ->path : string ->content : string ->super(path) : void ->super : typeof FileSystemObject ->path : string - } - export class Directory extends FileSystemObject { ->Directory : Directory ->FileSystemObject : FileSystemObject - - children: FileSystemObject[]; ->children : FileSystemObject[] ->FileSystemObject : FileSystemObject - } - export interface Networked { ->Networked : Networked - - host: string; ->host : string - } - - let file: FileSystemObject = new File("foo/bar.txt", "foo"); ->file : FileSystemObject ->FileSystemObject : FileSystemObject ->new File("foo/bar.txt", "foo") : File ->File : typeof File ->"foo/bar.txt" : string ->"foo" : string - - file.isNetworked = false; ->file.isNetworked = false : boolean ->file.isNetworked : this is Networked & FileSystemObject ->file : FileSystemObject ->isNetworked : this is Networked & FileSystemObject ->false : boolean - - file.isFSO = file.isFile; ->file.isFSO = file.isFile : this is File ->file.isFSO : this is FileSystemObject ->file : FileSystemObject ->isFSO : this is FileSystemObject ->file.isFile : this is File ->file : FileSystemObject ->isFile : this is File - - file.isFile = true; ->file.isFile = true : boolean ->file.isFile : this is File ->file : FileSystemObject ->isFile : this is File ->true : boolean - - let x = file.isFile; ->x : boolean ->file.isFile : this is File ->file : FileSystemObject ->isFile : this is File - - if (file.isFile) { ->file.isFile : this is File ->file : FileSystemObject ->isFile : this is File - - file.content; ->file.content : string ->file : File ->content : string - - if (file.isNetworked) { ->file.isNetworked : this is Networked & File ->file : File ->isNetworked : this is Networked & File - - file.host; ->file.host : string ->file : Networked & File ->host : string - - file.content; ->file.content : string ->file : Networked & File ->content : string - } - } - else if (file.isDirectory) { ->file.isDirectory : this is Directory ->file : FileSystemObject ->isDirectory : this is Directory - - file.children; ->file.children : FileSystemObject[] ->file : Directory ->children : FileSystemObject[] - } - else if (file.isNetworked) { ->file.isNetworked : this is Networked & FileSystemObject ->file : FileSystemObject ->isNetworked : this is Networked & FileSystemObject - - file.host; ->file.host : string ->file : Networked & FileSystemObject ->host : string - } - - interface GenericLeadGuard extends GenericGuard { ->GenericLeadGuard : GenericLeadGuard ->T : T ->GenericGuard : GenericGuard ->T : T - - lead(): void; ->lead : () => void - } - - interface GenericFollowerGuard extends GenericGuard { ->GenericFollowerGuard : GenericFollowerGuard ->T : T ->GenericGuard : GenericGuard ->T : T - - follow(): void; ->follow : () => void - } - - interface GenericGuard { ->GenericGuard : GenericGuard ->T : T - - target: T; ->target : T ->T : T - - isLeader: this is (GenericLeadGuard); ->isLeader : this is GenericLeadGuard ->GenericLeadGuard : GenericLeadGuard ->T : T - - isFollower: this is GenericFollowerGuard; ->isFollower : this is GenericFollowerGuard ->GenericFollowerGuard : GenericFollowerGuard ->T : T - } - - let guard: GenericGuard; ->guard : GenericGuard ->GenericGuard : GenericGuard ->File : File - - if (guard.isLeader) { ->guard.isLeader : this is GenericLeadGuard ->guard : GenericGuard ->isLeader : this is GenericLeadGuard - - guard.lead(); ->guard.lead() : void ->guard.lead : () => void ->guard : GenericLeadGuard ->lead : () => void - } - else if (guard.isFollower) { ->guard.isFollower : this is GenericFollowerGuard ->guard : GenericGuard ->isFollower : this is GenericFollowerGuard - - guard.follow(); ->guard.follow() : void ->guard.follow : () => void ->guard : GenericFollowerGuard ->follow : () => void - } - - interface SpecificGuard { ->SpecificGuard : SpecificGuard - - isMoreSpecific: this is MoreSpecificGuard; ->isMoreSpecific : this is MoreSpecificGuard ->MoreSpecificGuard : MoreSpecificGuard - } - - interface MoreSpecificGuard extends SpecificGuard { ->MoreSpecificGuard : MoreSpecificGuard ->SpecificGuard : SpecificGuard - - do(): void; ->do : () => void - } - - let general: SpecificGuard; ->general : SpecificGuard ->SpecificGuard : SpecificGuard - - if (general.isMoreSpecific) { ->general.isMoreSpecific : this is MoreSpecificGuard ->general : SpecificGuard ->isMoreSpecific : this is MoreSpecificGuard - - general.do(); ->general.do() : void ->general.do : () => void ->general : MoreSpecificGuard ->do : () => void - } -} - diff --git a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.errors.txt b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.errors.txt index 754cbffe6e6..88e9d41cc7b 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.errors.txt +++ b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.errors.txt @@ -1,27 +1,32 @@ -tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts(29,2): error TS1226: Type predicate 'this is File' is not assignable to 'this is Networked & FileSystemObject'. - Type 'File' is not assignable to type 'Networked & FileSystemObject'. - Type 'File' is not assignable to type 'Networked'. - Property 'host' is missing in type 'File'. -tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts(31,2): error TS1226: Type predicate 'this is FileSystemObject' is not assignable to 'this is File'. - Type 'FileSystemObject' is not assignable to type 'File'. - Property 'content' is missing in type 'FileSystemObject'. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts(4,10): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts(5,17): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts(11,22): error TS1228: A type predicate is only allowed in return type position for functions and methods. +tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts(14,16): error TS1228: A type predicate is only allowed in return type position for functions and methods. -==== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts (2 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.ts (4 errors) ==== // There's a 'File' class in the stdlib, wrap with a namespace to avoid collision namespace Test { export class FileSystemObject { isFSO: this is FileSystemObject; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. get isFile(): this is File { + ~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return this instanceof File; } set isFile(param) { // noop } get isDirectory(): this is Directory { + ~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. return this instanceof Directory; } isNetworked: this is (Networked & this); + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. constructor(public path: string) {} } @@ -37,15 +42,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMemberErrors.t let file: FileSystemObject = new File("foo/bar.txt", "foo"); file.isNetworked = file.isFile; - ~~~~~~~~~~~~~~~~ -!!! error TS1226: Type predicate 'this is File' is not assignable to 'this is Networked & FileSystemObject'. -!!! error TS1226: Type 'File' is not assignable to type 'Networked & FileSystemObject'. -!!! error TS1226: Type 'File' is not assignable to type 'Networked'. -!!! error TS1226: Property 'host' is missing in type 'File'. file.isFSO = file.isNetworked; file.isFile = file.isFSO; - ~~~~~~~~~~~ -!!! error TS1226: Type predicate 'this is FileSystemObject' is not assignable to 'this is File'. -!!! error TS1226: Type 'FileSystemObject' is not assignable to type 'File'. -!!! error TS1226: Property 'content' is missing in type 'FileSystemObject'. } \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterFixingWithConstraints.types b/tests/baselines/reference/typeParameterFixingWithConstraints.types index 22d294f9d2e..1e71f439e5e 100644 --- a/tests/baselines/reference/typeParameterFixingWithConstraints.types +++ b/tests/baselines/reference/typeParameterFixingWithConstraints.types @@ -31,17 +31,17 @@ var foo: IFoo; >IFoo : IFoo foo.foo({ bar: null }, bar => null, bar => null); ->foo.foo({ bar: null }, bar => null, bar => null) : { [x: string]: any; bar: any; } +>foo.foo({ bar: null }, bar => null, bar => null) : { bar: any; } >foo.foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar >foo : IFoo >foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar ->{ bar: null } : { [x: string]: null; bar: null; } +>{ bar: null } : { bar: null; } >bar : null >null : null ->bar => null : (bar: { [x: string]: any; bar: any; }) => any ->bar : { [x: string]: any; bar: any; } +>bar => null : (bar: { bar: any; }) => any +>bar : { bar: any; } >null : null ->bar => null : (bar: { [x: string]: any; bar: any; }) => any ->bar : { [x: string]: any; bar: any; } +>bar => null : (bar: { bar: any; }) => any +>bar : { bar: any; } >null : null diff --git a/tests/baselines/reference/typePredicateOnVariableDeclaration01.errors.txt b/tests/baselines/reference/typePredicateOnVariableDeclaration01.errors.txt new file mode 100644 index 00000000000..b713dd12ae7 --- /dev/null +++ b/tests/baselines/reference/typePredicateOnVariableDeclaration01.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration01.ts(2,8): error TS1228: A type predicate is only allowed in return type position for functions and methods. + + +==== tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration01.ts (1 errors) ==== + + var x: this is string; + ~~~~~~~~~~~~~~ +!!! error TS1228: A type predicate is only allowed in return type position for functions and methods. \ No newline at end of file diff --git a/tests/baselines/reference/typePredicateOnVariableDeclaration01.js b/tests/baselines/reference/typePredicateOnVariableDeclaration01.js new file mode 100644 index 00000000000..5831142cf5c --- /dev/null +++ b/tests/baselines/reference/typePredicateOnVariableDeclaration01.js @@ -0,0 +1,10 @@ +//// [typePredicateOnVariableDeclaration01.ts] + +var x: this is string; + +//// [typePredicateOnVariableDeclaration01.js] +var x; + + +//// [typePredicateOnVariableDeclaration01.d.ts] +declare var x: this is string; diff --git a/tests/baselines/reference/typePredicateOnVariableDeclaration02.errors.txt b/tests/baselines/reference/typePredicateOnVariableDeclaration02.errors.txt new file mode 100644 index 00000000000..af967b22b79 --- /dev/null +++ b/tests/baselines/reference/typePredicateOnVariableDeclaration02.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts(2,8): error TS2304: Cannot find name 'z'. +tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts(2,8): error TS4025: Exported variable 'y' has or is using private name 'z'. +tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts(2,10): error TS1005: '=' expected. +tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts(2,10): error TS2304: Cannot find name 'is'. +tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts(2,13): error TS1005: ',' expected. + + +==== tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts (5 errors) ==== + + var y: z is number; + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS4025: Exported variable 'y' has or is using private name 'z'. + ~~ +!!! error TS1005: '=' expected. + ~~ +!!! error TS2304: Cannot find name 'is'. + ~~~~~~ +!!! error TS1005: ',' expected. \ No newline at end of file diff --git a/tests/baselines/reference/typePredicateOnVariableDeclaration02.js b/tests/baselines/reference/typePredicateOnVariableDeclaration02.js new file mode 100644 index 00000000000..b28a89116ba --- /dev/null +++ b/tests/baselines/reference/typePredicateOnVariableDeclaration02.js @@ -0,0 +1,6 @@ +//// [typePredicateOnVariableDeclaration02.ts] + +var y: z is number; + +//// [typePredicateOnVariableDeclaration02.js] +var y = is, number; diff --git a/tests/baselines/reference/typesWithPrivateConstructor.errors.txt b/tests/baselines/reference/typesWithPrivateConstructor.errors.txt index 261038a1f4a..ab8ea4e26ad 100644 --- a/tests/baselines/reference/typesWithPrivateConstructor.errors.txt +++ b/tests/baselines/reference/typesWithPrivateConstructor.errors.txt @@ -1,36 +1,24 @@ -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(4,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(8,5): error TS2322: Type 'Function' is not assignable to type '() => void'. - Type 'Function' provides no match for the signature '(): void' -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(11,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(12,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(15,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(6,9): error TS2673: Constructor of class 'C' is private and only accessible within the class declaration. +tests/cases/conformance/types/members/typesWithPrivateConstructor.ts(14,10): error TS2673: Constructor of class 'C2' is private and only accessible within the class declaration. -==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (5 errors) ==== - // private constructors are not allowed +==== tests/cases/conformance/types/members/typesWithPrivateConstructor.ts (2 errors) ==== class C { private constructor() { } - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } - var c = new C(); + var c = new C(); // error C is private + ~~~~~~~ +!!! error TS2673: Constructor of class 'C' is private and only accessible within the class declaration. var r: () => void = c.constructor; - ~ -!!! error TS2322: Type 'Function' is not assignable to type '() => void'. -!!! error TS2322: Type 'Function' provides no match for the signature '(): void' class C2 { private constructor(x: number); - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. private constructor(x: any) { } - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } - var c2 = new C2(); + var c2 = new C2(); // error C2 is private ~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. +!!! error TS2673: Constructor of class 'C2' is private and only accessible within the class declaration. var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/baselines/reference/typesWithPrivateConstructor.js b/tests/baselines/reference/typesWithPrivateConstructor.js index d894eeda49a..1795ee6b316 100644 --- a/tests/baselines/reference/typesWithPrivateConstructor.js +++ b/tests/baselines/reference/typesWithPrivateConstructor.js @@ -1,11 +1,10 @@ //// [typesWithPrivateConstructor.ts] -// private constructors are not allowed class C { private constructor() { } } -var c = new C(); +var c = new C(); // error C is private var r: () => void = c.constructor; class C2 { @@ -13,22 +12,34 @@ class C2 { private constructor(x: any) { } } -var c2 = new C2(); +var c2 = new C2(); // error C2 is private var r2: (x: number) => void = c2.constructor; //// [typesWithPrivateConstructor.js] -// private constructors are not allowed var C = (function () { function C() { } return C; }()); -var c = new C(); +var c = new C(); // error C is private var r = c.constructor; var C2 = (function () { function C2(x) { } return C2; }()); -var c2 = new C2(); +var c2 = new C2(); // error C2 is private var r2 = c2.constructor; + + +//// [typesWithPrivateConstructor.d.ts] +declare class C { + private constructor(); +} +declare var c: any; +declare var r: () => void; +declare class C2 { + private constructor(x); +} +declare var c2: any; +declare var r2: (x: number) => void; diff --git a/tests/baselines/reference/typesWithProtectedConstructor.errors.txt b/tests/baselines/reference/typesWithProtectedConstructor.errors.txt new file mode 100644 index 00000000000..2a5a059f44d --- /dev/null +++ b/tests/baselines/reference/typesWithProtectedConstructor.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(6,9): error TS2674: Constructor of class 'C' is protected and only accessible within the class declaration. +tests/cases/conformance/types/members/typesWithProtectedConstructor.ts(14,10): error TS2674: Constructor of class 'C2' is protected and only accessible within the class declaration. + + +==== tests/cases/conformance/types/members/typesWithProtectedConstructor.ts (2 errors) ==== + + class C { + protected constructor() { } + } + + var c = new C(); // error C is protected + ~~~~~~~ +!!! error TS2674: Constructor of class 'C' is protected and only accessible within the class declaration. + var r: () => void = c.constructor; + + class C2 { + protected constructor(x: number); + protected constructor(x: any) { } + } + + var c2 = new C2(); // error C2 is protected + ~~~~~~~~ +!!! error TS2674: Constructor of class 'C2' is protected and only accessible within the class declaration. + var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/baselines/reference/typesWithProtectedConstructor.js b/tests/baselines/reference/typesWithProtectedConstructor.js new file mode 100644 index 00000000000..e75b3b6ecd3 --- /dev/null +++ b/tests/baselines/reference/typesWithProtectedConstructor.js @@ -0,0 +1,45 @@ +//// [typesWithProtectedConstructor.ts] + +class C { + protected constructor() { } +} + +var c = new C(); // error C is protected +var r: () => void = c.constructor; + +class C2 { + protected constructor(x: number); + protected constructor(x: any) { } +} + +var c2 = new C2(); // error C2 is protected +var r2: (x: number) => void = c2.constructor; + +//// [typesWithProtectedConstructor.js] +var C = (function () { + function C() { + } + return C; +}()); +var c = new C(); // error C is protected +var r = c.constructor; +var C2 = (function () { + function C2(x) { + } + return C2; +}()); +var c2 = new C2(); // error C2 is protected +var r2 = c2.constructor; + + +//// [typesWithProtectedConstructor.d.ts] +declare class C { + protected constructor(); +} +declare var c: any; +declare var r: () => void; +declare class C2 { + protected constructor(x: number); +} +declare var c2: any; +declare var r2: (x: number) => void; diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 4d8a05a5c38..37f3bdb12ab 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -31,7 +31,7 @@ _.each({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => alert(valu >_.each : { (list: T[], iterator: Iterator, context?: any): void; (list: Dictionary, iterator: Iterator, context?: any): void; } >_ : Underscore.Static >each : { (list: T[], iterator: Iterator, context?: any): void; (list: Dictionary, iterator: Iterator, context?: any): void; } ->{ one: 1, two: 2, three: 3 } : { [x: string]: number; one: number; two: number; three: number; } +>{ one: 1, two: 2, three: 3 } : { one: number; two: number; three: number; } >one : number >1 : number >two : number @@ -68,7 +68,7 @@ _.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 3); >_.map : { (list: T[], iterator: Iterator, context?: any): U[]; (list: Dictionary, iterator: Iterator, context?: any): U[]; } >_ : Underscore.Static >map : { (list: T[], iterator: Iterator, context?: any): U[]; (list: Dictionary, iterator: Iterator, context?: any): U[]; } ->{ one: 1, two: 2, three: 3 } : { [x: string]: number; one: number; two: number; three: number; } +>{ one: 1, two: 2, three: 3 } : { one: number; two: number; three: number; } >one : number >1 : number >two : number @@ -449,7 +449,7 @@ _.size({ one: 1, two: 2, three: 3 }); >_.size : { (list: T[]): number; (list: Dictionary): number; } >_ : Underscore.Static >size : { (list: T[]): number; (list: Dictionary): number; } ->{ one: 1, two: 2, three: 3 } : { [x: string]: number; one: number; two: number; three: number; } +>{ one: 1, two: 2, three: 3 } : { one: number; two: number; three: number; } >one : number >1 : number >two : number diff --git a/tests/baselines/reference/unionAndIntersectionInference1.types b/tests/baselines/reference/unionAndIntersectionInference1.types index 073a677b659..5d23688f0b7 100644 --- a/tests/baselines/reference/unionAndIntersectionInference1.types +++ b/tests/baselines/reference/unionAndIntersectionInference1.types @@ -110,7 +110,7 @@ function foo1(value: void|a): void { >a : a if (isVoid(value)) { ->isVoid(value) : value is void +>isVoid(value) : boolean >isVoid : (value: void | a) => value is void >value : void | a @@ -130,7 +130,7 @@ function baz1(value: void|a): void { >a : a if (isNonVoid(value)) { ->isNonVoid(value) : value is a +>isNonVoid(value) : boolean >isNonVoid : (value: void | a) => value is a >value : void | a diff --git a/tests/baselines/reference/widenedTypes.errors.txt b/tests/baselines/reference/widenedTypes.errors.txt index 2277ef6eea7..beda634c2a6 100644 --- a/tests/baselines/reference/widenedTypes.errors.txt +++ b/tests/baselines/reference/widenedTypes.errors.txt @@ -6,8 +6,8 @@ tests/cases/compiler/widenedTypes.ts(11,1): error TS2322: Type 'string' is not a tests/cases/compiler/widenedTypes.ts(18,1): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/widenedTypes.ts(23,5): error TS2322: Type 'number[]' is not assignable to type 'string[]'. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ [x: string]: number; x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. - Index signatures are incompatible. +tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. + Property 'x' is incompatible with index signature. Type 'number' is not assignable to type 'string'. @@ -52,6 +52,6 @@ tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ [x: string]: n !!! error TS2322: Type 'number' is not assignable to type 'string'. var obj: { [x: string]: string; } = { x: 3, y: null }; // assignable because null is widened, and therefore BCT is any ~~~ -!!! error TS2322: Type '{ [x: string]: number; x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ x: number; y: null; }' is not assignable to type '{ [x: string]: string; }'. +!!! error TS2322: Property 'x' is incompatible with index signature. !!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt b/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt index 60602351b46..47e8e6ff4f2 100644 --- a/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt +++ b/tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursiveConstraints4.ts(13,12): error TS2345: Argument of type '{ [x: number]: undefined; length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. +tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursiveConstraints4.ts(13,12): error TS2345: Argument of type '{ length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. ==== tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursiveConstraints4.ts (1 errors) ==== @@ -16,4 +16,4 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/wrappedAndRecursi var r = c.foo(''); var r2 = r({ length: 3, charAt: (x: number) => { '' } }); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ [x: number]: undefined; length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. \ No newline at end of file +!!! error TS2345: Argument of type '{ length: number; charAt: (x: number) => void; }' is not assignable to parameter of type 'string'. \ No newline at end of file diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index c63009f7d63..9672b9863fa 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -18,7 +18,7 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void var program = ts.createProgram(fileNames, options); var emitResult = program.emit(); - var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + var allDiagnostics = ts.getPreEmitDiagnostics(program); allDiagnostics.forEach(diagnostic => { var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); diff --git a/tests/cases/compiler/exportRedeclarationTypeAliases.ts b/tests/cases/compiler/exportRedeclarationTypeAliases.ts new file mode 100644 index 00000000000..eb5cbcd4c6d --- /dev/null +++ b/tests/cases/compiler/exportRedeclarationTypeAliases.ts @@ -0,0 +1,4 @@ +// @module: commonjs +export type Foo = number; +export function Foo(): number; +export function Foo(): any {} \ No newline at end of file diff --git a/tests/cases/compiler/implicitIndexSignatures.ts b/tests/cases/compiler/implicitIndexSignatures.ts new file mode 100644 index 00000000000..2e36a91bada --- /dev/null +++ b/tests/cases/compiler/implicitIndexSignatures.ts @@ -0,0 +1,45 @@ +type StringMap = { [x: string]: string }; + +const empty1 = {}; +let empty2: {}; +const names1 = { a: "foo", b: "bar" }; +let names2: { a: string, b: string }; +let map: StringMap; +map = { x: "xxx", y: "yyy" }; +map = empty1; +map = empty2; +map = names1; +map = names2; + +declare function getStringIndexValue(map: { [x: string]: T }): T; +declare function getNumberIndexValue(map: { [x: number]: T }): T; + +function f1() { + const o1 = { a: 1, b: 2 }; + let o2: { a: number, b: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f2() { + const o1 = { a: "1", b: "2" }; + let o2: { a: string, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f3() { + const o1 = { a: 1, b: "2" }; + let o2: { a: number, b: string }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); +} + +function f4() { + const o1 = { 0: "0", 1: "1", count: 2 }; + let o2: { 0: string, 1: string, count: number }; + const v1 = getStringIndexValue(o1); + const v2 = getStringIndexValue(o2); + const v3 = getNumberIndexValue(o1); + const v4 = getNumberIndexValue(o2); +} diff --git a/tests/cases/compiler/jsFileCompilationDecoratorSyntax.ts b/tests/cases/compiler/jsFileCompilationDecoratorSyntax.ts index 2ef95db01fe..6627fb5dca0 100644 --- a/tests/cases/compiler/jsFileCompilationDecoratorSyntax.ts +++ b/tests/cases/compiler/jsFileCompilationDecoratorSyntax.ts @@ -1,3 +1,5 @@ // @allowJs: true +// @noEmit: true +// @experimentalDecorators: true // @filename: a.js -@internal class C { } \ No newline at end of file +@internal class C { } diff --git a/tests/cases/compiler/protectedMembers.ts b/tests/cases/compiler/protectedMembers.ts index ae32e472425..b7528f26068 100644 --- a/tests/cases/compiler/protectedMembers.ts +++ b/tests/cases/compiler/protectedMembers.ts @@ -82,7 +82,6 @@ interface E extends C { } class CC { - // Error, constructor cannot be protected protected constructor() { } } diff --git a/tests/cases/compiler/relativeNamesInClassicResolution.ts b/tests/cases/compiler/relativeNamesInClassicResolution.ts new file mode 100644 index 00000000000..7c73a2e3cad --- /dev/null +++ b/tests/cases/compiler/relativeNamesInClassicResolution.ts @@ -0,0 +1,7 @@ +// @module:amd + +// @filename: somefolder/a.ts +import {x} from "./b" + +// @filename: b.ts +export let x = 1; \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts index c2e4855e63a..1c9a801429d 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts @@ -1,18 +1,20 @@ +// @declaration: true + class C { public constructor(public x: number) { } } class D { - private constructor(public x: number) { } // error + private constructor(public x: number) { } } class E { - protected constructor(public x: number) { } // error + protected constructor(public x: number) { } } var c = new C(1); -var d = new D(1); -var e = new E(1); +var d = new D(1); // error +var e = new E(1); // error module Generic { class C { @@ -20,14 +22,14 @@ module Generic { } class D { - private constructor(public x: T) { } // error + private constructor(public x: T) { } } class E { - protected constructor(public x: T) { } // error + protected constructor(public x: T) { } } var c = new C(1); - var d = new D(1); - var e = new E(1); + var d = new D(1); // error + var e = new E(1); // error } diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts new file mode 100644 index 00000000000..2a961e2c067 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts @@ -0,0 +1,42 @@ +// @declaration: true + +class BaseA { + public constructor(public x: number) { } + createInstance() { new BaseA(1); } +} + +class BaseB { + protected constructor(public x: number) { } + createInstance() { new BaseB(1); } +} + +class BaseC { + private constructor(public x: number) { } + createInstance() { new BaseC(1); } +} + +class DerivedA extends BaseA { + constructor(public x: number) { super(x); } + createInstance() { new DerivedA(1); } + createBaseInstance() { new BaseA(1); } +} + +class DerivedB extends BaseB { + constructor(public x: number) { super(x); } + createInstance() { new DerivedB(1); } + createBaseInstance() { new BaseB(1); } // error +} + +class DerivedC extends BaseC { // error + constructor(public x: number) { super(x); } + createInstance() { new DerivedC(1); } + createBaseInstance() { new BaseC(1); } // error +} + +var ba = new BaseA(1); +var bb = new BaseB(1); // error +var bc = new BaseC(1); // error + +var da = new DerivedA(1); +var db = new DerivedB(1); +var dc = new DerivedC(1); \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts new file mode 100644 index 00000000000..91bb4873d96 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility3.ts @@ -0,0 +1,35 @@ +// @declaration: true + +class Foo { + constructor(public x: number) { } +} + +class Bar { + public constructor(public x: number) { } +} + +class Baz { + protected constructor(public x: number) { } +} + +class Qux { + private constructor(public x: number) { } +} + +// b is public +let a = Foo; +a = Bar; +a = Baz; // error Baz is protected +a = Qux; // error Qux is private + +// b is protected +let b = Baz; +b = Foo; +b = Bar; +b = Qux; // error Qux is private + +// c is private +let c = Qux; +c = Foo; +c = Bar; +c = Baz; \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility4.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility4.ts new file mode 100644 index 00000000000..3760f2176ae --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility4.ts @@ -0,0 +1,31 @@ +// @declaration: true + +class A { + private constructor() { } + + method() { + class B { + method() { + new A(); // OK + } + } + + class C extends A { // OK + } + } +} + +class D { + protected constructor() { } + + method() { + class E { + method() { + new D(); // OK + } + } + + class F extends D { // OK + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts new file mode 100644 index 00000000000..5ed20d03853 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts @@ -0,0 +1,34 @@ +// @declaration: true + +class A { + public constructor(a: boolean) // error + protected constructor(a: number) // error + private constructor(a: string) + private constructor() { + + } +} + +class B { + protected constructor(a: number) // error + constructor(a: string) + constructor() { + + } +} + +class C { + protected constructor(a: number) + protected constructor(a: string) + protected constructor() { + + } +} + +class D { + constructor(a: number) + constructor(a: string) + public constructor() { + + } +} \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts new file mode 100644 index 00000000000..c4a223f07ef --- /dev/null +++ b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts @@ -0,0 +1,6 @@ +// @declaration: true +// @module: commonjs + +export function f(x: any): x is number { + return typeof x === "number"; +} \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts new file mode 100644 index 00000000000..1398b2bc040 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts @@ -0,0 +1,10 @@ +// @declaration: true +// @module: commonjs + +interface I { + a: number; +} + +export function f(x: any): x is I { + return typeof x.a === "number"; +} \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates01.ts b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates01.ts new file mode 100644 index 00000000000..69af9c5b077 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates01.ts @@ -0,0 +1,11 @@ +// @declaration: true +// @module: commonjs + +export class C { + m(): this is D { + return this instanceof D; + } +} + +export class D extends C { +} \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts new file mode 100644 index 00000000000..02f2a798831 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts @@ -0,0 +1,15 @@ +// @declaration: true +// @module: commonjs + +export interface Foo { + a: string; + b: number; + c: boolean; +} + +export const obj = { + m(): this is Foo { + let dis = this as Foo; + return dis.a != null && dis.b != null && dis.c != null; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts new file mode 100644 index 00000000000..461c7d17571 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts @@ -0,0 +1,11 @@ +// @declaration: true +// @module: commonjs + +export class C { + m(): this is D { + return this instanceof D; + } +} + +class D extends C { +} \ No newline at end of file diff --git a/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts new file mode 100644 index 00000000000..c238bb16ec8 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts @@ -0,0 +1,15 @@ +// @declaration: true +// @module: commonjs + +interface Foo { + a: string; + b: number; + c: boolean; +} + +export const obj = { + m(): this is Foo { + let dis = this as Foo; + return dis.a != null && dis.b != null && dis.c != null; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing1.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing1.ts new file mode 100644 index 00000000000..e5d63f2e930 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing1.ts @@ -0,0 +1,15 @@ +declare var Factory: any + +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + super(i); + var s = { + t: this._t + } + var i = Factory.create(s); + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing2.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing2.ts new file mode 100644 index 00000000000..1b0a0d541e9 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing2.ts @@ -0,0 +1,9 @@ +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + super(() => { this._t }); // no error. only check when this is directly accessing in constructor + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing3.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing3.ts new file mode 100644 index 00000000000..1386998aaae --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing3.ts @@ -0,0 +1,12 @@ +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + let x = () => { this._t }; + x(); // no error; we only check super is called before this when the container is a constructor + this._t; // error + super(undefined); + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts new file mode 100644 index 00000000000..9135e03b0ce --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts @@ -0,0 +1,15 @@ +class D extends null { + private _t; + constructor() { + this._t; + super(); + } +} + +class E extends null { + private _t; + constructor() { + super(); + this._t; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing5.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing5.ts new file mode 100644 index 00000000000..17820277585 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing5.ts @@ -0,0 +1,6 @@ +class D extends null { + private _t; + constructor() { + this._t; // No error + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing6.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing6.ts new file mode 100644 index 00000000000..8f36f2eb056 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing6.ts @@ -0,0 +1,9 @@ +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + super(this); + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing7.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing7.ts new file mode 100644 index 00000000000..d40c96a60f3 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing7.ts @@ -0,0 +1,12 @@ +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + let x = { + j: this._t, + } + super(undefined); + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing8.ts b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing8.ts new file mode 100644 index 00000000000..5742cdab845 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing8.ts @@ -0,0 +1,12 @@ +class Base { + constructor(c) { } +} +class D extends Base { + private _t; + constructor() { + let x = { + k: super(undefined), + j: this._t, // no error + } + } +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormFunctionEquality.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormFunctionEquality.ts new file mode 100644 index 00000000000..baff942bb8e --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormFunctionEquality.ts @@ -0,0 +1,14 @@ +declare function isString1(a: number, b: Object): b is string; + +declare function isString2(a: Object): a is string; + +switch (isString1(0, "")) { + case isString2(""): + default: +} + +var x = isString1(0, "") === isString2(""); + +function isString3(a: number, b: number, c: Object): c is string { + return isString1(0, c); +} diff --git a/tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration01.ts b/tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration01.ts new file mode 100644 index 00000000000..a445e18ee40 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration01.ts @@ -0,0 +1,3 @@ +// @declaration: true + +var x: this is string; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts b/tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts new file mode 100644 index 00000000000..4b010287337 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typePredicateOnVariableDeclaration02.ts @@ -0,0 +1,3 @@ +// @declaration: true + +var y: z is number; \ No newline at end of file diff --git a/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts b/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts index 4fb24ca58e4..321864e1751 100644 --- a/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts +++ b/tests/cases/conformance/types/members/typesWithPrivateConstructor.ts @@ -1,10 +1,10 @@ -// private constructors are not allowed +// @declaration: true class C { private constructor() { } } -var c = new C(); +var c = new C(); // error C is private var r: () => void = c.constructor; class C2 { @@ -12,5 +12,5 @@ class C2 { private constructor(x: any) { } } -var c2 = new C2(); +var c2 = new C2(); // error C2 is private var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/cases/conformance/types/members/typesWithProtectedConstructor.ts b/tests/cases/conformance/types/members/typesWithProtectedConstructor.ts new file mode 100644 index 00000000000..e7f6adc38a8 --- /dev/null +++ b/tests/cases/conformance/types/members/typesWithProtectedConstructor.ts @@ -0,0 +1,16 @@ +// @declaration: true + +class C { + protected constructor() { } +} + +var c = new C(); // error C is protected +var r: () => void = c.constructor; + +class C2 { + protected constructor(x: number); + protected constructor(x: any) { } +} + +var c2 = new C2(); // error C2 is protected +var r2: (x: number) => void = c2.constructor; \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts index b71677554a2..8a7120acbb3 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts @@ -1,15 +1,8 @@ /// // @allowJs: true +// @experimentalDecorators: true // @Filename: a.js //// @internal class C {} -verify.getSemanticDiagnostics(`[ - { - "message": "'decorators' can only be used in a .ts file.", - "start": 0, - "length": 9, - "category": "error", - "code": 8017 - } -]`); \ No newline at end of file +verify.getSemanticDiagnostics(`[]`); diff --git a/tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts b/tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts new file mode 100644 index 00000000000..5ebdcd815b2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnPrivateConstructorCall.ts @@ -0,0 +1,9 @@ +/// + +////class A { +//// private constructor() {} +////} +////var x = new A(/*1*/ + +goTo.marker("1"); +verify.not.signatureHelpPresent(); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts b/tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts new file mode 100644 index 00000000000..094a07f3d51 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnProtectedConstructorCall.ts @@ -0,0 +1,9 @@ +/// + +////class A { +//// protected constructor() {} +////} +////var x = new A(/*1*/ + +goTo.marker("1"); +verify.not.signatureHelpPresent(); \ No newline at end of file diff --git a/tests/cases/fourslash/thisPredicateFunctionCompletions01.ts b/tests/cases/fourslash/thisPredicateFunctionCompletions01.ts new file mode 100644 index 00000000000..8c9abb85418 --- /dev/null +++ b/tests/cases/fourslash/thisPredicateFunctionCompletions01.ts @@ -0,0 +1,52 @@ +/// + +//// class FileSystemObject { +//// isFile(): this is Item { +//// return this instanceof Item; +//// } +//// isDirectory(): this is Directory { +//// return this instanceof Directory; +//// } +//// isNetworked(): this is (Networked & this) { +//// return !!(this as Networked).host; +//// } +//// constructor(public path: string) {} +//// } +//// +//// class Item extends FileSystemObject { +//// constructor(path: string, public content: string) { super(path); } +//// } +//// class Directory extends FileSystemObject { +//// children: FileSystemObject[]; +//// } +//// interface Networked { +//// host: string; +//// } +//// +//// const obj: FileSystemObject = new Item("/foo", ""); +//// if (obj.isFile()) { +//// obj./*1*/; +//// if (obj.isNetworked()) { +//// obj./*2*/; +//// } +//// } +//// if (obj.isDirectory()) { +//// obj./*3*/; +//// if (obj.isNetworked()) { +//// obj./*4*/; +//// } +//// } +//// if (obj.isNetworked()) { +//// obj./*5*/; +//// } + +goTo.marker("1"); +verify.completionListContains("content"); +goTo.marker("2"); +verify.completionListContains("host"); +goTo.marker("3"); +verify.completionListContains("children"); +goTo.marker("4"); +verify.completionListContains("host"); +goTo.marker("5"); +verify.completionListContains("host"); \ No newline at end of file diff --git a/tests/cases/fourslash/thisPredicateFunctionCompletions02.ts b/tests/cases/fourslash/thisPredicateFunctionCompletions02.ts new file mode 100644 index 00000000000..e2e311ea649 --- /dev/null +++ b/tests/cases/fourslash/thisPredicateFunctionCompletions02.ts @@ -0,0 +1,43 @@ +/// + +//// interface Sundries { +//// broken: boolean; +//// } +//// +//// interface Supplies { +//// spoiled: boolean; +//// } +//// +//// interface Crate { +//// contents: T; +//// isSundries(): this is Crate; +//// isSupplies(): this is Crate; +//// isPackedTight(): this is (this & {extraContents: T}); +//// } +//// const crate: Crate; +//// if (crate.isPackedTight()) { +//// crate./*1*/; +//// } +//// if (crate.isSundries()) { +//// crate.contents./*2*/; +//// if (crate.isPackedTight()) { +//// crate./*3*/; +//// } +//// } +//// if (crate.isSupplies()) { +//// crate.contents./*4*/; +//// if (crate.isPackedTight()) { +//// crate./*5*/; +//// } +//// } + +goTo.marker("1"); +verify.completionListContains("extraContents"); +goTo.marker("2"); +verify.completionListContains("broken"); +goTo.marker("3"); +verify.completionListContains("extraContents"); +goTo.marker("4"); +verify.completionListContains("spoiled"); +goTo.marker("5"); +verify.completionListContains("extraContents"); \ No newline at end of file diff --git a/tests/cases/fourslash/thisPredicateFunctionCompletions.ts b/tests/cases/fourslash/thisPredicateFunctionCompletions03.ts similarity index 100% rename from tests/cases/fourslash/thisPredicateFunctionCompletions.ts rename to tests/cases/fourslash/thisPredicateFunctionCompletions03.ts diff --git a/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts b/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts new file mode 100644 index 00000000000..135df559189 --- /dev/null +++ b/tests/cases/fourslash/thisPredicateFunctionQuickInfo01.ts @@ -0,0 +1,59 @@ +/// + +//// class FileSystemObject { +//// /*1*/isFile(): this is Item { +//// return this instanceof Item; +//// } +//// /*2*/isDirectory(): this is Directory { +//// return this instanceof Directory; +//// } +//// /*3*/isNetworked(): this is (Networked & this) { +//// return !!(this as Networked).host; +//// } +//// constructor(public path: string) {} +//// } +//// +//// class Item extends FileSystemObject { +//// constructor(path: string, public content: string) { super(path); } +//// } +//// class Directory extends FileSystemObject { +//// children: FileSystemObject[]; +//// } +//// interface Networked { +//// host: string; +//// } +//// +//// const obj: FileSystemObject = new Item("/foo", ""); +//// if (obj.isFile/*4*/()) { +//// obj.; +//// if (obj.isNetworked/*5*/()) { +//// obj.; +//// } +//// } +//// if (obj.isDirectory/*6*/()) { +//// obj.; +//// if (obj.isNetworked/*7*/()) { +//// obj.; +//// } +//// } +//// if (obj.isNetworked/*8*/()) { +//// obj.; +//// } + +goTo.marker("1"); +verify.quickInfoIs("(method) FileSystemObject.isFile(): this is Item"); +goTo.marker("2"); +verify.quickInfoIs("(method) FileSystemObject.isDirectory(): this is Directory"); +goTo.marker("3"); +verify.quickInfoIs("(method) FileSystemObject.isNetworked(): this is Networked & this"); + +goTo.marker("4"); +verify.quickInfoIs("(method) FileSystemObject.isFile(): this is Item"); +goTo.marker("5"); +verify.quickInfoIs("(method) FileSystemObject.isNetworked(): this is Networked & Item"); +goTo.marker("6"); +verify.quickInfoIs("(method) FileSystemObject.isDirectory(): this is Directory"); +goTo.marker("7"); +verify.quickInfoIs("(method) FileSystemObject.isNetworked(): this is Networked & Directory"); +goTo.marker("8"); +verify.quickInfoIs("(method) FileSystemObject.isNetworked(): this is Networked & FileSystemObject"); \ No newline at end of file diff --git a/tests/cases/fourslash/thisPredicateFunctionQuickInfo02.ts b/tests/cases/fourslash/thisPredicateFunctionQuickInfo02.ts new file mode 100644 index 00000000000..b8135026c82 --- /dev/null +++ b/tests/cases/fourslash/thisPredicateFunctionQuickInfo02.ts @@ -0,0 +1,57 @@ +/// + +//// interface Sundries { +//// broken: boolean; +//// } +//// +//// interface Supplies { +//// spoiled: boolean; +//// } +//// +//// interface Crate { +//// contents: T; +//// /*1*/isSundries(): this is Crate; +//// /*2*/isSupplies(): this is Crate; +//// /*3*/isPackedTight(): this is (this & {extraContents: T}); +//// } +//// const crate: Crate; +//// if (crate.isPackedTight/*4*/()) { +//// crate.; +//// } +//// if (crate.isSundries/*5*/()) { +//// crate.contents.; +//// if (crate.isPackedTight/*6*/()) { +//// crate.; +//// } +//// } +//// if (crate.isSupplies/*7*/()) { +//// crate.contents.; +//// if (crate.isPackedTight/*8*/()) { +//// crate.; +//// } +//// } + +goTo.marker("1"); +verify.quickInfoIs("(method) Crate.isSundries(): this is Crate"); +goTo.marker("2"); +verify.quickInfoIs("(method) Crate.isSupplies(): this is Crate"); +goTo.marker("3"); +verify.quickInfoIs(`(method) Crate.isPackedTight(): this is this & { + extraContents: T; +}`); +goTo.marker("4"); +verify.quickInfoIs(`(method) Crate.isPackedTight(): this is Crate & { + extraContents: any; +}`); +goTo.marker("5"); +verify.quickInfoIs("(method) Crate.isSundries(): this is Crate"); +goTo.marker("6"); +verify.quickInfoIs(`(method) Crate.isPackedTight(): this is Crate & { + extraContents: Sundries; +}`); +goTo.marker("7"); +verify.quickInfoIs("(method) Crate.isSupplies(): this is Crate"); +goTo.marker("8"); +verify.quickInfoIs(`(method) Crate.isPackedTight(): this is Crate & { + extraContents: Supplies; +}`); \ No newline at end of file diff --git a/tests/cases/fourslash/thisPredicateMemberCompletions.ts b/tests/cases/fourslash/thisPredicateMemberCompletions.ts deleted file mode 100644 index 24ce742faac..00000000000 --- a/tests/cases/fourslash/thisPredicateMemberCompletions.ts +++ /dev/null @@ -1,95 +0,0 @@ -/// - -//// class FileSystemObject { -//// get is/*1*/File(): this is Item { -//// return this instanceof Item; -//// } -//// set is/*2*/File(param) { -//// // noop -//// } -//// get is/*3*/Directory(): this is Directory { -//// return this instanceof Directory; -//// } -//// is/*4*/Networked: this is (Networked & this); -//// constructor(public path: string) {} -//// } -//// -//// class Item extends FileSystemObject { -//// constructor(path: string, public content: string) { super(path); } -//// } -//// class Directory extends FileSystemObject { -//// children: FileSystemObject[]; -//// } -//// interface Networked { -//// host: string; -//// } -//// -//// interface Sundries { -//// broken: boolean; -//// } -//// -//// interface Supplies { -//// spoiled: boolean; -//// } -//// -//// interface Crate { -//// contents: T; -//// is/*5*/Sundries: this is Crate; -//// is/*6*/Supplies: this is Crate; -//// is/*7*/PackedTight: this is (this & {extraContents: T}); -//// } -//// -//// const obj: FileSystemObject = new Item("/foo", ""); -//// if (obj.is/*8*/File) { -//// obj./*9*/; -//// if (obj.is/*10*/Networked) { -//// obj./*11*/; -//// } -//// } -//// if (obj.is/*12*/Directory) { -//// obj./*13*/; -//// if (obj.is/*14*/Networked) { -//// obj./*15*/; -//// } -//// } -//// if (obj.is/*16*/Networked) { -//// obj./*17*/; -//// } -//// -//// const crate: Crate; -//// if (crate.is/*18*/PackedTight) { -//// crate./*19*/; -//// } -//// if (crate.is/*20*/Sundries) { -//// crate.contents./*21*/; -//// if (crate.is/*22*/PackedTight) { -//// crate./*23*/ -//// } -//// } -//// if (crate.is/*24*/Supplies) { -//// crate.contents./*25*/; -//// if (crate.is/*26*/PackedTight) { -//// crate./*27*/ -//// } -//// } - -goTo.marker("9"); -verify.completionListContains("content"); -goTo.marker("11"); -verify.completionListContains("host"); -goTo.marker("13"); -verify.completionListContains("children"); -goTo.marker("15"); -verify.completionListContains("host"); -goTo.marker("17"); -verify.completionListContains("host"); -goTo.marker("19"); -verify.completionListContains("extraContents"); -goTo.marker("21"); -verify.completionListContains("broken"); -goTo.marker("23"); -verify.completionListContains("extraContents"); -goTo.marker("25"); -verify.completionListContains("spoiled"); -goTo.marker("27"); -verify.completionListContains("extraContents"); \ No newline at end of file diff --git a/tests/cases/fourslash/thisPredicateMemberQuickInfo.ts b/tests/cases/fourslash/thisPredicateMemberQuickInfo.ts deleted file mode 100644 index 20d519e0008..00000000000 --- a/tests/cases/fourslash/thisPredicateMemberQuickInfo.ts +++ /dev/null @@ -1,117 +0,0 @@ -/// - -//// class FileSystemObject { -//// get is/*1*/File(): this is Item { -//// return this instanceof Item; -//// } -//// set is/*2*/File(param) { -//// // noop -//// } -//// get is/*3*/Directory(): this is Directory { -//// return this instanceof Directory; -//// } -//// is/*4*/Networked: this is (Networked & this); -//// constructor(public path: string) {} -//// } -//// -//// class Item extends FileSystemObject { -//// constructor(path: string, public content: string) { super(path); } -//// } -//// class Directory extends FileSystemObject { -//// children: FileSystemObject[]; -//// } -//// interface Networked { -//// host: string; -//// } -//// -//// interface Sundries { -//// broken: boolean; -//// } -//// -//// interface Supplies { -//// spoiled: boolean; -//// } -//// -//// interface Crate { -//// contents: T; -//// is/*5*/Sundries: this is Crate; -//// is/*6*/Supplies: this is Crate; -//// is/*7*/PackedTight: this is (this & {extraContents: T}); -//// } -//// -//// const obj: FileSystemObject = new Item("/foo", ""); -//// if (obj.is/*8*/File) { -//// obj./*9*/; -//// if (obj.is/*10*/Networked) { -//// obj./*11*/; -//// } -//// } -//// if (obj.is/*12*/Directory) { -//// obj./*13*/; -//// if (obj.is/*14*/Networked) { -//// obj./*15*/; -//// } -//// } -//// if (obj.is/*16*/Networked) { -//// obj./*17*/; -//// } -//// -//// const crate: Crate; -//// if (crate.is/*18*/PackedTight) { -//// crate./*19*/; -//// } -//// if (crate.is/*20*/Sundries) { -//// crate.contents./*21*/; -//// if (crate.is/*22*/PackedTight) { -//// crate./*23*/ -//// } -//// } -//// if (crate.is/*24*/Supplies) { -//// crate.contents./*25*/; -//// if (crate.is/*26*/PackedTight) { -//// crate./*27*/ -//// } -//// } - -goTo.marker("1"); -verify.quickInfoIs("(property) FileSystemObject.isFile: this is Item"); -goTo.marker("2"); -verify.quickInfoIs("(property) FileSystemObject.isFile: this is Item"); -goTo.marker("3"); -verify.quickInfoIs("(property) FileSystemObject.isDirectory: this is Directory"); -goTo.marker("4"); -verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & this"); -goTo.marker("5"); -verify.quickInfoIs("(property) Crate.isSundries: this is Crate"); -goTo.marker("6"); -verify.quickInfoIs("(property) Crate.isSupplies: this is Crate"); -goTo.marker("7"); -verify.quickInfoIs(`(property) Crate.isPackedTight: this is this & { - extraContents: T; -}`); -goTo.marker("8"); -verify.quickInfoIs("(property) FileSystemObject.isFile: this is Item"); -goTo.marker("10"); -verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & Item"); -goTo.marker("12"); -verify.quickInfoIs("(property) FileSystemObject.isDirectory: this is Directory"); -goTo.marker("14"); -verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & Directory"); -goTo.marker("16"); -verify.quickInfoIs("(property) FileSystemObject.isNetworked: this is Networked & FileSystemObject"); -goTo.marker("18"); -verify.quickInfoIs(`(property) Crate.isPackedTight: this is Crate & { - extraContents: any; -}`); -goTo.marker("20"); -verify.quickInfoIs("(property) Crate.isSundries: this is Crate"); -goTo.marker("22"); -verify.quickInfoIs(`(property) Crate.isPackedTight: this is Crate & { - extraContents: Sundries; -}`); -goTo.marker("24"); -verify.quickInfoIs("(property) Crate.isSupplies: this is Crate"); -goTo.marker("26"); -verify.quickInfoIs(`(property) Crate.isPackedTight: this is Crate & { - extraContents: Supplies; -}`); \ No newline at end of file diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index 1173f579f2c..9a52d9896e4 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -48,7 +48,7 @@ module ts { return hasProperty(directories, path); }, fileExists: path => { - assert.isTrue(hasProperty(directories, getDirectoryPath(path)), "'fileExists' request in non-existing directory"); + assert.isTrue(hasProperty(directories, getDirectoryPath(path)), `'fileExists' '${path}' request in non-existing directory`); return hasProperty(map, path); } } @@ -814,7 +814,6 @@ import b = require("./moduleB.ts"); it ("classic + rootDirs", () => { test(/*hasDirectoryExists*/ false); - test(/*hasDirectoryExists*/ true); function test(hasDirectoryExists: boolean) { let file1: File = { name: "/root/folder1/file1.ts" }; @@ -844,24 +843,20 @@ import b = require("./moduleB.ts"); "/root/generated/folder1/file1.d.ts", // then try alternative rootDir entry ]); - check("../folder1/file1_1", file3, file4, [ - // load from initial location + check("folder1/file1_1", file3, file4, [ + // current location + "/root/generated/folder2/folder1/file1_1.ts", + "/root/generated/folder2/folder1/file1_1.tsx", + "/root/generated/folder2/folder1/file1_1.d.ts", + // other entry in rootDirs "/root/generated/folder1/file1_1.ts", "/root/generated/folder1/file1_1.tsx", "/root/generated/folder1/file1_1.d.ts", - // load from alternative rootDir entry - "/root/folder1/file1_1.ts", - "/root/folder1/file1_1.tsx", - "/root/folder1/file1_1.d.ts", - // fallback to classic - // step1: initial location - "/root/generated/folder1/file1_1.ts", - "/root/generated/folder1/file1_1.tsx", - "/root/generated/folder1/file1_1.d.ts", - // step2: walk 1 level up + // fallback "/root/folder1/file1_1.ts", "/root/folder1/file1_1.tsx", "/root/folder1/file1_1.d.ts", + // found one ]); function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) {