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

This commit is contained in:
Daniel Rosenwasser 2016-09-27 11:13:44 -07:00
commit 5fadfd40d1
109 changed files with 2278 additions and 435 deletions

View File

@ -3,7 +3,6 @@ language: node_js
node_js:
- 'stable'
- '4'
- '0.10'
sudo: false
@ -12,13 +11,6 @@ env:
matrix:
fast_finish: true
include:
- os: osx
node_js: stable
osx_image: xcode7.3
env: workerCount=2
allow_failures:
- os: osx
branches:
only:

View File

@ -132,6 +132,7 @@ namespace ts {
const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
const voidType = createIntrinsicType(TypeFlags.Void, "void");
const neverType = createIntrinsicType(TypeFlags.Never, "never");
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
@ -147,6 +148,7 @@ namespace ts {
const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
const silentNeverSignature = createSignature(undefined, undefined, undefined, emptyArray, silentNeverType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
@ -2013,6 +2015,10 @@ namespace ts {
isExternalModuleAugmentation(node.parent.parent);
}
function literalTypeToString(type: LiteralType) {
return type.flags & TypeFlags.StringLiteral ? `"${escapeString((<LiteralType>type).text)}"` : (<LiteralType>type).text;
}
function getSymbolDisplayBuilder(): SymbolDisplayBuilder {
function getNameOfSymbol(symbol: Symbol): string {
@ -2188,11 +2194,8 @@ namespace ts {
else if (type.flags & TypeFlags.Anonymous) {
writeAnonymousType(<ObjectType>type, nextFlags);
}
else if (type.flags & TypeFlags.StringLiteral) {
writer.writeStringLiteral(`"${escapeString((<LiteralType>type).text)}"`);
}
else if (type.flags & TypeFlags.NumberLiteral) {
writer.writeStringLiteral((<LiteralType>type).text);
else if (type.flags & TypeFlags.StringOrNumberLiteral) {
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
}
else {
// Should never get here
@ -2744,8 +2747,9 @@ namespace ts {
// Type parameters are always visible
case SyntaxKind.TypeParameter:
// Source file is always visible
// Source file and namespace export are always visible
case SyntaxKind.SourceFile:
case SyntaxKind.NamespaceExportDeclaration:
return true;
// Export assignments do not create name bindings outside the module
@ -3836,6 +3840,14 @@ namespace ts {
return true;
}
function createEnumLiteralType(symbol: Symbol, baseType: EnumType, text: string) {
const type = <EnumLiteralType>createType(TypeFlags.EnumLiteral);
type.symbol = symbol;
type.baseType = <EnumType & UnionType>baseType;
type.text = text;
return type;
}
function getDeclaredTypeOfEnum(symbol: Symbol): Type {
const links = getSymbolLinks(symbol);
if (!links.declaredType) {
@ -3851,10 +3863,7 @@ namespace ts {
const memberSymbol = getSymbolOfNode(member);
const value = getEnumMemberValue(member);
if (!memberTypes[value]) {
const memberType = memberTypes[value] = <EnumLiteralType>createType(TypeFlags.EnumLiteral);
memberType.symbol = memberSymbol;
memberType.baseType = <EnumType & UnionType>enumType;
memberType.text = "" + value;
const memberType = memberTypes[value] = createEnumLiteralType(memberSymbol, enumType, "" + value);
memberTypeList.push(memberType);
}
}
@ -5333,6 +5342,9 @@ namespace ts {
containsUndefined?: boolean;
containsNull?: boolean;
containsNonWideningType?: boolean;
containsString?: boolean;
containsNumber?: boolean;
containsStringOrNumberLiteral?: boolean;
}
function binarySearchTypes(types: Type[], type: Type): number {
@ -5360,22 +5372,26 @@ namespace ts {
}
function addTypeToUnion(typeSet: TypeSet, type: Type) {
if (type.flags & TypeFlags.Union) {
const flags = type.flags;
if (flags & TypeFlags.Union) {
addTypesToUnion(typeSet, (<UnionType>type).types);
}
else if (type.flags & TypeFlags.Any) {
else if (flags & TypeFlags.Any) {
typeSet.containsAny = true;
}
else if (!strictNullChecks && type.flags & TypeFlags.Nullable) {
if (type.flags & TypeFlags.Undefined) typeSet.containsUndefined = true;
if (type.flags & TypeFlags.Null) typeSet.containsNull = true;
if (!(type.flags & TypeFlags.ContainsWideningType)) typeSet.containsNonWideningType = true;
else if (!strictNullChecks && flags & TypeFlags.Nullable) {
if (flags & TypeFlags.Undefined) typeSet.containsUndefined = true;
if (flags & TypeFlags.Null) typeSet.containsNull = true;
if (!(flags & TypeFlags.ContainsWideningType)) typeSet.containsNonWideningType = true;
}
else if (!(type.flags & TypeFlags.Never)) {
else if (!(flags & TypeFlags.Never)) {
if (flags & TypeFlags.String) typeSet.containsString = true;
if (flags & TypeFlags.Number) typeSet.containsNumber = true;
if (flags & TypeFlags.StringOrNumberLiteral) typeSet.containsStringOrNumberLiteral = true;
const len = typeSet.length;
const index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type);
if (index < 0) {
if (!(type.flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) {
if (!(flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) {
typeSet.splice(~index, 0, type);
}
}
@ -5408,7 +5424,7 @@ namespace ts {
return false;
}
function removeSubtypes(types: Type[]) {
function removeSubtypes(types: TypeSet) {
let i = types.length;
while (i > 0) {
i--;
@ -5418,6 +5434,21 @@ namespace ts {
}
}
function removeRedundantLiteralTypes(types: TypeSet) {
let i = types.length;
while (i > 0) {
i--;
const t = types[i];
const remove =
t.flags & TypeFlags.StringLiteral && types.containsString ||
t.flags & TypeFlags.NumberLiteral && types.containsNumber ||
t.flags & TypeFlags.StringOrNumberLiteral && t.flags & TypeFlags.FreshLiteral && containsType(types, (<LiteralType>t).regularType);
if (remove) {
orderedRemoveItemAt(types, i);
}
}
}
// We sort and deduplicate the constituent types based on object identity. If the subtypeReduction
// flag is specified we also reduce the constituent type set to only include types that aren't subtypes
// of other types. Subtype reduction is expensive for large union types and is possible only when union
@ -5440,6 +5471,9 @@ namespace ts {
if (subtypeReduction) {
removeSubtypes(typeSet);
}
else if (typeSet.containsStringOrNumberLiteral) {
removeRedundantLiteralTypes(typeSet);
}
if (typeSet.length === 0) {
return typeSet.containsNull ? typeSet.containsNonWideningType ? nullType : nullWideningType :
typeSet.containsUndefined ? typeSet.containsNonWideningType ? undefinedType : undefinedWideningType :
@ -5551,6 +5585,22 @@ namespace ts {
return type;
}
function getFreshTypeOfLiteralType(type: Type) {
if (type.flags & TypeFlags.StringOrNumberLiteral && !(type.flags & TypeFlags.FreshLiteral)) {
if (!(<LiteralType>type).freshType) {
const freshType = <LiteralType>createLiteralType(type.flags | TypeFlags.FreshLiteral, (<LiteralType>type).text);
freshType.regularType = <LiteralType>type;
(<LiteralType>type).freshType = freshType;
}
return (<LiteralType>type).freshType;
}
return type;
}
function getRegularTypeOfLiteralType(type: Type) {
return type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral ? (<LiteralType>type).regularType : type;
}
function getLiteralTypeForText(flags: TypeFlags, text: string) {
const map = flags & TypeFlags.StringLiteral ? stringLiteralTypes : numericLiteralTypes;
return map[text] || (map[text] = createLiteralType(flags, text));
@ -5559,7 +5609,7 @@ namespace ts {
function getTypeFromLiteralTypeNode(node: LiteralTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
links.resolvedType = checkExpression(node.literal);
links.resolvedType = getRegularTypeOfLiteralType(checkExpression(node.literal));
}
return links.resolvedType;
}
@ -5945,7 +5995,7 @@ namespace ts {
// Returns true if the given expression contains (at any level of nesting) a function or arrow expression
// that is subject to contextual typing.
function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean {
function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike): boolean {
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
switch (node.kind) {
case SyntaxKind.FunctionExpression:
@ -6271,7 +6321,7 @@ namespace ts {
if ((source.flags & TypeFlags.Number | source.flags & TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true;
if (source.flags & TypeFlags.EnumLiteral &&
target.flags & TypeFlags.EnumLiteral &&
(<LiteralType>source).text === (<LiteralType>target).text &&
(<EnumLiteralType>source).text === (<EnumLiteralType>target).text &&
isEnumTypeRelatedTo((<EnumLiteralType>source).baseType, (<EnumLiteralType>target).baseType, errorReporter)) {
return true;
}
@ -6285,6 +6335,12 @@ namespace ts {
}
function isTypeRelatedTo(source: Type, target: Type, relation: Map<RelationComparisonResult>) {
if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
source = (<LiteralType>source).regularType;
}
if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) {
target = (<LiteralType>target).regularType;
}
if (source === target || relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) {
return true;
}
@ -6382,6 +6438,12 @@ namespace ts {
// Ternary.False if they are not related.
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
let result: Ternary;
if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
source = (<LiteralType>source).regularType;
}
if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) {
target = (<LiteralType>target).regularType;
}
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
if (source === target) return Ternary.True;
@ -6391,7 +6453,7 @@ namespace ts {
if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
if (source.flags & TypeFlags.FreshObjectLiteral) {
if (source.flags & TypeFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
if (reportErrors) {
reportRelationError(headMessage, source, target);
@ -6502,6 +6564,9 @@ namespace ts {
if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) {
tryElaborateErrorsForPrimitivesAndObjects(source, target);
}
else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) {
reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
}
reportRelationError(headMessage, source, target);
}
return Ternary.False;
@ -7297,6 +7362,15 @@ namespace ts {
type;
}
function getWidenedLiteralType(type: Type): Type {
return type.flags & TypeFlags.StringLiteral && type.flags & TypeFlags.FreshLiteral ? stringType :
type.flags & TypeFlags.NumberLiteral && type.flags & TypeFlags.FreshLiteral ? numberType :
type.flags & TypeFlags.BooleanLiteral ? booleanType :
type.flags & TypeFlags.EnumLiteral ? (<EnumLiteralType>type).baseType :
type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Enum) ? getUnionType(map((<UnionType>type).types, getWidenedLiteralType)) :
type;
}
/**
* Check if a Type was written as a tuple type literal.
* Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
@ -7318,8 +7392,8 @@ namespace ts {
// no flags for all other types (including non-falsy literal types).
function getFalsyFlags(type: Type): TypeFlags {
return type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((<UnionType>type).types) :
type.flags & TypeFlags.StringLiteral ? type === emptyStringType ? TypeFlags.StringLiteral : 0 :
type.flags & TypeFlags.NumberLiteral ? type === zeroType ? TypeFlags.NumberLiteral : 0 :
type.flags & TypeFlags.StringLiteral ? (<LiteralType>type).text === "" ? TypeFlags.StringLiteral : 0 :
type.flags & TypeFlags.NumberLiteral ? (<LiteralType>type).text === "0" ? TypeFlags.NumberLiteral : 0 :
type.flags & TypeFlags.BooleanLiteral ? type === falseType ? TypeFlags.BooleanLiteral : 0 :
type.flags & TypeFlags.PossiblyFalsy;
}
@ -7386,7 +7460,7 @@ namespace ts {
* Leave signatures alone since they are not subject to the check.
*/
function getRegularTypeOfObjectLiteral(type: Type): Type {
if (!(type.flags & TypeFlags.FreshObjectLiteral)) {
if (!(type.flags & TypeFlags.ObjectLiteral && type.flags & TypeFlags.FreshLiteral)) {
return type;
}
const regularType = (<FreshObjectLiteralType>type).regularType;
@ -7402,7 +7476,7 @@ namespace ts {
resolved.constructSignatures,
resolved.stringIndexInfo,
resolved.numberIndexInfo);
regularNew.flags = resolved.flags & ~TypeFlags.FreshObjectLiteral;
regularNew.flags = resolved.flags & ~TypeFlags.FreshLiteral;
(<FreshObjectLiteralType>type).regularType = regularNew;
return regularNew;
}
@ -7853,7 +7927,7 @@ namespace ts {
const widenLiteralTypes = context.inferences[index].topLevel &&
!hasPrimitiveConstraint(signature.typeParameters[index]) &&
(context.inferences[index].isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), signature.typeParameters[index]));
const baseInferences = widenLiteralTypes ? map(inferences, getBaseTypeOfLiteralType) : inferences;
const baseInferences = widenLiteralTypes ? map(inferences, getWidenedLiteralType) : inferences;
// Infer widened union or supertype, or the unknown type for no common supertype
const unionOrSuperType = context.inferUnionTypes ? getUnionType(baseInferences, /*subtypeReduction*/ true) : getCommonSupertype(baseInferences);
inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType;
@ -8070,8 +8144,11 @@ namespace ts {
// we remove type string.
function getAssignmentReducedType(declaredType: UnionType, assignedType: Type) {
if (declaredType !== assignedType) {
if (assignedType.flags & TypeFlags.Never) {
return assignedType;
}
const reducedType = filterType(declaredType, t => typeMaybeAssignableTo(assignedType, t));
if (reducedType !== neverType) {
if (!(reducedType.flags & TypeFlags.Never)) {
return reducedType;
}
}
@ -8101,14 +8178,14 @@ namespace ts {
}
if (flags & TypeFlags.StringLiteral) {
return strictNullChecks ?
type === emptyStringType ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts :
type === emptyStringType ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts;
(<LiteralType>type).text === "" ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts :
(<LiteralType>type).text === "" ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts;
}
if (flags & (TypeFlags.Number | TypeFlags.Enum)) {
return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts;
}
if (flags & (TypeFlags.NumberLiteral | TypeFlags.EnumLiteral)) {
const isZero = type === zeroType || type.flags & TypeFlags.EnumLiteral && (<LiteralType>type).text === "0";
const isZero = (<LiteralType>type).text === "0";
return strictNullChecks ?
isZero ? TypeFacts.ZeroStrictFacts : TypeFacts.NonZeroStrictFacts :
isZero ? TypeFacts.ZeroFacts : TypeFacts.NonZeroFacts;
@ -8281,7 +8358,7 @@ namespace ts {
function getTypeOfSwitchClause(clause: CaseClause | DefaultClause) {
if (clause.kind === SyntaxKind.CaseClause) {
const caseType = checkExpression((<CaseClause>clause).expression);
const caseType = getRegularTypeOfLiteralType(checkExpression((<CaseClause>clause).expression));
return isUnitType(caseType) ? caseType : undefined;
}
return neverType;
@ -8351,7 +8428,7 @@ namespace ts {
const visitedFlowStart = visitedFlowCount;
const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
visitedFlowCount = visitedFlowStart;
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === neverType) {
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
return declaredType;
}
return result;
@ -8440,17 +8517,18 @@ namespace ts {
function getTypeAtFlowCondition(flow: FlowCondition): FlowType {
const flowType = getTypeAtFlowNode(flow.antecedent);
let type = getTypeFromFlowType(flowType);
if (type !== neverType) {
if (!(type.flags & TypeFlags.Never)) {
// If we have an antecedent type (meaning we're reachable in some way), we first
// attempt to narrow the antecedent type. If that produces the never type, and if
// the antecedent type is incomplete (i.e. a transient type in a loop), then we
// take the type guard as an indication that control *could* reach here once we
// have the complete type. We proceed by reverting to the declared type and then
// narrow that.
// have the complete type. We proceed by switching to the silent never type which
// doesn't report errors when operators are applied to it. Note that this is the
// *only* place a silent never type is ever generated.
const assumeTrue = (flow.flags & FlowFlags.TrueCondition) !== 0;
type = narrowType(type, flow.expression, assumeTrue);
if (type === neverType && isIncomplete(flowType)) {
type = narrowType(declaredType, flow.expression, assumeTrue);
if (type.flags & TypeFlags.Never && isIncomplete(flowType)) {
type = silentNeverType;
}
}
return createFlowType(type, isIncomplete(flowType));
@ -8659,9 +8737,13 @@ namespace ts {
}
if (assumeTrue) {
const narrowedType = filterType(type, t => areTypesComparable(t, valueType));
return narrowedType !== neverType ? narrowedType : type;
return narrowedType.flags & TypeFlags.Never ? type : narrowedType;
}
return isUnitType(valueType) ? filterType(type, t => t !== valueType) : type;
if (isUnitType(valueType)) {
const regularType = getRegularTypeOfLiteralType(valueType);
return filterType(type, t => getRegularTypeOfLiteralType(t) !== regularType);
}
return type;
}
function narrowTypeByTypeof(type: Type, typeOfExpr: TypeOfExpression, operator: SyntaxKind, literal: LiteralExpression, assumeTrue: boolean): Type {
@ -8702,12 +8784,12 @@ namespace ts {
const clauseTypes = switchTypes.slice(clauseStart, clauseEnd);
const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, neverType);
const discriminantType = getUnionType(clauseTypes);
const caseType = discriminantType === neverType ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t));
const caseType = discriminantType.flags & TypeFlags.Never ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t));
if (!hasDefaultClause) {
return caseType;
}
const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, t)));
return caseType === neverType ? defaultType : getUnionType([caseType, defaultType]);
const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, getRegularTypeOfLiteralType(t))));
return caseType.flags & TypeFlags.Never ? defaultType : getUnionType([caseType, defaultType]);
}
function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
@ -8771,7 +8853,7 @@ namespace ts {
// the candidate type. If one or more constituents remain, return a union of those.
if (type.flags & TypeFlags.Union) {
const assignableType = filterType(type, t => isTypeInstanceOf(t, candidate));
if (assignableType !== neverType) {
if (!(assignableType.flags & TypeFlags.Never)) {
return assignableType;
}
}
@ -9541,14 +9623,14 @@ namespace ts {
if (parameter.dotDotDotToken) {
const restTypes: Type[] = [];
for (let i = indexOfParameter; i < iife.arguments.length; i++) {
restTypes.push(getBaseTypeOfLiteralType(checkExpression(iife.arguments[i])));
restTypes.push(getWidenedLiteralType(checkExpression(iife.arguments[i])));
}
return createArrayType(getUnionType(restTypes));
}
const links = getNodeLinks(iife);
const cached = links.resolvedSignature;
links.resolvedSignature = anySignature;
const type = getBaseTypeOfLiteralType(checkExpression(iife.arguments[indexOfParameter]));
const type = getWidenedLiteralType(checkExpression(iife.arguments[indexOfParameter]));
links.resolvedSignature = cached;
return type;
}
@ -9783,7 +9865,7 @@ namespace ts {
return getContextualTypeForObjectLiteralElement(node);
}
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) {
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike) {
const objectLiteral = <ObjectLiteralExpression>element.parent;
const type = getApparentTypeOfContextualType(objectLiteral);
if (type) {
@ -9900,7 +9982,7 @@ namespace ts {
return getContextualTypeForBinaryOperand(node);
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
return getContextualTypeForObjectLiteralElement(<ObjectLiteralElement>parent);
return getContextualTypeForObjectLiteralElement(<ObjectLiteralElementLike>parent);
case SyntaxKind.ArrayLiteralExpression:
return getContextualTypeForElementExpression(node);
case SyntaxKind.ConditionalExpression:
@ -10280,7 +10362,7 @@ namespace ts {
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;
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0);
if (inDestructuringPattern) {
result.pattern = node;
@ -10889,7 +10971,7 @@ namespace ts {
function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
const type = checkNonNullExpression(left);
if (isTypeAny(type)) {
if (isTypeAny(type) || type === silentNeverType) {
return type;
}
@ -11036,8 +11118,8 @@ namespace ts {
const objectType = getApparentType(checkNonNullExpression(node.expression));
const indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType;
if (objectType === unknownType) {
return unknownType;
if (objectType === unknownType || objectType === silentNeverType) {
return objectType;
}
const isConstEnum = isConstEnumObjectType(objectType);
@ -12087,6 +12169,9 @@ namespace ts {
}
const funcType = checkNonNullExpression(node.expression);
if (funcType === silentNeverType) {
return silentNeverSignature;
}
const apparentType = getApparentType(funcType);
if (apparentType === unknownType) {
@ -12159,6 +12244,9 @@ namespace ts {
}
let expressionType = checkNonNullExpression(node.expression);
if (expressionType === silentNeverType) {
return silentNeverSignature;
}
// If expressionType's apparent type(section 3.8.1) is an object type with one or
// more construct signatures, the expression is processed in the same manner as a
@ -12644,7 +12732,7 @@ namespace ts {
reportErrorsFromWidening(func, type);
}
if (isUnitType(type) && !(contextualSignature && isLiteralContextualType(getReturnTypeOfSignature(contextualSignature)))) {
type = getBaseTypeOfLiteralType(type);
type = getWidenedLiteralType(type);
}
const widenedType = getWidenedType(type);
@ -12718,7 +12806,7 @@ namespace ts {
// the native Promise<T> type by the caller.
type = checkAwaitedType(type, func, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
}
if (type === neverType) {
if (type.flags & TypeFlags.Never) {
hasReturnOfTypeNever = true;
}
else if (!contains(aggregatedTypes, type)) {
@ -12768,7 +12856,7 @@ namespace ts {
const hasExplicitReturn = func.flags & NodeFlags.HasExplicitReturn;
if (returnType === neverType) {
if (returnType && returnType.flags & TypeFlags.Never) {
error(func.type, Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point);
}
else if (returnType && !hasExplicitReturn) {
@ -13024,8 +13112,11 @@ namespace ts {
function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type {
const operandType = checkExpression(node.operand);
if (operandType === silentNeverType) {
return silentNeverType;
}
if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral) {
return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(<LiteralExpression>node.operand).text);
return getFreshTypeOfLiteralType(getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(<LiteralExpression>node.operand).text));
}
switch (node.operator) {
case SyntaxKind.PlusToken:
@ -13057,6 +13148,9 @@ namespace ts {
function checkPostfixUnaryExpression(node: PostfixUnaryExpression): Type {
const operandType = checkExpression(node.operand);
if (operandType === silentNeverType) {
return silentNeverType;
}
const ok = checkArithmeticOperandType(node.operand, getNonNullableType(operandType),
Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
if (ok) {
@ -13121,6 +13215,9 @@ namespace ts {
}
function checkInstanceOfExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type {
if (leftType === silentNeverType || rightType === silentNeverType) {
return silentNeverType;
}
// TypeScript 1.0 spec (April 2014): 4.15.4
// The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type,
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
@ -13137,6 +13234,9 @@ namespace ts {
}
function checkInExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type {
if (leftType === silentNeverType || rightType === silentNeverType) {
return silentNeverType;
}
// TypeScript 1.0 spec (April 2014): 4.15.5
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
// and the right operand to be of type Any, an object type, or a type parameter type.
@ -13158,7 +13258,7 @@ namespace ts {
return sourceType;
}
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElement, contextualMapper?: TypeMapper) {
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, contextualMapper?: TypeMapper) {
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
const name = <PropertyName>(<PropertyAssignment>property).name;
if (name.kind === SyntaxKind.ComputedPropertyName) {
@ -13401,6 +13501,9 @@ namespace ts {
case SyntaxKind.CaretEqualsToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.AmpersandEqualsToken:
if (leftType === silentNeverType || rightType === silentNeverType) {
return silentNeverType;
}
// TypeScript 1.0 spec (April 2014): 4.19.1
// These operators require their operands to be of type Any, the Number primitive type,
// or an enum type. Operands of an enum type are treated
@ -13433,6 +13536,9 @@ namespace ts {
return numberType;
case SyntaxKind.PlusToken:
case SyntaxKind.PlusEqualsToken:
if (leftType === silentNeverType || rightType === silentNeverType) {
return silentNeverType;
}
// TypeScript 1.0 spec (April 2014): 4.19.2
// The binary + operator requires both operands to be of the Number primitive type or an enum type,
// or at least one of the operands to be of type Any or the String primitive type.
@ -13649,12 +13755,13 @@ namespace ts {
}
switch (node.kind) {
case SyntaxKind.StringLiteral:
return getLiteralTypeForText(TypeFlags.StringLiteral, (<LiteralExpression>node).text);
return getFreshTypeOfLiteralType(getLiteralTypeForText(TypeFlags.StringLiteral, (<LiteralExpression>node).text));
case SyntaxKind.NumericLiteral:
return getLiteralTypeForText(TypeFlags.NumberLiteral, (<LiteralExpression>node).text);
return getFreshTypeOfLiteralType(getLiteralTypeForText(TypeFlags.NumberLiteral, (<LiteralExpression>node).text));
case SyntaxKind.TrueKeyword:
return trueType;
case SyntaxKind.FalseKeyword:
return node.kind === SyntaxKind.TrueKeyword ? trueType : falseType;
return falseType;
}
}
@ -13702,7 +13809,7 @@ namespace ts {
const type = checkExpressionCached(declaration.initializer);
return getCombinedNodeFlags(declaration) & NodeFlags.Const ||
getCombinedModifierFlags(declaration) & ModifierFlags.Readonly ||
isTypeAssertion(declaration.initializer) ? type : getBaseTypeOfLiteralType(type);
isTypeAssertion(declaration.initializer) ? type : getWidenedLiteralType(type);
}
function isLiteralContextualType(contextualType: Type) {
@ -13724,7 +13831,7 @@ namespace ts {
function checkExpressionForMutableLocation(node: Expression, contextualMapper?: TypeMapper): Type {
const type = checkExpression(node, contextualMapper);
return isTypeAssertion(node) || isLiteralContextualType(getContextualType(node)) ? type : getBaseTypeOfLiteralType(type);
return isTypeAssertion(node) || isLiteralContextualType(getContextualType(node)) ? type : getWidenedLiteralType(type);
}
function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type {
@ -16266,7 +16373,7 @@ namespace ts {
// Now that we've removed all the StringLike types, if no constituents remain, then the entire
// arrayOrStringType was a string.
if (arrayType === neverType) {
if (arrayType.flags & TypeFlags.Never) {
return stringType;
}
}
@ -16327,7 +16434,7 @@ namespace ts {
if (func) {
const signature = getSignatureFromDeclaration(func);
const returnType = getReturnTypeOfSignature(signature);
if (strictNullChecks || node.expression || returnType === neverType) {
if (strictNullChecks || node.expression || returnType.flags & TypeFlags.Never) {
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
if (func.asteriskToken) {
@ -18413,7 +18520,7 @@ namespace ts {
// for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) {
if (expr.parent.kind === SyntaxKind.PropertyAssignment) {
const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>expr.parent.parent);
return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || unknownType, <ObjectLiteralElement>expr.parent);
return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || unknownType, <ObjectLiteralElementLike>expr.parent);
}
// Array literal assignment - array destructuring pattern
Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression);
@ -18440,7 +18547,7 @@ namespace ts {
if (isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
expr = <Expression>expr.parent;
}
return checkExpression(expr);
return getRegularTypeOfLiteralType(checkExpression(expr));
}
/**
@ -18851,7 +18958,7 @@ namespace ts {
// Get type of the symbol if this is the valid symbol otherwise get type at location
const symbol = getSymbolOfNode(declaration);
const type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
? getTypeOfSymbol(symbol)
? getWidenedLiteralType(getTypeOfSymbol(symbol))
: unknownType;
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
@ -18911,6 +19018,19 @@ namespace ts {
return undefined;
}
function isLiteralConstDeclaration(node: VariableDeclaration): boolean {
if (isConst(node)) {
const type = getTypeOfSymbol(getSymbolOfNode(node));
return !!(type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral);
}
return false;
}
function writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter) {
const type = getTypeOfSymbol(getSymbolOfNode(node));
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
}
function createResolver(): EmitResolver {
// this variable and functions that use it are deliberately moved here from the outer scope
// to avoid scope pollution
@ -18955,7 +19075,9 @@ namespace ts {
isArgumentsLocalBinding,
getExternalModuleFileFromDeclaration,
getTypeReferenceDirectivesForEntityName,
getTypeReferenceDirectivesForSymbol
getTypeReferenceDirectivesForSymbol,
isLiteralConstDeclaration,
writeLiteralConstValue
};
// defined here to avoid outer scope pollution
@ -20101,10 +20223,29 @@ namespace ts {
}
}
function isStringOrNumberLiteralExpression(expr: Expression) {
return expr.kind === SyntaxKind.StringLiteral || expr.kind === SyntaxKind.NumericLiteral ||
expr.kind === SyntaxKind.PrefixUnaryExpression && (<PrefixUnaryExpression>expr).operator === SyntaxKind.MinusToken &&
(<PrefixUnaryExpression>expr).operand.kind === SyntaxKind.NumericLiteral;
}
function checkGrammarVariableDeclaration(node: VariableDeclaration) {
if (node.parent.parent.kind !== SyntaxKind.ForInStatement && node.parent.parent.kind !== SyntaxKind.ForOfStatement) {
if (isInAmbientContext(node)) {
if (node.initializer) {
if (isConst(node) && !node.type) {
if (!isStringOrNumberLiteralExpression(node.initializer)) {
return grammarErrorOnNode(node.initializer, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal);
}
}
else {
// Error on equals token which immediate precedes the initializer
const equalsTokenLength = "=".length;
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength,
equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
}
}
if (node.initializer && !(isConst(node) && isStringOrNumberLiteralExpression(node.initializer))) {
// Error on equals token which immediate precedes the initializer
const equalsTokenLength = "=".length;
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength,

View File

@ -408,6 +408,7 @@ namespace ts {
"es2017": "lib.es2017.d.ts",
// Host only
"dom": "lib.dom.d.ts",
"dom.iterable": "lib.dom.iterable.d.ts",
"webworker": "lib.webworker.d.ts",
"scripthost": "lib.scripthost.d.ts",
// ES2015 Or ESNext By-feature options

View File

@ -1142,6 +1142,10 @@ namespace ts {
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {
emitTypeOfVariableDeclarationFromTypeLiteral(node);
}
else if (resolver.isLiteralConstDeclaration(node)) {
write(" = ");
resolver.writeLiteralConstValue(node, writer);
}
else if (!hasModifier(node, ModifierFlags.Private)) {
writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
}

View File

@ -819,6 +819,10 @@
"category": "Error",
"code": 1253
},
"A 'const' initializer in an ambient context must be a string or numeric literal.": {
"category": "Error",
"code": 1254
},
"'with' statements are not allowed in an async function block.": {
"category": "Error",
"code": 1300
@ -1959,6 +1963,10 @@
"category": "Error",
"code": 2695
},
"The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?": {
"category": "Error",
"code": 2696
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",

View File

@ -416,7 +416,7 @@ namespace ts {
return node;
}
export function createObjectLiteral(properties?: ObjectLiteralElement[], location?: TextRange, multiLine?: boolean) {
export function createObjectLiteral(properties?: ObjectLiteralElementLike[], location?: TextRange, multiLine?: boolean) {
const node = <ObjectLiteralExpression>createNode(SyntaxKind.ObjectLiteralExpression, location);
node.properties = createNodeArray(properties);
if (multiLine) {
@ -425,7 +425,7 @@ namespace ts {
return node;
}
export function updateObjectLiteral(node: ObjectLiteralExpression, properties: ObjectLiteralElement[]) {
export function updateObjectLiteral(node: ObjectLiteralExpression, properties: ObjectLiteralElementLike[]) {
if (node.properties !== properties) {
return updateNode(createObjectLiteral(properties, node, node.multiLine), node);
}
@ -2069,7 +2069,7 @@ namespace ts {
}
}
export function createExpressionForObjectLiteralElement(node: ObjectLiteralExpression, property: ObjectLiteralElement, receiver: Expression): Expression {
export function createExpressionForObjectLiteralElementLike(node: ObjectLiteralExpression, property: ObjectLiteralElementLike, receiver: Expression): Expression {
switch (property.kind) {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
@ -2086,7 +2086,7 @@ namespace ts {
function createExpressionForAccessorDeclaration(properties: NodeArray<Declaration>, property: AccessorDeclaration, receiver: Expression, multiLine: boolean) {
const { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(properties, property);
if (property === firstAccessor) {
const properties: ObjectLiteralElement[] = [];
const properties: ObjectLiteralElementLike[] = [];
if (getAccessor) {
const getterFunction = createFunctionExpression(
/*asteriskToken*/ undefined,

View File

@ -4121,7 +4121,7 @@ namespace ts {
return undefined;
}
function parseObjectLiteralElement(): ObjectLiteralElement {
function parseObjectLiteralElement(): ObjectLiteralElementLike {
const fullStart = scanner.getStartPos();
const decorators = parseDecorators();
const modifiers = parseModifiers();

View File

@ -126,14 +126,22 @@ namespace ts {
context: TransformationContext,
node: VariableDeclaration,
value?: Expression,
visitor?: (node: Node) => VisitResult<Node>) {
visitor?: (node: Node) => VisitResult<Node>,
recordTempVariable?: (node: Identifier) => void) {
const declarations: VariableDeclaration[] = [];
let pendingAssignments: Expression[];
flattenDestructuring(context, node, value, node, emitAssignment, emitTempVariableAssignment, visitor);
return declarations;
function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) {
if (pendingAssignments) {
pendingAssignments.push(value);
value = inlineExpressions(pendingAssignments);
pendingAssignments = undefined;
}
const declaration = createVariableDeclaration(name, /*type*/ undefined, value, location);
declaration.original = original;
@ -146,8 +154,19 @@ namespace ts {
}
function emitTempVariableAssignment(value: Expression, location: TextRange) {
const name = createTempVariable(/*recordTempVariable*/ undefined);
emitAssignment(name, value, location, /*original*/ undefined);
const name = createTempVariable(recordTempVariable);
if (recordTempVariable) {
const assignment = createAssignment(name, value, location);
if (pendingAssignments) {
pendingAssignments.push(assignment);
}
else {
pendingAssignments = [assignment];
}
}
else {
emitAssignment(name, value, location, /*original*/ undefined);
}
return name;
}
}

View File

@ -187,12 +187,12 @@ namespace ts {
let currentText: string;
let currentParent: Node;
let currentNode: Node;
let enclosingVariableStatement: VariableStatement;
let enclosingBlockScopeContainer: Node;
let enclosingBlockScopeContainerParent: Node;
let containingNonArrowFunction: FunctionLikeDeclaration | ClassElement;
/** Tracks the container that determines whether `super.x` is a static. */
let superScopeContainer: FunctionLikeDeclaration | ClassElement;
let enclosingFunction: FunctionLikeDeclaration;
let enclosingNonArrowFunction: FunctionLikeDeclaration;
let enclosingNonAsyncFunctionBody: FunctionLikeDeclaration | ClassElement;
/**
* Used to track if we are emitting body of the converted loop
@ -206,11 +206,6 @@ namespace ts {
*/
let enabledSubstitutions: ES6SubstitutionFlags;
/**
* This is used to determine whether we need to emit `_this` instead of `this`.
*/
let useCapturedThis: boolean;
return transformSourceFile;
function transformSourceFile(node: SourceFile) {
@ -230,13 +225,14 @@ namespace ts {
}
function saveStateAndInvoke<T>(node: Node, f: (node: Node) => T): T {
const savedContainingNonArrowFunction = containingNonArrowFunction;
const savedSuperScopeContainer = superScopeContainer;
const savedCurrentParent = currentParent;
const savedCurrentNode = currentNode;
const savedEnclosingFunction = enclosingFunction;
const savedEnclosingNonArrowFunction = enclosingNonArrowFunction;
const savedEnclosingNonAsyncFunctionBody = enclosingNonAsyncFunctionBody;
const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer;
const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent;
const savedEnclosingVariableStatement = enclosingVariableStatement;
const savedCurrentParent = currentParent;
const savedCurrentNode = currentNode;
const savedConvertedLoopState = convertedLoopState;
if (nodeStartsNewLexicalEnvironment(node)) {
// don't treat content of nodes that start new lexical environment as part of converted loop copy
@ -247,12 +243,14 @@ namespace ts {
const visited = f(node);
convertedLoopState = savedConvertedLoopState;
containingNonArrowFunction = savedContainingNonArrowFunction;
superScopeContainer = savedSuperScopeContainer;
currentParent = savedCurrentParent;
currentNode = savedCurrentNode;
enclosingFunction = savedEnclosingFunction;
enclosingNonArrowFunction = savedEnclosingNonArrowFunction;
enclosingNonAsyncFunctionBody = savedEnclosingNonAsyncFunctionBody;
enclosingBlockScopeContainer = savedEnclosingBlockScopeContainer;
enclosingBlockScopeContainerParent = savedEnclosingBlockScopeContainerParent;
enclosingVariableStatement = savedEnclosingVariableStatement;
currentParent = savedCurrentParent;
currentNode = savedCurrentNode;
return visited;
}
@ -275,22 +273,13 @@ namespace ts {
}
function visitorForConvertedLoopWorker(node: Node): VisitResult<Node> {
const savedUseCapturedThis = useCapturedThis;
if (nodeStartsNewLexicalEnvironment(node)) {
useCapturedThis = false;
}
let result: VisitResult<Node>;
if (shouldCheckNode(node)) {
result = visitJavaScript(node);
}
else {
result = visitNodesInConvertedLoop(node);
}
useCapturedThis = savedUseCapturedThis;
return result;
}
@ -344,7 +333,7 @@ namespace ts {
return visitFunctionExpression(<FunctionExpression>node);
case SyntaxKind.VariableDeclaration:
return visitVariableDeclaration(<VariableDeclaration>node, /*offset*/ undefined);
return visitVariableDeclaration(<VariableDeclaration>node);
case SyntaxKind.Identifier:
return visitIdentifier(<Identifier>node);
@ -433,30 +422,44 @@ namespace ts {
}
function onBeforeVisitNode(node: Node) {
const currentGrandparent = currentParent;
currentParent = currentNode;
currentNode = node;
if (currentParent) {
if (isBlockScope(currentParent, currentGrandparent)) {
enclosingBlockScopeContainer = currentParent;
enclosingBlockScopeContainerParent = currentGrandparent;
if (currentNode) {
if (isBlockScope(currentNode, currentParent)) {
enclosingBlockScopeContainer = currentNode;
enclosingBlockScopeContainerParent = currentParent;
}
switch (currentParent.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.Constructor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.FunctionDeclaration:
containingNonArrowFunction = <FunctionLikeDeclaration>currentParent;
if (!(containingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody)) {
superScopeContainer = containingNonArrowFunction;
if (isFunctionLike(currentNode)) {
enclosingFunction = currentNode;
if (currentNode.kind !== SyntaxKind.ArrowFunction) {
enclosingNonArrowFunction = currentNode;
if (!(currentNode.emitFlags & NodeEmitFlags.AsyncFunctionBody)) {
enclosingNonAsyncFunctionBody = currentNode;
}
}
}
// keep track of the enclosing variable statement when in the context of
// variable statements, variable declarations, binding elements, and binding
// patterns.
switch (currentNode.kind) {
case SyntaxKind.VariableStatement:
enclosingVariableStatement = <VariableStatement>currentNode;
break;
case SyntaxKind.VariableDeclarationList:
case SyntaxKind.VariableDeclaration:
case SyntaxKind.BindingElement:
case SyntaxKind.ObjectBindingPattern:
case SyntaxKind.ArrayBindingPattern:
break;
default:
enclosingVariableStatement = undefined;
}
}
currentParent = currentNode;
currentNode = node;
}
function visitSwitchStatement(node: SwitchStatement): SwitchStatement {
@ -492,9 +495,8 @@ namespace ts {
function visitThisKeyword(node: Node): Node {
Debug.assert(convertedLoopState !== undefined);
if (useCapturedThis) {
// if useCapturedThis is true then 'this' keyword is contained inside an arrow function.
if (enclosingFunction && enclosingFunction.kind === SyntaxKind.ArrowFunction) {
// if the enclosing function is an ArrowFunction is then we use the captured 'this' keyword.
convertedLoopState.containsLexicalThis = true;
return node;
}
@ -1430,7 +1432,7 @@ namespace ts {
setNodeEmitFlags(propertyName, NodeEmitFlags.NoComments | NodeEmitFlags.NoLeadingSourceMap);
setSourceMapRange(propertyName, firstAccessor.name);
const properties: ObjectLiteralElement[] = [];
const properties: ObjectLiteralElementLike[] = [];
if (getAccessor) {
const getterFunction = transformFunctionLikeToExpression(getAccessor, /*location*/ undefined, /*name*/ undefined);
setSourceMapRange(getterFunction, getSourceMapRange(getAccessor));
@ -1477,12 +1479,7 @@ namespace ts {
enableSubstitutionsForCapturedThis();
}
const savedUseCapturedThis = useCapturedThis;
useCapturedThis = true;
const func = transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined);
useCapturedThis = savedUseCapturedThis;
setNodeEmitFlags(func, NodeEmitFlags.CapturesThis);
return func;
}
@ -1505,7 +1502,7 @@ namespace ts {
return setOriginalNode(
createFunctionDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
node.modifiers,
node.asteriskToken,
node.name,
/*typeParameters*/ undefined,
@ -1525,9 +1522,9 @@ namespace ts {
* @param name The name of the new FunctionExpression.
*/
function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: TextRange, name: Identifier): FunctionExpression {
const savedContainingNonArrowFunction = containingNonArrowFunction;
const savedContainingNonArrowFunction = enclosingNonArrowFunction;
if (node.kind !== SyntaxKind.ArrowFunction) {
containingNonArrowFunction = node;
enclosingNonArrowFunction = node;
}
const expression = setOriginalNode(
@ -1543,7 +1540,7 @@ namespace ts {
/*original*/ node
);
containingNonArrowFunction = savedContainingNonArrowFunction;
enclosingNonArrowFunction = savedContainingNonArrowFunction;
return expression;
}
@ -1834,13 +1831,13 @@ namespace ts {
*
* @param node A VariableDeclaration node.
*/
function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration, offset: number) {
function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration) {
// For binding pattern names that lack initializers there is no point to emit
// explicit initializer since downlevel codegen for destructuring will fail
// in the absence of initializer so all binding elements will say uninitialized
const name = node.name;
if (isBindingPattern(name)) {
return visitVariableDeclaration(node, offset);
return visitVariableDeclaration(node);
}
if (!node.initializer && shouldEmitExplicitInitializerForLetDeclaration(node)) {
@ -1857,10 +1854,13 @@ namespace ts {
*
* @param node A VariableDeclaration node.
*/
function visitVariableDeclaration(node: VariableDeclaration, offset: number): VisitResult<VariableDeclaration> {
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
// If we are here it is because the name contains a binding pattern.
if (isBindingPattern(node.name)) {
return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor);
const recordTempVariablesInLine = !enclosingVariableStatement
|| !hasModifier(enclosingVariableStatement, ModifierFlags.Export);
return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor,
recordTempVariablesInLine ? undefined : hoistVariableDeclaration);
}
return visitEachChild(node, visitor, context);
@ -1936,7 +1936,7 @@ namespace ts {
// Note also that because an extra statement is needed to assign to the LHS,
// for-of bodies are always emitted as blocks.
const expression = node.expression;
const expression = visitNode(node.expression, visitor, isExpression);
const initializer = node.initializer;
const statements: Statement[] = [];
@ -2111,7 +2111,7 @@ namespace ts {
temp,
setNodeEmitFlags(
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialProperties),
visitNodes(properties, visitor, isObjectLiteralElementLike, 0, numInitialProperties),
/*location*/ undefined,
node.multiLine
),
@ -2185,7 +2185,7 @@ namespace ts {
case SyntaxKind.ForOfStatement:
const initializer = (<ForStatement | ForInStatement | ForOfStatement>node).initializer;
if (initializer && initializer.kind === SyntaxKind.VariableDeclarationList) {
loopInitializer = <VariableDeclarationList>(<ForStatement | ForInStatement | ForOfStatement>node).initializer;
loopInitializer = <VariableDeclarationList>initializer;
}
break;
}
@ -2237,8 +2237,8 @@ namespace ts {
}
const isAsyncBlockContainingAwait =
containingNonArrowFunction
&& (containingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody) !== 0
enclosingNonArrowFunction
&& (enclosingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody) !== 0
&& (node.statement.transformFlags & TransformFlags.ContainsYield) !== 0;
let loopBodyFlags: NodeEmitFlags = 0;
@ -2645,7 +2645,7 @@ namespace ts {
*
* @param node A MethodDeclaration node.
*/
function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElement {
function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElementLike {
// We should only get here for methods on an object literal with regular identifier names.
// Methods on classes are handled in visitClassDeclaration/visitClassExpression.
// Methods with computed property names are handled in visitObjectLiteralExpression.
@ -2664,7 +2664,7 @@ namespace ts {
*
* @param node A ShorthandPropertyAssignment node.
*/
function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement {
function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
return createPropertyAssignment(
node.name,
getSynthesizedClone(node.name),
@ -3026,9 +3026,9 @@ namespace ts {
* Visits the `super` keyword
*/
function visitSuperKeyword(node: PrimaryExpression): LeftHandSideExpression {
return superScopeContainer
&& isClassElement(superScopeContainer)
&& !hasModifier(superScopeContainer, ModifierFlags.Static)
return enclosingNonAsyncFunctionBody
&& isClassElement(enclosingNonAsyncFunctionBody)
&& !hasModifier(enclosingNonAsyncFunctionBody, ModifierFlags.Static)
&& currentParent.kind !== SyntaxKind.CallExpression
? createPropertyAccess(createIdentifier("_super"), "prototype")
: createIdentifier("_super");
@ -3053,17 +3053,16 @@ namespace ts {
* @param node The node to be printed.
*/
function onEmitNode(node: Node, emit: (node: Node) => void) {
const savedUseCapturedThis = useCapturedThis;
const savedEnclosingFunction = enclosingFunction;
if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && isFunctionLike(node)) {
// If we are tracking a captured `this`, push a bit that indicates whether the
// containing function is an arrow function.
useCapturedThis = (getNodeEmitFlags(node) & NodeEmitFlags.CapturesThis) !== 0;
// If we are tracking a captured `this`, keep track of the enclosing function.
enclosingFunction = node;
}
previousOnEmitNode(node, emit);
useCapturedThis = savedUseCapturedThis;
enclosingFunction = savedEnclosingFunction;
}
/**
@ -3191,7 +3190,9 @@ namespace ts {
* @param node The ThisKeyword node.
*/
function substituteThisKeyword(node: PrimaryExpression): PrimaryExpression {
if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && useCapturedThis) {
if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis
&& enclosingFunction
&& enclosingFunction.emitFlags & NodeEmitFlags.CapturesThis) {
return createIdentifier("_this", /*location*/ node);
}

View File

@ -573,11 +573,11 @@ namespace ts {
operationLocations = undefined;
state = createTempVariable(/*recordTempVariable*/ undefined);
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
// Build the generator
startLexicalEnvironment();
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
transformAndEmitStatements(body.statements, statementOffset);
const buildResult = build();
@ -615,6 +615,11 @@ namespace ts {
return undefined;
}
else {
// Do not hoist custom prologues.
if (node.emitFlags & NodeEmitFlags.CustomPrologue) {
return node;
}
for (const variable of node.declarationList.declarations) {
hoistVariableDeclaration(<Identifier>variable.name);
}
@ -1020,7 +1025,7 @@ namespace ts {
const temp = declareLocal();
emitAssignment(temp,
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialProperties),
visitNodes(properties, visitor, isObjectLiteralElementLike, 0, numInitialProperties),
/*location*/ undefined,
multiLine
)
@ -1030,13 +1035,13 @@ namespace ts {
expressions.push(multiLine ? startOnNewLine(getMutableClone(temp)) : temp);
return inlineExpressions(expressions);
function reduceProperty(expressions: Expression[], property: ObjectLiteralElement) {
function reduceProperty(expressions: Expression[], property: ObjectLiteralElementLike) {
if (containsYield(property) && expressions.length > 0) {
emitStatement(createStatement(inlineExpressions(expressions)));
expressions = [];
}
const expression = createExpressionForObjectLiteralElement(node, property, temp);
const expression = createExpressionForObjectLiteralElementLike(node, property, temp);
const visited = visitNode(expression, visitor, isExpression);
if (visited) {
if (multiLine) {

View File

@ -850,7 +850,7 @@ namespace ts {
return node;
}
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement {
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
const name = node.name;
const exportedOrImportedName = substituteExpressionIdentifier(name);
if (exportedOrImportedName !== name) {

View File

@ -288,7 +288,7 @@ namespace ts {
}
}
const exportedNames: ObjectLiteralElement[] = [];
const exportedNames: ObjectLiteralElementLike[] = [];
if (exportedLocalNames) {
for (const exportedLocalName of exportedLocalNames) {
// write name of exported declaration, i.e 'export var x...'
@ -1107,7 +1107,7 @@ namespace ts {
return false;
}
function hasExportedReferenceInObjectDestructuringElement(node: ObjectLiteralElement): boolean {
function hasExportedReferenceInObjectDestructuringElement(node: ObjectLiteralElementLike): boolean {
if (isShorthandPropertyAssignment(node)) {
return isExportedBinding(node.name);
}

View File

@ -1560,7 +1560,7 @@ namespace ts {
function addNewTypeMetadata(node: Declaration, decoratorExpressions: Expression[]) {
if (compilerOptions.emitDecoratorMetadata) {
let properties: ObjectLiteralElement[];
let properties: ObjectLiteralElementLike[];
if (shouldAddTypeMetadata(node)) {
(properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeTypeOfNode(node))));
}
@ -3273,7 +3273,7 @@ namespace ts {
return node;
}
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement {
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) {
const name = node.name;
const exportedName = trySubstituteNamespaceExportedName(name);

View File

@ -667,7 +667,7 @@ namespace ts {
}
function printHelp() {
let output = "";
const output: string[] = [];
// We want to align our "syntax" and "examples" commands to a certain margin.
const syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
@ -678,17 +678,17 @@ namespace ts {
let syntax = makePadding(marginLength - syntaxLength);
syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]";
output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax);
output += sys.newLine + sys.newLine;
output.push(getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax));
output.push(sys.newLine + sys.newLine);
// Build up the list of examples.
const padding = makePadding(marginLength);
output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine;
output += padding + "tsc --outFile file.js file.ts" + sys.newLine;
output += padding + "tsc @args.txt" + sys.newLine;
output += sys.newLine;
output.push(getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine);
output.push(padding + "tsc --outFile file.js file.ts" + sys.newLine);
output.push(padding + "tsc @args.txt" + sys.newLine);
output.push(sys.newLine);
output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine;
output.push(getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine);
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
const optsList = filter(optionDeclarations.slice(), v => !v.experimental);
@ -755,18 +755,20 @@ namespace ts {
const usage = usageColumn[i];
const description = descriptionColumn[i];
const kindsList = optionsDescriptionMap[description];
output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine;
output.push(usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine);
if (kindsList) {
output += makePadding(marginLength + 4);
output.push(makePadding(marginLength + 4));
for (const kind of kindsList) {
output += kind + " ";
output.push(kind + " ");
}
output += sys.newLine;
output.push(sys.newLine);
}
}
sys.write(output);
for (const line of output) {
sys.write(line);
}
return;
function getParamType(option: CommandLineOption) {

View File

@ -648,6 +648,8 @@ namespace ts {
name?: PropertyName;
}
export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration;
// @kind(SyntaxKind.PropertyAssignment)
export interface PropertyAssignment extends ObjectLiteralElement {
_propertyAssignmentBrand: any;
@ -1048,10 +1050,19 @@ namespace ts {
expression: Expression;
}
/**
* This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to
* ObjectLiteralExpression in that it contains array of properties; however, JSXAttributes' properties can only be
* JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type
* ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.)
**/
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElement> extends PrimaryExpression, Declaration {
properties: NodeArray<T>;
}
// An ObjectLiteralExpression is the declaration node for an anonymous symbol.
// @kind(SyntaxKind.ObjectLiteralExpression)
export interface ObjectLiteralExpression extends PrimaryExpression, Declaration {
properties: NodeArray<ObjectLiteralElement>;
export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase<ObjectLiteralElementLike> {
/* @internal */
multiLine?: boolean;
}
@ -2156,6 +2167,8 @@ namespace ts {
getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): SourceFile;
getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): string[];
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[];
isLiteralConstDeclaration(node: VariableDeclaration): boolean;
writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter): void;
}
export const enum SymbolFlags {
@ -2372,7 +2385,7 @@ namespace ts {
/* @internal */
ObjectLiteral = 1 << 23, // Originates in an object literal
/* @internal */
FreshObjectLiteral = 1 << 24, // Fresh object literal type
FreshLiteral = 1 << 24, // Fresh literal type
/* @internal */
ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type
/* @internal */
@ -2385,6 +2398,7 @@ namespace ts {
/* @internal */
Nullable = Undefined | Null,
Literal = StringLiteral | NumberLiteral | BooleanLiteral | EnumLiteral,
StringOrNumberLiteral = StringLiteral | NumberLiteral,
/* @internal */
DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null,
PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean,
@ -2426,12 +2440,15 @@ namespace ts {
/* @internal */
// Intrinsic types (TypeFlags.Intrinsic)
export interface IntrinsicType extends Type {
intrinsicName: string; // Name of intrinsic type
intrinsicName: string; // Name of intrinsic type
}
// String literal types (TypeFlags.StringLiteral)
// Numeric literal types (TypeFlags.NumberLiteral)
export interface LiteralType extends Type {
text: string; // Text of string literal
text: string; // Text of literal
freshType?: LiteralType; // Fresh version of type
regularType?: LiteralType; // Regular version of type
}
// Enum types (TypeFlags.Enum)
@ -2441,7 +2458,7 @@ namespace ts {
// Enum types (TypeFlags.EnumLiteral)
export interface EnumLiteralType extends LiteralType {
baseType: EnumType & UnionType;
baseType: EnumType & UnionType; // Base enum type
}
// Object types (TypeFlags.ObjectType)

View File

@ -3736,7 +3736,7 @@ namespace ts {
|| kind === SyntaxKind.SemicolonClassElement;
}
export function isObjectLiteralElement(node: Node): node is ObjectLiteralElement {
export function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike {
const kind = node.kind;
return kind === SyntaxKind.PropertyAssignment
|| kind === SyntaxKind.ShorthandPropertyAssignment

View File

@ -772,7 +772,7 @@ namespace ts {
case SyntaxKind.ObjectLiteralExpression:
return updateObjectLiteral(<ObjectLiteralExpression>node,
visitNodes((<ObjectLiteralExpression>node).properties, visitor, isObjectLiteralElement));
visitNodes((<ObjectLiteralExpression>node).properties, visitor, isObjectLiteralElementLike));
case SyntaxKind.PropertyAccessExpression:
return updatePropertyAccess(<PropertyAccessExpression>node,

View File

@ -136,9 +136,7 @@ class CompilerBaselineRunner extends RunnerBase {
// check errors
it("Correct errors for " + fileName, () => {
if (this.errors) {
Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors);
}
Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors);
});
it (`Correct module resolution tracing for ${fileName}`, () => {

View File

@ -1407,7 +1407,7 @@ namespace Harness {
export function doErrorBaseline(baselinePath: string, inputFiles: TestFile[], errors: ts.Diagnostic[]) {
Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?$/, ".errors.txt"), (): string => {
if (errors.length === 0) {
if (!errors || (errors.length === 0)) {
/* tslint:disable:no-null-keyword */
return null;
/* tslint:enable:no-null-keyword */

View File

@ -60,7 +60,7 @@ namespace ts {
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
@ -263,7 +263,7 @@ namespace ts {
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
@ -283,7 +283,7 @@ namespace ts {
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

View File

@ -233,7 +233,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@ -264,7 +264,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@ -295,7 +295,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@ -326,7 +326,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]

View File

@ -1,4 +1,4 @@
/// <reference path="lib.dom.generated.d.ts" />
/// <reference path="lib.dom.d.ts" />
interface DOMTokenList {
[Symbol.iterator](): IterableIterator<string>;

View File

@ -0,0 +1,72 @@
//// [ambientConstLiterals.ts]
function f<T>(x: T): T {
return x;
}
enum E { A, B, C }
const c1 = "abc";
const c2 = 123;
const c3 = c1;
const c4 = c2;
const c5 = f(123);
const c6 = f(-123);
const c7 = true;
const c8 = E.A;
const c9 = { x: "abc" };
const c10 = [123];
const c11 = "abc" + "def";
const c12 = 123 + 456;
const c13 = Math.random() > 0.5 ? "abc" : "def";
const c14 = Math.random() > 0.5 ? 123 : 456;
//// [ambientConstLiterals.js]
function f(x) {
return x;
}
var E;
(function (E) {
E[E["A"] = 0] = "A";
E[E["B"] = 1] = "B";
E[E["C"] = 2] = "C";
})(E || (E = {}));
var c1 = "abc";
var c2 = 123;
var c3 = c1;
var c4 = c2;
var c5 = f(123);
var c6 = f(-123);
var c7 = true;
var c8 = E.A;
var c9 = { x: "abc" };
var c10 = [123];
var c11 = "abc" + "def";
var c12 = 123 + 456;
var c13 = Math.random() > 0.5 ? "abc" : "def";
var c14 = Math.random() > 0.5 ? 123 : 456;
//// [ambientConstLiterals.d.ts]
declare function f<T>(x: T): T;
declare enum E {
A = 0,
B = 1,
C = 2,
}
declare const c1 = "abc";
declare const c2 = 123;
declare const c3 = "abc";
declare const c4 = 123;
declare const c5 = 123;
declare const c6 = -123;
declare const c7: boolean;
declare const c8: E;
declare const c9: {
x: string;
};
declare const c10: number[];
declare const c11: string;
declare const c12: number;
declare const c13: string;
declare const c14: number;

View File

@ -0,0 +1,75 @@
=== tests/cases/compiler/ambientConstLiterals.ts ===
function f<T>(x: T): T {
>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0))
>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11))
>x : Symbol(x, Decl(ambientConstLiterals.ts, 1, 14))
>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11))
>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11))
return x;
>x : Symbol(x, Decl(ambientConstLiterals.ts, 1, 14))
}
enum E { A, B, C }
>E : Symbol(E, Decl(ambientConstLiterals.ts, 3, 1))
>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8))
>B : Symbol(E.B, Decl(ambientConstLiterals.ts, 5, 11))
>C : Symbol(E.C, Decl(ambientConstLiterals.ts, 5, 14))
const c1 = "abc";
>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 7, 5))
const c2 = 123;
>c2 : Symbol(c2, Decl(ambientConstLiterals.ts, 8, 5))
const c3 = c1;
>c3 : Symbol(c3, Decl(ambientConstLiterals.ts, 9, 5))
>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 7, 5))
const c4 = c2;
>c4 : Symbol(c4, Decl(ambientConstLiterals.ts, 10, 5))
>c2 : Symbol(c2, Decl(ambientConstLiterals.ts, 8, 5))
const c5 = f(123);
>c5 : Symbol(c5, Decl(ambientConstLiterals.ts, 11, 5))
>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0))
const c6 = f(-123);
>c6 : Symbol(c6, Decl(ambientConstLiterals.ts, 12, 5))
>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0))
const c7 = true;
>c7 : Symbol(c7, Decl(ambientConstLiterals.ts, 13, 5))
const c8 = E.A;
>c8 : Symbol(c8, Decl(ambientConstLiterals.ts, 14, 5))
>E.A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8))
>E : Symbol(E, Decl(ambientConstLiterals.ts, 3, 1))
>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8))
const c9 = { x: "abc" };
>c9 : Symbol(c9, Decl(ambientConstLiterals.ts, 15, 5))
>x : Symbol(x, Decl(ambientConstLiterals.ts, 15, 12))
const c10 = [123];
>c10 : Symbol(c10, Decl(ambientConstLiterals.ts, 16, 5))
const c11 = "abc" + "def";
>c11 : Symbol(c11, Decl(ambientConstLiterals.ts, 17, 5))
const c12 = 123 + 456;
>c12 : Symbol(c12, Decl(ambientConstLiterals.ts, 18, 5))
const c13 = Math.random() > 0.5 ? "abc" : "def";
>c13 : Symbol(c13, Decl(ambientConstLiterals.ts, 19, 5))
>Math.random : Symbol(Math.random, Decl(lib.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.d.ts, --, --))
const c14 = Math.random() > 0.5 ? 123 : 456;
>c14 : Symbol(c14, Decl(ambientConstLiterals.ts, 20, 5))
>Math.random : Symbol(Math.random, Decl(lib.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>random : Symbol(Math.random, Decl(lib.d.ts, --, --))

View File

@ -0,0 +1,105 @@
=== tests/cases/compiler/ambientConstLiterals.ts ===
function f<T>(x: T): T {
>f : <T>(x: T) => T
>T : T
>x : T
>T : T
>T : T
return x;
>x : T
}
enum E { A, B, C }
>E : E
>A : E.A
>B : E.B
>C : E.C
const c1 = "abc";
>c1 : "abc"
>"abc" : "abc"
const c2 = 123;
>c2 : 123
>123 : 123
const c3 = c1;
>c3 : "abc"
>c1 : "abc"
const c4 = c2;
>c4 : 123
>c2 : 123
const c5 = f(123);
>c5 : 123
>f(123) : 123
>f : <T>(x: T) => T
>123 : 123
const c6 = f(-123);
>c6 : -123
>f(-123) : -123
>f : <T>(x: T) => T
>-123 : -123
>123 : 123
const c7 = true;
>c7 : true
>true : true
const c8 = E.A;
>c8 : E.A
>E.A : E.A
>E : typeof E
>A : E.A
const c9 = { x: "abc" };
>c9 : { x: string; }
>{ x: "abc" } : { x: string; }
>x : string
>"abc" : "abc"
const c10 = [123];
>c10 : number[]
>[123] : number[]
>123 : 123
const c11 = "abc" + "def";
>c11 : string
>"abc" + "def" : string
>"abc" : "abc"
>"def" : "def"
const c12 = 123 + 456;
>c12 : number
>123 + 456 : number
>123 : 123
>456 : 456
const c13 = Math.random() > 0.5 ? "abc" : "def";
>c13 : "abc" | "def"
>Math.random() > 0.5 ? "abc" : "def" : "abc" | "def"
>Math.random() > 0.5 : boolean
>Math.random() : number
>Math.random : () => number
>Math : Math
>random : () => number
>0.5 : 0.5
>"abc" : "abc"
>"def" : "def"
const c14 = Math.random() > 0.5 ? 123 : 456;
>c14 : 123 | 456
>Math.random() > 0.5 ? 123 : 456 : 123 | 456
>Math.random() > 0.5 : boolean
>Math.random() : number
>Math.random : () => number
>Math : Math
>random : () => number
>0.5 : 0.5
>123 : 123
>456 : 456

View File

@ -46,7 +46,7 @@ class parser {
>this : this
>options : IOptions[]
>sort : (compareFn?: (a: IOptions, b: IOptions) => number) => IOptions[]
>function(a, b) { var aName = a.name.toLowerCase(); var bName = b.name.toLowerCase(); if (aName > bName) { return 1; } else if (aName < bName) { return -1; } else { return 0; } } : (a: IOptions, b: IOptions) => 0 | 1 | -1
>function(a, b) { var aName = a.name.toLowerCase(); var bName = b.name.toLowerCase(); if (aName > bName) { return 1; } else if (aName < bName) { return -1; } else { return 0; } } : (a: IOptions, b: IOptions) => 1 | -1 | 0
>a : IOptions
>b : IOptions

View File

@ -0,0 +1,38 @@
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'exec' is missing in type 'Object'.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'String'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'charAt' is missing in type 'Object'.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,5): error TS2322: Type 'Number' is not assignable to type 'String'.
Property 'charAt' is missing in type 'Number'.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'name' is missing in type 'Object'.
==== tests/cases/compiler/assigningFromObjectToAnythingElse.ts (4 errors) ====
var x: Object;
var y: RegExp;
y = x;
~
!!! error TS2322: Type 'Object' is not assignable to type 'RegExp'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Property 'exec' is missing in type 'Object'.
var a: String = Object.create<Object>("");
~
!!! error TS2322: Type 'Object' is not assignable to type 'String'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Property 'charAt' is missing in type 'Object'.
var c: String = Object.create<Number>(1);
~
!!! error TS2322: Type 'Number' is not assignable to type 'String'.
!!! error TS2322: Property 'charAt' is missing in type 'Number'.
var w: Error = new Object();
~
!!! error TS2322: Type 'Object' is not assignable to type 'Error'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Property 'name' is missing in type 'Object'.

View File

@ -0,0 +1,18 @@
//// [assigningFromObjectToAnythingElse.ts]
var x: Object;
var y: RegExp;
y = x;
var a: String = Object.create<Object>("");
var c: String = Object.create<Number>(1);
var w: Error = new Object();
//// [assigningFromObjectToAnythingElse.js]
var x;
var y;
y = x;
var a = Object.create("");
var c = Object.create(1);
var w = new Object();

View File

@ -9,7 +9,7 @@ var bar = async (): Promise<void> => {
//// [asyncArrowFunction7_es5.js]
var _this = this;
var bar = function () { return __awaiter(_this, void 0, void 0, function () {
_this = this;
var _this = this;
var foo;
return __generator(this, function (_a) {
foo = function (a) {
@ -22,4 +22,4 @@ var bar = function () { return __awaiter(_this, void 0, void 0, function () {
};
return [2 /*return*/];
});
}); var _this; };
}); };

View File

@ -30,7 +30,7 @@ var derived2: Derived2;
var r2 = true ? 1 : '';
>r2 : string | number
>true ? 1 : '' : "" | 1
>true ? 1 : '' : 1 | ""
>true : true
>1 : 1
>'' : ""

View File

@ -0,0 +1,21 @@
//// [blockScopedBindingCaptureThisInFunction.ts]
// https://github.com/Microsoft/TypeScript/issues/11038
() => function () {
for (let someKey in {}) {
this.helloWorld();
() => someKey;
}
};
//// [blockScopedBindingCaptureThisInFunction.js]
// https://github.com/Microsoft/TypeScript/issues/11038
(function () { return function () {
var _loop_1 = function (someKey) {
this_1.helloWorld();
(function () { return someKey; });
};
var this_1 = this;
for (var someKey in {}) {
_loop_1(someKey);
}
}; });

View File

@ -0,0 +1,11 @@
=== tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts ===
// https://github.com/Microsoft/TypeScript/issues/11038
() => function () {
for (let someKey in {}) {
>someKey : Symbol(someKey, Decl(blockScopedBindingCaptureThisInFunction.ts, 2, 12))
this.helloWorld();
() => someKey;
>someKey : Symbol(someKey, Decl(blockScopedBindingCaptureThisInFunction.ts, 2, 12))
}
};

View File

@ -0,0 +1,21 @@
=== tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts ===
// https://github.com/Microsoft/TypeScript/issues/11038
() => function () {
>() => function () { for (let someKey in {}) { this.helloWorld(); () => someKey; }} : () => () => void
>function () { for (let someKey in {}) { this.helloWorld(); () => someKey; }} : () => void
for (let someKey in {}) {
>someKey : string
>{} : {}
this.helloWorld();
>this.helloWorld() : any
>this.helloWorld : any
>this : any
>helloWorld : any
() => someKey;
>() => someKey : () => string
>someKey : string
}
};

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ var b = false ? undefined : 0;
var c = false ? 1 : 0;
>c : number
>false ? 1 : 0 : 0 | 1
>false ? 1 : 0 : 1 | 0
>false : false
>1 : 1
>0 : 0

View File

@ -1,13 +1,12 @@
tests/cases/compiler/constDeclarations-ambient-errors.ts(3,27): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(4,26): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(5,18): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(5,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
tests/cases/compiler/constDeclarations-ambient-errors.ts(5,37): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(5,51): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(8,14): error TS1039: Initializers are not allowed in ambient contexts.
tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: Initializers are not allowed in ambient contexts.
==== tests/cases/compiler/constDeclarations-ambient-errors.ts (7 errors) ====
==== tests/cases/compiler/constDeclarations-ambient-errors.ts (6 errors) ====
// error: no intialization expected in ambient declarations
declare const c1: boolean = true;
@ -17,8 +16,8 @@ tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: In
~
!!! error TS1039: Initializers are not allowed in ambient contexts.
declare const c3 = null, c4 :string = "", c5: any = 0;
~
!!! error TS1039: Initializers are not allowed in ambient contexts.
~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
~
!!! error TS1039: Initializers are not allowed in ambient contexts.
~
@ -26,8 +25,6 @@ tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: In
declare module M {
const c6 = 0;
~
!!! error TS1039: Initializers are not allowed in ambient contexts.
const c7: number = 7;
~
!!! error TS1039: Initializers are not allowed in ambient contexts.

View File

@ -25,6 +25,6 @@ for (const c5 = 0, c6 = 0; c5 < c6;) {
//// [constDeclarations.d.ts]
declare const c1: false;
declare const c1: boolean;
declare const c2: number;
declare const c3: 0, c4: string, c5: any;
declare const c3 = 0, c4: string, c5: any;

View File

@ -20,7 +20,7 @@ var M;
//// [constDeclarations2.d.ts]
declare module M {
const c1: false;
const c1: boolean;
const c2: number;
const c3: 0, c4: string, c5: any;
const c3 = 0, c4: string, c5: any;
}

View File

@ -0,0 +1,53 @@
//// [controlFlowWithIncompleteTypes.ts]
// Repro from #11000
declare var cond: boolean;
function foo1() {
let x: string | number | boolean = 0;
while (cond) {
if (typeof x === "string") {
x = x.slice();
}
else {
x = "abc";
}
}
}
function foo2() {
let x: string | number | boolean = 0;
while (cond) {
if (typeof x === "number") {
x = "abc";
}
else {
x = x.slice();
}
}
}
//// [controlFlowWithIncompleteTypes.js]
// Repro from #11000
function foo1() {
var x = 0;
while (cond) {
if (typeof x === "string") {
x = x.slice();
}
else {
x = "abc";
}
}
}
function foo2() {
var x = 0;
while (cond) {
if (typeof x === "number") {
x = "abc";
}
else {
x = x.slice();
}
}
}

View File

@ -0,0 +1,55 @@
=== tests/cases/compiler/controlFlowWithIncompleteTypes.ts ===
// Repro from #11000
declare var cond: boolean;
>cond : Symbol(cond, Decl(controlFlowWithIncompleteTypes.ts, 2, 11))
function foo1() {
>foo1 : Symbol(foo1, Decl(controlFlowWithIncompleteTypes.ts, 2, 26))
let x: string | number | boolean = 0;
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7))
while (cond) {
>cond : Symbol(cond, Decl(controlFlowWithIncompleteTypes.ts, 2, 11))
if (typeof x === "string") {
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7))
x = x.slice();
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7))
>x.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7))
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
}
else {
x = "abc";
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7))
}
}
}
function foo2() {
>foo2 : Symbol(foo2, Decl(controlFlowWithIncompleteTypes.ts, 14, 1))
let x: string | number | boolean = 0;
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7))
while (cond) {
>cond : Symbol(cond, Decl(controlFlowWithIncompleteTypes.ts, 2, 11))
if (typeof x === "number") {
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7))
x = "abc";
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7))
}
else {
x = x.slice();
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7))
>x.slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7))
>slice : Symbol(String.slice, Decl(lib.d.ts, --, --))
}
}
}

View File

@ -0,0 +1,71 @@
=== tests/cases/compiler/controlFlowWithIncompleteTypes.ts ===
// Repro from #11000
declare var cond: boolean;
>cond : boolean
function foo1() {
>foo1 : () => void
let x: string | number | boolean = 0;
>x : string | number | boolean
>0 : 0
while (cond) {
>cond : boolean
if (typeof x === "string") {
>typeof x === "string" : boolean
>typeof x : string
>x : string | number
>"string" : "string"
x = x.slice();
>x = x.slice() : string
>x : string | number | boolean
>x.slice() : string
>x.slice : (start?: number, end?: number) => string
>x : string
>slice : (start?: number, end?: number) => string
}
else {
x = "abc";
>x = "abc" : "abc"
>x : string | number | boolean
>"abc" : "abc"
}
}
}
function foo2() {
>foo2 : () => void
let x: string | number | boolean = 0;
>x : string | number | boolean
>0 : 0
while (cond) {
>cond : boolean
if (typeof x === "number") {
>typeof x === "number" : boolean
>typeof x : string
>x : string | number
>"number" : "number"
x = "abc";
>x = "abc" : "abc"
>x : string | number | boolean
>"abc" : "abc"
}
else {
x = x.slice();
>x = x.slice() : string
>x : string | number | boolean
>x.slice() : string
>x.slice : (start?: number, end?: number) => string
>x : string
>slice : (start?: number, end?: number) => string
}
}
}

View File

@ -25,7 +25,7 @@ var y = [() => new c()];
var k: (() => c) | string = (() => new c()) || "";
>k : string | (() => c)
>c : c
>(() => new c()) || "" : "" | (() => c)
>(() => new c()) || "" : (() => c) | ""
>(() => new c()) : () => c
>() => new c() : () => c
>new c() : c

View File

@ -45,7 +45,7 @@ var Foo = (function () {
//// [declarationEmitClassMemberNameConflict2.d.ts]
declare const Bar: "bar";
declare const Bar = "bar";
declare enum Hello {
World = 0,
}

View File

@ -11,15 +11,15 @@ export default function f3(d = 0) {
//// [es6modulekindWithES5Target6.js]
function f1(d) {
export function f1(d) {
if (d === void 0) { d = 0; }
}
function f2() {
export function f2() {
var arg = [];
for (var _i = 0; _i < arguments.length; _i++) {
arg[_i - 0] = arguments[_i];
}
}
function f3(d) {
export default function f3(d) {
if (d === void 0) { d = 0; }
}

View File

@ -0,0 +1,13 @@
//// [forOfTransformsExpression.ts]
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {
}
//// [forOfTransformsExpression.js]
// https://github.com/Microsoft/TypeScript/issues/11024
var items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var _i = 0, _a = items.sort(function (a, b) { return a.name.localeCompare(b.name); }); _i < _a.length; _i++) {
var item = _a[_i];
}

View File

@ -0,0 +1,25 @@
=== tests/cases/compiler/forOfTransformsExpression.ts ===
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
>items : Symbol(items, Decl(forOfTransformsExpression.ts, 1, 3))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 29))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 44))
for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {
>item : Symbol(item, Decl(forOfTransformsExpression.ts, 2, 8))
>items.sort : Symbol(Array.sort, Decl(lib.d.ts, --, --))
>items : Symbol(items, Decl(forOfTransformsExpression.ts, 1, 3))
>sort : Symbol(Array.sort, Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(forOfTransformsExpression.ts, 2, 29))
>b : Symbol(b, Decl(forOfTransformsExpression.ts, 2, 31))
>a.name.localeCompare : Symbol(String.localeCompare, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a.name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>a : Symbol(a, Decl(forOfTransformsExpression.ts, 2, 29))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>localeCompare : Symbol(String.localeCompare, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>b.name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>b : Symbol(b, Decl(forOfTransformsExpression.ts, 2, 31))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
}

View File

@ -0,0 +1,35 @@
=== tests/cases/compiler/forOfTransformsExpression.ts ===
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
>items : { name: string; }[]
>[{ name: "A" }, { name: "C" }, { name: "B" }] : { name: string; }[]
>{ name: "A" } : { name: string; }
>name : string
>"A" : "A"
>{ name: "C" } : { name: string; }
>name : string
>"C" : "C"
>{ name: "B" } : { name: string; }
>name : string
>"B" : "B"
for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {
>item : { name: string; }
>items.sort((a, b) => a.name.localeCompare(b.name)) : { name: string; }[]
>items.sort : (compareFn?: (a: { name: string; }, b: { name: string; }) => number) => { name: string; }[]
>items : { name: string; }[]
>sort : (compareFn?: (a: { name: string; }, b: { name: string; }) => number) => { name: string; }[]
>(a, b) => a.name.localeCompare(b.name) : (a: { name: string; }, b: { name: string; }) => number
>a : { name: string; }
>b : { name: string; }
>a.name.localeCompare(b.name) : number
>a.name.localeCompare : { (that: string): number; (that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; }
>a.name : string
>a : { name: string; }
>name : string
>localeCompare : { (that: string): number; (that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; }
>b.name : string
>b : { name: string; }
>name : string
}

View File

@ -4,7 +4,7 @@
// it is an error if there is no single BCT, these are error cases
function f1() {
>f1 : () => "" | 1
>f1 : () => 1 | ""
if (true) {
>true : true
@ -19,7 +19,7 @@ function f1() {
}
function f2() {
>f2 : () => "" | 1 | 2
>f2 : () => 1 | "" | 2
if (true) {
>true : true
@ -40,7 +40,7 @@ function f2() {
}
function f3() {
>f3 : () => "" | 1
>f3 : () => 1 | ""
try {
return 1;
@ -55,7 +55,7 @@ function f3() {
}
function f4() {
>f4 : () => "" | 1
>f4 : () => 1 | ""
try {
return 1;
@ -72,7 +72,7 @@ function f4() {
}
function f5() {
>f5 : () => "" | 1
>f5 : () => 1 | ""
return 1;
>1 : 1

View File

@ -7,5 +7,5 @@
//// [functionsWithModifiersInBlocks1.js]
{
function f() { }
export function f() { }
}

View File

@ -2,7 +2,8 @@ tests/cases/compiler/intTypeCheck.ts(35,6): error TS2304: Cannot find name 'p'.
tests/cases/compiler/intTypeCheck.ts(71,6): error TS2304: Cannot find name 'p'.
tests/cases/compiler/intTypeCheck.ts(85,5): error TS2386: Overload signatures must all be optional or required.
tests/cases/compiler/intTypeCheck.ts(99,5): error TS2322: Type 'Object' is not assignable to type 'i1'.
Property 'p' is missing in type 'Object'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'p' is missing in type 'Object'.
tests/cases/compiler/intTypeCheck.ts(100,16): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(101,5): error TS2322: Type 'Base' is not assignable to type 'i1'.
Property 'p' is missing in type 'Base'.
@ -15,7 +16,8 @@ tests/cases/compiler/intTypeCheck.ts(107,17): error TS2351: Cannot use 'new' wit
tests/cases/compiler/intTypeCheck.ts(112,5): error TS2322: Type '{}' is not assignable to type 'i2'.
Type '{}' provides no match for the signature '(): any'
tests/cases/compiler/intTypeCheck.ts(113,5): error TS2322: Type 'Object' is not assignable to type 'i2'.
Type 'Object' provides no match for the signature '(): any'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature '(): any'
tests/cases/compiler/intTypeCheck.ts(114,17): error TS2350: Only a void function can be called with the 'new' keyword.
tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not assignable to type 'i2'.
Type 'Base' provides no match for the signature '(): any'
@ -26,7 +28,8 @@ tests/cases/compiler/intTypeCheck.ts(121,17): error TS2351: Cannot use 'new' wit
tests/cases/compiler/intTypeCheck.ts(126,5): error TS2322: Type '{}' is not assignable to type 'i3'.
Type '{}' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(127,5): error TS2322: Type 'Object' is not assignable to type 'i3'.
Type 'Object' provides no match for the signature 'new (): any'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(129,5): error TS2322: Type 'Base' is not assignable to type 'i3'.
Type 'Base' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is not assignable to type 'i3'.
@ -43,7 +46,8 @@ tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' wit
tests/cases/compiler/intTypeCheck.ts(154,5): error TS2322: Type '{}' is not assignable to type 'i5'.
Property 'p' is missing in type '{}'.
tests/cases/compiler/intTypeCheck.ts(155,5): error TS2322: Type 'Object' is not assignable to type 'i5'.
Property 'p' is missing in type 'Object'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'p' is missing in type 'Object'.
tests/cases/compiler/intTypeCheck.ts(156,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(157,5): error TS2322: Type 'Base' is not assignable to type 'i5'.
Property 'p' is missing in type 'Base'.
@ -56,7 +60,8 @@ tests/cases/compiler/intTypeCheck.ts(163,17): error TS2351: Cannot use 'new' wit
tests/cases/compiler/intTypeCheck.ts(168,5): error TS2322: Type '{}' is not assignable to type 'i6'.
Type '{}' provides no match for the signature '(): any'
tests/cases/compiler/intTypeCheck.ts(169,5): error TS2322: Type 'Object' is not assignable to type 'i6'.
Type 'Object' provides no match for the signature '(): any'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature '(): any'
tests/cases/compiler/intTypeCheck.ts(170,17): error TS2350: Only a void function can be called with the 'new' keyword.
tests/cases/compiler/intTypeCheck.ts(171,5): error TS2322: Type 'Base' is not assignable to type 'i6'.
Type 'Base' provides no match for the signature '(): any'
@ -69,7 +74,8 @@ tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' wit
tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'.
Type '{}' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'.
Type 'Object' provides no match for the signature 'new (): any'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(185,17): error TS2352: Type 'Base' cannot be converted to type 'i7'.
Type 'Base' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'.
@ -193,7 +199,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
var obj2: i1 = new Object();
~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'i1'.
!!! error TS2322: Property 'p' is missing in type 'Object'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Property 'p' is missing in type 'Object'.
var obj3: i1 = new obj0;
~~~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -229,7 +236,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
var obj13: i2 = new Object();
~~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'i2'.
!!! error TS2322: Type 'Object' provides no match for the signature '(): any'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature '(): any'
var obj14: i2 = new obj11;
~~~~~~~~~
!!! error TS2350: Only a void function can be called with the 'new' keyword.
@ -262,7 +270,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
var obj24: i3 = new Object();
~~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'i3'.
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
var obj25: i3 = new obj22;
var obj26: i3 = new Base;
~~~~~
@ -320,7 +329,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
var obj46: i5 = new Object();
~~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'i5'.
!!! error TS2322: Property 'p' is missing in type 'Object'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Property 'p' is missing in type 'Object'.
var obj47: i5 = new obj44;
~~~~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -356,7 +366,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
var obj57: i6 = new Object();
~~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'i6'.
!!! error TS2322: Type 'Object' provides no match for the signature '(): any'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature '(): any'
var obj58: i6 = new obj55;
~~~~~~~~~
!!! error TS2350: Only a void function can be called with the 'new' keyword.
@ -392,7 +403,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
var obj68: i7 = new Object();
~~~~~
!!! error TS2322: Type 'Object' is not assignable to type 'i7'.
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
var obj69: i7 = new obj66;
var obj70: i7 = <i7>new Base;
~~~~~~~~~~~~

View File

@ -0,0 +1,174 @@
//// [literalTypeWidening.ts]
// Widening vs. non-widening literal types
function f1() {
const c1 = "hello"; // Widening type "hello"
let v1 = c1; // Type string
const c2 = c1; // Widening type "hello"
let v2 = c2; // Type string
const c3: "hello" = "hello"; // Type "hello"
let v3 = c3; // Type "hello"
const c4: "hello" = c1; // Type "hello"
let v4 = c4; // Type "hello"
}
function f2(cond: boolean) {
const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
const c2: "foo" | "bar" = c1; // "foo" | "bar"
const c3 = cond ? c1 : c2; // "foo" | "bar"
const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz"
let v1 = c1; // string
let v2 = c2; // "foo" | "bar"
let v3 = c3; // "foo" | "bar"
let v4 = c4; // string
let v5 = c5; // "foo" | "bar" | "baz"
}
function f3() {
const c1 = 123; // Widening type 123
let v1 = c1; // Type number
const c2 = c1; // Widening type 123
let v2 = c2; // Type number
const c3: 123 = 123; // Type 123
let v3 = c3; // Type 123
const c4: 123 = c1; // Type 123
let v4 = c4; // Type 123
}
function f4(cond: boolean) {
const c1 = cond ? 123 : 456; // widening 123 | widening 456
const c2: 123 | 456 = c1; // 123 | 456
const c3 = cond ? c1 : c2; // 123 | 456
const c4 = cond ? c3 : 789; // 123 | 456 | widening 789
const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789
let v1 = c1; // number
let v2 = c2; // 123 | 456
let v3 = c3; // 123 | 456
let v4 = c4; // number
let v5 = c5; // 123 | 456 | 789
}
function f5() {
const c1 = "foo";
let v1 = c1;
const c2: "foo" = "foo";
let v2 = c2;
const c3 = "foo" as "foo";
let v3 = c3;
const c4 = <"foo">"foo";
let v4 = c4;
}
// Repro from #10898
type FAILURE = "FAILURE";
const FAILURE = "FAILURE";
type Result<T> = T | FAILURE;
function doWork<T>(): Result<T> {
return FAILURE;
}
function isSuccess<T>(result: Result<T>): result is T {
return !isFailure(result);
}
function isFailure<T>(result: Result<T>): result is FAILURE {
return result === FAILURE;
}
function increment(x: number): number {
return x + 1;
}
let result = doWork<number>();
if (isSuccess(result)) {
increment(result);
}
// Repro from #10898
type TestEvent = "onmouseover" | "onmouseout";
function onMouseOver(): TestEvent { return "onmouseover"; }
let x = onMouseOver();
//// [literalTypeWidening.js]
// Widening vs. non-widening literal types
function f1() {
var c1 = "hello"; // Widening type "hello"
var v1 = c1; // Type string
var c2 = c1; // Widening type "hello"
var v2 = c2; // Type string
var c3 = "hello"; // Type "hello"
var v3 = c3; // Type "hello"
var c4 = c1; // Type "hello"
var v4 = c4; // Type "hello"
}
function f2(cond) {
var c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
var c2 = c1; // "foo" | "bar"
var c3 = cond ? c1 : c2; // "foo" | "bar"
var c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
var c5 = c4; // "foo" | "bar" | "baz"
var v1 = c1; // string
var v2 = c2; // "foo" | "bar"
var v3 = c3; // "foo" | "bar"
var v4 = c4; // string
var v5 = c5; // "foo" | "bar" | "baz"
}
function f3() {
var c1 = 123; // Widening type 123
var v1 = c1; // Type number
var c2 = c1; // Widening type 123
var v2 = c2; // Type number
var c3 = 123; // Type 123
var v3 = c3; // Type 123
var c4 = c1; // Type 123
var v4 = c4; // Type 123
}
function f4(cond) {
var c1 = cond ? 123 : 456; // widening 123 | widening 456
var c2 = c1; // 123 | 456
var c3 = cond ? c1 : c2; // 123 | 456
var c4 = cond ? c3 : 789; // 123 | 456 | widening 789
var c5 = c4; // 123 | 456 | 789
var v1 = c1; // number
var v2 = c2; // 123 | 456
var v3 = c3; // 123 | 456
var v4 = c4; // number
var v5 = c5; // 123 | 456 | 789
}
function f5() {
var c1 = "foo";
var v1 = c1;
var c2 = "foo";
var v2 = c2;
var c3 = "foo";
var v3 = c3;
var c4 = "foo";
var v4 = c4;
}
var FAILURE = "FAILURE";
function doWork() {
return FAILURE;
}
function isSuccess(result) {
return !isFailure(result);
}
function isFailure(result) {
return result === FAILURE;
}
function increment(x) {
return x + 1;
}
var result = doWork();
if (isSuccess(result)) {
increment(result);
}
function onMouseOver() { return "onmouseover"; }
var x = onMouseOver();

View File

@ -0,0 +1,285 @@
=== tests/cases/conformance/types/literal/literalTypeWidening.ts ===
// Widening vs. non-widening literal types
function f1() {
>f1 : Symbol(f1, Decl(literalTypeWidening.ts, 0, 0))
const c1 = "hello"; // Widening type "hello"
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
let v1 = c1; // Type string
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 4, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
const c2 = c1; // Widening type "hello"
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 5, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
let v2 = c2; // Type string
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 6, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 5, 9))
const c3: "hello" = "hello"; // Type "hello"
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 7, 9))
let v3 = c3; // Type "hello"
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 8, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 7, 9))
const c4: "hello" = c1; // Type "hello"
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 9, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
let v4 = c4; // Type "hello"
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 10, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 9, 9))
}
function f2(cond: boolean) {
>f2 : Symbol(f2, Decl(literalTypeWidening.ts, 11, 1))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
const c2: "foo" | "bar" = c1; // "foo" | "bar"
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
const c3 = cond ? c1 : c2; // "foo" | "bar"
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9))
const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9))
const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz"
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 18, 9))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9))
let v1 = c1; // string
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 19, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
let v2 = c2; // "foo" | "bar"
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 20, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9))
let v3 = c3; // "foo" | "bar"
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 21, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9))
let v4 = c4; // string
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 22, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9))
let v5 = c5; // "foo" | "bar" | "baz"
>v5 : Symbol(v5, Decl(literalTypeWidening.ts, 23, 7))
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 18, 9))
}
function f3() {
>f3 : Symbol(f3, Decl(literalTypeWidening.ts, 24, 1))
const c1 = 123; // Widening type 123
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
let v1 = c1; // Type number
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 28, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
const c2 = c1; // Widening type 123
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 29, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
let v2 = c2; // Type number
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 30, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 29, 9))
const c3: 123 = 123; // Type 123
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 31, 9))
let v3 = c3; // Type 123
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 32, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 31, 9))
const c4: 123 = c1; // Type 123
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 33, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
let v4 = c4; // Type 123
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 34, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 33, 9))
}
function f4(cond: boolean) {
>f4 : Symbol(f4, Decl(literalTypeWidening.ts, 35, 1))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
const c1 = cond ? 123 : 456; // widening 123 | widening 456
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
const c2: 123 | 456 = c1; // 123 | 456
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
const c3 = cond ? c1 : c2; // 123 | 456
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9))
const c4 = cond ? c3 : 789; // 123 | 456 | widening 789
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9))
const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 42, 9))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9))
let v1 = c1; // number
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 43, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
let v2 = c2; // 123 | 456
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 44, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9))
let v3 = c3; // 123 | 456
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 45, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9))
let v4 = c4; // number
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 46, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9))
let v5 = c5; // 123 | 456 | 789
>v5 : Symbol(v5, Decl(literalTypeWidening.ts, 47, 7))
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 42, 9))
}
function f5() {
>f5 : Symbol(f5, Decl(literalTypeWidening.ts, 48, 1))
const c1 = "foo";
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 51, 9))
let v1 = c1;
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 52, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 51, 9))
const c2: "foo" = "foo";
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 53, 9))
let v2 = c2;
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 54, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 53, 9))
const c3 = "foo" as "foo";
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 55, 9))
let v3 = c3;
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 56, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 55, 9))
const c4 = <"foo">"foo";
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9))
let v4 = c4;
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 58, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9))
}
// Repro from #10898
type FAILURE = "FAILURE";
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
const FAILURE = "FAILURE";
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
type Result<T> = T | FAILURE;
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12))
>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12))
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
function doWork<T>(): Result<T> {
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29))
>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16))
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16))
return FAILURE;
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
}
function isSuccess<T>(result: Result<T>): result is T {
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1))
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
return !isFailure(result);
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1))
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
}
function isFailure<T>(result: Result<T>): result is FAILURE {
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1))
>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
return result === FAILURE;
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
}
function increment(x: number): number {
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1))
>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19))
return x + 1;
>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19))
}
let result = doWork<number>();
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29))
if (isSuccess(result)) {
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1))
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
increment(result);
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1))
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
}
// Repro from #10898
type TestEvent = "onmouseover" | "onmouseout";
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1))
function onMouseOver(): TestEvent { return "onmouseover"; }
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46))
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1))
let x = onMouseOver();
>x : Symbol(x, Decl(literalTypeWidening.ts, 96, 3))
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46))

View File

@ -0,0 +1,318 @@
=== tests/cases/conformance/types/literal/literalTypeWidening.ts ===
// Widening vs. non-widening literal types
function f1() {
>f1 : () => void
const c1 = "hello"; // Widening type "hello"
>c1 : "hello"
>"hello" : "hello"
let v1 = c1; // Type string
>v1 : string
>c1 : "hello"
const c2 = c1; // Widening type "hello"
>c2 : "hello"
>c1 : "hello"
let v2 = c2; // Type string
>v2 : string
>c2 : "hello"
const c3: "hello" = "hello"; // Type "hello"
>c3 : "hello"
>"hello" : "hello"
let v3 = c3; // Type "hello"
>v3 : "hello"
>c3 : "hello"
const c4: "hello" = c1; // Type "hello"
>c4 : "hello"
>c1 : "hello"
let v4 = c4; // Type "hello"
>v4 : "hello"
>c4 : "hello"
}
function f2(cond: boolean) {
>f2 : (cond: boolean) => void
>cond : boolean
const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
>c1 : "foo" | "bar"
>cond ? "foo" : "bar" : "foo" | "bar"
>cond : boolean
>"foo" : "foo"
>"bar" : "bar"
const c2: "foo" | "bar" = c1; // "foo" | "bar"
>c2 : "foo" | "bar"
>c1 : "foo" | "bar"
const c3 = cond ? c1 : c2; // "foo" | "bar"
>c3 : "foo" | "bar"
>cond ? c1 : c2 : "foo" | "bar"
>cond : boolean
>c1 : "foo" | "bar"
>c2 : "foo" | "bar"
const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
>c4 : "foo" | "bar" | "baz"
>cond ? c3 : "baz" : "foo" | "bar" | "baz"
>cond : boolean
>c3 : "foo" | "bar"
>"baz" : "baz"
const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz"
>c5 : "foo" | "bar" | "baz"
>c4 : "foo" | "bar" | "baz"
let v1 = c1; // string
>v1 : string
>c1 : "foo" | "bar"
let v2 = c2; // "foo" | "bar"
>v2 : "foo" | "bar"
>c2 : "foo" | "bar"
let v3 = c3; // "foo" | "bar"
>v3 : "foo" | "bar"
>c3 : "foo" | "bar"
let v4 = c4; // string
>v4 : string
>c4 : "foo" | "bar" | "baz"
let v5 = c5; // "foo" | "bar" | "baz"
>v5 : "foo" | "bar" | "baz"
>c5 : "foo" | "bar" | "baz"
}
function f3() {
>f3 : () => void
const c1 = 123; // Widening type 123
>c1 : 123
>123 : 123
let v1 = c1; // Type number
>v1 : number
>c1 : 123
const c2 = c1; // Widening type 123
>c2 : 123
>c1 : 123
let v2 = c2; // Type number
>v2 : number
>c2 : 123
const c3: 123 = 123; // Type 123
>c3 : 123
>123 : 123
let v3 = c3; // Type 123
>v3 : 123
>c3 : 123
const c4: 123 = c1; // Type 123
>c4 : 123
>c1 : 123
let v4 = c4; // Type 123
>v4 : 123
>c4 : 123
}
function f4(cond: boolean) {
>f4 : (cond: boolean) => void
>cond : boolean
const c1 = cond ? 123 : 456; // widening 123 | widening 456
>c1 : 123 | 456
>cond ? 123 : 456 : 123 | 456
>cond : boolean
>123 : 123
>456 : 456
const c2: 123 | 456 = c1; // 123 | 456
>c2 : 123 | 456
>c1 : 123 | 456
const c3 = cond ? c1 : c2; // 123 | 456
>c3 : 123 | 456
>cond ? c1 : c2 : 123 | 456
>cond : boolean
>c1 : 123 | 456
>c2 : 123 | 456
const c4 = cond ? c3 : 789; // 123 | 456 | widening 789
>c4 : 123 | 456 | 789
>cond ? c3 : 789 : 123 | 456 | 789
>cond : boolean
>c3 : 123 | 456
>789 : 789
const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789
>c5 : 123 | 456 | 789
>c4 : 123 | 456 | 789
let v1 = c1; // number
>v1 : number
>c1 : 123 | 456
let v2 = c2; // 123 | 456
>v2 : 123 | 456
>c2 : 123 | 456
let v3 = c3; // 123 | 456
>v3 : 123 | 456
>c3 : 123 | 456
let v4 = c4; // number
>v4 : number
>c4 : 123 | 456 | 789
let v5 = c5; // 123 | 456 | 789
>v5 : 123 | 456 | 789
>c5 : 123 | 456 | 789
}
function f5() {
>f5 : () => void
const c1 = "foo";
>c1 : "foo"
>"foo" : "foo"
let v1 = c1;
>v1 : string
>c1 : "foo"
const c2: "foo" = "foo";
>c2 : "foo"
>"foo" : "foo"
let v2 = c2;
>v2 : "foo"
>c2 : "foo"
const c3 = "foo" as "foo";
>c3 : "foo"
>"foo" as "foo" : "foo"
>"foo" : "foo"
let v3 = c3;
>v3 : "foo"
>c3 : "foo"
const c4 = <"foo">"foo";
>c4 : "foo"
><"foo">"foo" : "foo"
>"foo" : "foo"
let v4 = c4;
>v4 : "foo"
>c4 : "foo"
}
// Repro from #10898
type FAILURE = "FAILURE";
>FAILURE : "FAILURE"
const FAILURE = "FAILURE";
>FAILURE : "FAILURE"
>"FAILURE" : "FAILURE"
type Result<T> = T | FAILURE;
>Result : Result<T>
>T : T
>T : T
>FAILURE : "FAILURE"
function doWork<T>(): Result<T> {
>doWork : <T>() => Result<T>
>T : T
>Result : Result<T>
>T : T
return FAILURE;
>FAILURE : "FAILURE"
}
function isSuccess<T>(result: Result<T>): result is T {
>isSuccess : <T>(result: Result<T>) => result is T
>T : T
>result : Result<T>
>Result : Result<T>
>T : T
>result : any
>T : T
return !isFailure(result);
>!isFailure(result) : boolean
>isFailure(result) : boolean
>isFailure : <T>(result: Result<T>) => result is "FAILURE"
>result : Result<T>
}
function isFailure<T>(result: Result<T>): result is FAILURE {
>isFailure : <T>(result: Result<T>) => result is "FAILURE"
>T : T
>result : Result<T>
>Result : Result<T>
>T : T
>result : any
>FAILURE : "FAILURE"
return result === FAILURE;
>result === FAILURE : boolean
>result : Result<T>
>FAILURE : "FAILURE"
}
function increment(x: number): number {
>increment : (x: number) => number
>x : number
return x + 1;
>x + 1 : number
>x : number
>1 : 1
}
let result = doWork<number>();
>result : Result<number>
>doWork<number>() : Result<number>
>doWork : <T>() => Result<T>
if (isSuccess(result)) {
>isSuccess(result) : boolean
>isSuccess : <T>(result: Result<T>) => result is T
>result : Result<number>
increment(result);
>increment(result) : number
>increment : (x: number) => number
>result : number
}
// Repro from #10898
type TestEvent = "onmouseover" | "onmouseout";
>TestEvent : TestEvent
function onMouseOver(): TestEvent { return "onmouseover"; }
>onMouseOver : () => TestEvent
>TestEvent : TestEvent
>"onmouseover" : "onmouseover"
let x = onMouseOver();
>x : TestEvent
>onMouseOver() : TestEvent
>onMouseOver : () => TestEvent

View File

@ -482,7 +482,7 @@ function f6() {
const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" };
>c1 : boolean
>true : true
>c2 : 0 | 1
>c2 : 1 | 0
>0 : 0
>c3 : "foo" | "bar"
>"foo" : "foo"
@ -552,10 +552,10 @@ class C2 {
>0 : 0
}
bar() {
>bar : () => 0 | 1
>bar : () => 1 | 0
return cond ? 0 : 1;
>cond ? 0 : 1 : 0 | 1
>cond ? 0 : 1 : 1 | 0
>cond : boolean
>0 : 0
>1 : 1

View File

@ -0,0 +1,10 @@
//// [modularizeLibrary_Dom.iterable.ts]
for (const element of document.getElementsByTagName("a")) {
element.href;
}
//// [modularizeLibrary_Dom.iterable.js]
for (const element of document.getElementsByTagName("a")) {
element.href;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,7 @@
return C;
}());
export default C;
function bee() { }
export function bee() { }
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";

View File

@ -45,7 +45,7 @@ function blah() {
return C;
}());
export default C;
function bee() { }
export function bee() { }
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";

View File

@ -370,7 +370,7 @@ function f14(x: 0 | 1 | 2, y: string) {
>y : string
var b = x || y;
>b : string | number
>b : string | 1 | 2
>x || y : string | 1 | 2
>x : 0 | 1 | 2
>y : string
@ -383,25 +383,25 @@ function f15(x: 0 | false, y: 1 | "one") {
>y : 1 | "one"
var a = x && y;
>a : number | boolean
>a : boolean | 0
>x && y : false | 0
>x : false | 0
>y : 1 | "one"
var b = y && x;
>b : number | boolean
>b : boolean | 0
>y && x : false | 0
>y : 1 | "one"
>x : false | 0
var c = x || y;
>c : string | number
>c : 1 | "one"
>x || y : 1 | "one"
>x : false | 0
>y : 1 | "one"
var d = y || x;
>d : string | number | boolean
>d : boolean | 0 | 1 | "one"
>y || x : false | 0 | 1 | "one"
>y : 1 | "one"
>x : false | 0

View File

@ -365,13 +365,13 @@ function f14(x: 0 | 1 | 2, y: string) {
>y : string
var a = x && y;
>a : string | number
>a : string | 0
>x && y : string | 0
>x : 0 | 1 | 2
>y : string
var b = x || y;
>b : string | number
>b : string | 1 | 2
>x || y : string | 1 | 2
>x : 0 | 1 | 2
>y : string
@ -384,25 +384,25 @@ function f15(x: 0 | false, y: 1 | "one") {
>y : 1 | "one"
var a = x && y;
>a : number | boolean
>a : boolean | 0
>x && y : false | 0
>x : false | 0
>y : 1 | "one"
var b = y && x;
>b : number | boolean
>b : boolean | 0
>y && x : false | 0
>y : 1 | "one"
>x : false | 0
var c = x || y;
>c : string | number
>c : 1 | "one"
>x || y : 1 | "one"
>x : false | 0
>y : 1 | "one"
var d = y || x;
>d : string | number
>d : 1 | "one"
>y || x : 1 | "one"
>y : 1 | "one"
>x : false | 0

View File

@ -3,17 +3,19 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC
Type '() => number' is not assignable to type '() => string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'.
Types of property 'toString' are incompatible.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Types of property 'toString' are incompatible.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(14,1): error TS2322: Type 'C' is not assignable to type 'Object'.
Types of property 'toString' are incompatible.
Type '() => number' is not assignable to type '() => string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(15,1): error TS2322: Type 'Object' is not assignable to type 'C'.
Types of property 'toString' are incompatible.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Types of property 'toString' are incompatible.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(20,1): error TS2322: Type '{ toString: () => void; }' is not assignable to type 'Object'.
Types of property 'toString' are incompatible.
Type '() => void' is not assignable to type '() => string'.
@ -36,9 +38,10 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC
i = o; // error
~
!!! error TS2322: Type 'Object' is not assignable to type 'I'.
!!! error TS2322: Types of property 'toString' are incompatible.
!!! error TS2322: Type '() => string' is not assignable to type '() => number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Types of property 'toString' are incompatible.
!!! error TS2322: Type '() => string' is not assignable to type '() => number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
class C {
toString(): number { return 1; }
@ -53,9 +56,10 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC
c = o; // error
~
!!! error TS2322: Type 'Object' is not assignable to type 'C'.
!!! error TS2322: Types of property 'toString' are incompatible.
!!! error TS2322: Type '() => string' is not assignable to type '() => number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Types of property 'toString' are incompatible.
!!! error TS2322: Type '() => string' is not assignable to type '() => number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var a = {
toString: () => { }

View File

@ -1,7 +1,9 @@
tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'.
Type 'Object' provides no match for the signature '(): void'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature '(): void'
tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts(14,1): error TS2322: Type 'Object' is not assignable to type '() => void'.
Type 'Object' provides no match for the signature '(): void'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature '(): void'
==== tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts (2 errors) ====
@ -15,7 +17,8 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOf
i = f;
~
!!! error TS2322: Type 'Object' is not assignable to type 'I'.
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'
var a: {
(): void
@ -24,4 +27,5 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOf
a = f;
~
!!! error TS2322: Type 'Object' is not assignable to type '() => void'.
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'

View File

@ -1,7 +1,9 @@
tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'.
Type 'Object' provides no match for the signature 'new (): any'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature 'new (): any'
tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts(14,1): error TS2322: Type 'Object' is not assignable to type 'new () => any'.
Type 'Object' provides no match for the signature 'new (): any'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature 'new (): any'
==== tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts (2 errors) ====
@ -15,7 +17,8 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMemb
i = f;
~
!!! error TS2322: Type 'Object' is not assignable to type 'I'.
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
var a: {
new(): any
@ -24,4 +27,5 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMemb
a = f;
~
!!! error TS2322: Type 'Object' is not assignable to type 'new () => any'.
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any'

View File

@ -1,7 +1,9 @@
tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'.
Type 'Object' provides no match for the signature '(): void'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature '(): void'
tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts(14,1): error TS2322: Type 'Object' is not assignable to type '() => void'.
Type 'Object' provides no match for the signature '(): void'
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' provides no match for the signature '(): void'
==== tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts (2 errors) ====
@ -15,7 +17,8 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAut
i = o;
~
!!! error TS2322: Type 'Object' is not assignable to type 'I'.
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'
var a: {
(): void
@ -24,5 +27,6 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAut
a = o;
~
!!! error TS2322: Type 'Object' is not assignable to type '() => void'.
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
!!! error TS2322: Type 'Object' provides no match for the signature '(): void'

View File

@ -8,7 +8,7 @@ export function foo() {
//// [parserModifierOnStatementInBlock3.js]
"use strict";
function foo() {
function bar() {
export function bar() {
}
}
exports.foo = foo;

View File

@ -7,6 +7,6 @@
//// [parserModifierOnStatementInBlock4.js]
{
function bar() {
export function bar() {
}
}

View File

@ -0,0 +1,19 @@
{
"scenario": "declarations_ExportNamespace",
"projectRoot": "tests/cases/projects/declarations_ExportNamespace",
"inputFiles": [
"decl.d.ts",
"useModule.ts"
],
"declaration": true,
"baselineCheck": true,
"emittedFiles": [
"useModule.js",
"useModule.d.ts"
],
"resolvedInputFiles": [
"lib.d.ts",
"decl.d.ts",
"useModule.ts"
]
}

View File

@ -0,0 +1,5 @@
declare module moduleB {
interface IUseModuleA {
a: moduleA.A;
}
}

View File

@ -0,0 +1,19 @@
{
"scenario": "declarations_ExportNamespace",
"projectRoot": "tests/cases/projects/declarations_ExportNamespace",
"inputFiles": [
"decl.d.ts",
"useModule.ts"
],
"declaration": true,
"baselineCheck": true,
"emittedFiles": [
"useModule.js",
"useModule.d.ts"
],
"resolvedInputFiles": [
"lib.d.ts",
"decl.d.ts",
"useModule.ts"
]
}

View File

@ -0,0 +1,5 @@
declare module moduleB {
interface IUseModuleA {
a: moduleA.A;
}
}

View File

@ -17,5 +17,5 @@ exports.foo = foo;
//// [shorthandOfExportedEntity01_targetES2015_CommonJS.d.ts]
export declare const test: "test";
export declare const test = "test";
export declare function foo(): void;

View File

@ -17,5 +17,5 @@ exports.foo = foo;
//// [shorthandOfExportedEntity02_targetES5_CommonJS.d.ts]
export declare const test: "test";
export declare const test = "test";
export declare function foo(): void;

View File

@ -1,16 +1,13 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts(6,5): error TS2322: Type 'string' is not assignable to type '"foo"'.
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts(8,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'.
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts (2 errors) ====
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts (1 errors) ====
declare function myRandBool(): boolean;
let a: "foo" = "foo";
let b = a || "foo";
let c: "foo" = b;
~
!!! error TS2322: Type 'string' is not assignable to type '"foo"'.
let d = b || "bar";
let e: "foo" | "bar" = d;
~

View File

@ -20,7 +20,7 @@ var e = d;
//// [stringLiteralTypesAndLogicalOrExpressions01.d.ts]
declare function myRandBool(): boolean;
declare let a: "foo";
declare let b: string;
declare let b: "foo";
declare let c: "foo";
declare let d: string;
declare let e: "foo" | "bar";

View File

@ -38,8 +38,8 @@ hResult = h("bar");
declare function foo<T extends "foo">(f: (x: T) => T): (x: T) => T;
declare function bar<T extends "foo" | "bar">(f: (x: T) => T): (x: T) => T;
declare let f: (x: "foo") => "foo";
declare let fResult: string;
declare let fResult: "foo";
declare let g: (x: "foo") => "foo";
declare let gResult: string;
declare let gResult: "foo";
declare let h: (x: "foo" | "bar") => "foo" | "bar";
declare let hResult: string;
declare let hResult: "foo" | "bar";

View File

@ -33,7 +33,7 @@ let f = foo(x => x);
>x : "foo"
let fResult = f("foo");
>fResult : string
>fResult : "foo"
>f("foo") : "foo"
>f : (x: "foo") => "foo"
>"foo" : "foo"
@ -48,7 +48,7 @@ let g = foo((x => x));
>x : "foo"
let gResult = g("foo");
>gResult : string
>gResult : "foo"
>g("foo") : "foo"
>g : (x: "foo") => "foo"
>"foo" : "foo"
@ -62,14 +62,14 @@ let h = bar(x => x);
>x : "foo" | "bar"
let hResult = h("foo");
>hResult : string
>hResult : "foo" | "bar"
>h("foo") : "foo" | "bar"
>h : (x: "foo" | "bar") => "foo" | "bar"
>"foo" : "foo"
hResult = h("bar");
>hResult = h("bar") : "foo" | "bar"
>hResult : string
>hResult : "foo" | "bar"
>h("bar") : "foo" | "bar"
>h : (x: "foo" | "bar") => "foo" | "bar"
>"bar" : "bar"

View File

@ -18,4 +18,4 @@ var fResult = f("foo");
//// [stringLiteralTypesAsTypeParameterConstraint02.d.ts]
declare function foo<T extends "foo">(f: (x: T) => T): (x: T) => T;
declare let f: (x: "foo") => "foo";
declare let fResult: string;
declare let fResult: "foo";

View File

@ -26,7 +26,7 @@ let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo");
>"foo" : "foo"
let fResult = f("foo");
>fResult : string
>fResult : "foo"
>f("foo") : "foo"
>f : (x: "foo") => "foo"
>"foo" : "foo"

View File

@ -1,26 +0,0 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(16,9): error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'.
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts (1 errors) ====
type T = "foo" | "bar" | "baz";
var x: "foo" | "bar" | "baz" = undefined;
var y: T = undefined;
if (x === "foo") {
let a = x;
}
else if (x !== "bar") {
let b = x || y;
}
else {
let c = x;
let d = y;
let e: (typeof x) | (typeof y) = c || d;
~
!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'.
}
x = y;
y = x;

View File

@ -1,62 +1,62 @@
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts ===
type T = string | "foo" | "bar" | "baz";
>T : string | "foo" | "bar" | "baz"
>T : string
var x: "foo" | "bar" | "baz" | string = undefined;
>x : string | "foo" | "bar" | "baz"
>x : string
>undefined : undefined
var y: T = undefined;
>y : string | "foo" | "bar" | "baz"
>T : string | "foo" | "bar" | "baz"
>y : string
>T : string
>undefined : undefined
if (x === "foo") {
>x === "foo" : boolean
>x : string | "foo" | "bar" | "baz"
>x : string
>"foo" : "foo"
let a = x;
>a : string
>x : string | "foo"
>x : string
}
else if (x !== "bar") {
>x !== "bar" : boolean
>x : string | "bar" | "baz"
>x : string
>"bar" : "bar"
let b = x || y;
>b : string
>x || y : string
>x : string | "baz"
>y : string | "foo" | "bar" | "baz"
>x : string
>y : string
}
else {
let c = x;
>c : string
>x : string | "bar"
>x : string
let d = y;
>d : string
>y : string | "foo" | "bar" | "baz"
>y : string
let e: (typeof x) | (typeof y) = c || d;
>e : string | "foo" | "bar" | "baz"
>x : string | "bar"
>y : string | "foo" | "bar" | "baz"
>e : string
>x : string
>y : string
>c || d : string
>c : string
>d : string
}
x = y;
>x = y : string | "foo" | "bar" | "baz"
>x : string | "foo" | "bar" | "baz"
>y : string | "foo" | "bar" | "baz"
>x = y : string
>x : string
>y : string
y = x;
>y = x : string | "foo" | "bar" | "baz"
>y : string | "foo" | "bar" | "baz"
>x : string | "foo" | "bar" | "baz"
>y = x : string
>y : string
>x : string

View File

@ -1,28 +0,0 @@
tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(16,9): error TS2322: Type 'string | number' is not assignable to type 'number | "foo" | "bar"'.
Type 'string' is not assignable to type 'number | "foo" | "bar"'.
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts (1 errors) ====
type T = number | "foo" | "bar";
var x: "foo" | "bar" | number;
var y: T = undefined;
if (x === "foo") {
let a = x;
}
else if (x !== "bar") {
let b = x || y;
}
else {
let c = x;
let d = y;
let e: (typeof x) | (typeof y) = c || d;
~
!!! error TS2322: Type 'string | number' is not assignable to type 'number | "foo" | "bar"'.
!!! error TS2322: Type 'string' is not assignable to type 'number | "foo" | "bar"'.
}
x = y;
y = x;

View File

@ -19,7 +19,7 @@ if (x === "") {
>"" : ""
let a = x;
>a : string
>a : ""
>x : ""
}
@ -29,7 +29,7 @@ if (x !== "") {
>"" : ""
let b = x;
>b : string
>b : "foo"
>x : "foo"
}
@ -39,7 +39,7 @@ if (x == "") {
>"" : ""
let c = x;
>c : string
>c : ""
>x : ""
}
@ -49,7 +49,7 @@ if (x != "") {
>"" : ""
let d = x;
>d : string
>d : "foo"
>x : "foo"
}
@ -57,7 +57,7 @@ if (x) {
>x : T
let e = x;
>e : string
>e : "foo"
>x : "foo"
}
@ -66,7 +66,7 @@ if (!x) {
>x : T
let f = x;
>f : string
>f : T
>x : T
}
@ -76,7 +76,7 @@ if (!!x) {
>x : T
let g = x;
>g : string
>g : "foo"
>x : "foo"
}
@ -87,6 +87,6 @@ if (!!!x) {
>x : T
let h = x;
>h : string
>h : T
>x : T
}

View File

@ -100,12 +100,12 @@ declare function getFalsyPrimitive(x: "number" | "string"): number | string;
declare function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
declare namespace Consts1 {
}
declare const string: "string";
declare const number: "number";
declare const boolean: "boolean";
declare const stringOrNumber: "string" | "number";
declare const stringOrBoolean: "string" | "boolean";
declare const booleanOrNumber: "number" | "boolean";
declare const stringOrBooleanOrNumber: "string" | "number" | "boolean";
declare const string = "string";
declare const number = "number";
declare const boolean = "boolean";
declare const stringOrNumber: string;
declare const stringOrBoolean: string;
declare const booleanOrNumber: string;
declare const stringOrBooleanOrNumber: string;
declare namespace Consts2 {
}

View File

@ -42,12 +42,12 @@ if (kindIs(x, "A")) {
>"A" : "A"
let a = x;
>a : string
>a : "A"
>x : "A"
}
else {
let b = x;
>b : string
>b : "B"
>x : "B"
}
@ -59,11 +59,11 @@ if (!kindIs(x, "B")) {
>"B" : "B"
let c = x;
>c : string
>c : "A"
>x : "A"
}
else {
let d = x;
>d : string
>d : "B"
>x : "B"
}

View File

@ -259,14 +259,14 @@ function f6<T extends String>(x: T) {
var r2 = true ? '' : x; // ok
>r2 : string | T
>true ? '' : x : "" | T
>true ? '' : x : T | ""
>true : true
>'' : ""
>x : T
var r2 = true ? x : ''; // ok
>r2 : string | T
>true ? x : '' : "" | T
>true ? x : '' : T | ""
>true : true
>x : T
>'' : ""

View File

@ -11,17 +11,21 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,52): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(68,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(70,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(77,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(61,5): error TS2322: Type 'string' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(63,5): error TS2322: Type 'string' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,5): error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'.
Type '"World"' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(77,5): error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'.
Type '"World"' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(87,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(88,43): error TS2345: Argument of type '"Hello"' is not assignable to parameter of type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,52): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(100,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(104,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(107,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(111,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(93,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(97,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(100,25): error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'.
Type '"World"' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(104,25): error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'.
Type '"World"' is not assignable to type '"Hello"'.
==== tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts (24 errors) ====
@ -112,30 +116,32 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
~
!!! error TS2322: Type 'string' is not assignable to type '"Hello"'.
b = takeReturnString(b);
c = takeReturnString(c);
~
!!! error TS2322: Type 'string' is not assignable to type '"Hello"'.
d = takeReturnString(d);
e = takeReturnString(e);
// Should be valid
a = takeReturnHello(a);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
b = takeReturnHello(b);
c = takeReturnHello(c);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
d = takeReturnHello(d);
e = takeReturnHello(e);
// Assignment from the returned value should cause an error.
a = takeReturnHelloWorld(a);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
~
!!! error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'.
!!! error TS2322: Type '"World"' is not assignable to type '"Hello"'.
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
~
!!! error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'.
!!! error TS2322: Type '"World"' is not assignable to type '"Hello"'.
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
}
@ -158,30 +164,32 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
~
!!! error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
~
!!! error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
!!! error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'.
!!! error TS2345: Type '"World"' is not assignable to type '"Hello"'.
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
!!! error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'.
!!! error TS2345: Type '"World"' is not assignable to type '"Hello"'.
// Both should be valid.
a = takeReturnHelloWorld(a);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
}

View File

@ -229,16 +229,16 @@ declare namespace n1 {
let e: string;
}
declare namespace n2 {
let a: string;
let a: "Hello";
let b: any;
let c: string;
let c: "Hello";
let d: any;
let e: any;
}
declare namespace n3 {
let a: string;
let a: "Hello" | "World";
let b: any;
let c: any;
let d: any;
let e: string;
let e: "Hello" | "World";
}

View File

@ -1,5 +1,6 @@
tests/cases/compiler/typeParametersShouldNotBeEqual.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'.
tests/cases/compiler/typeParametersShouldNotBeEqual.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
==== tests/cases/compiler/typeParametersShouldNotBeEqual.ts (2 errors) ====
@ -12,6 +13,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual.ts(5,5): error TS2322: Type
x = z; // Error
~
!!! error TS2322: Type 'Object' is not assignable to type 'T'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
z = x; // Ok
}

View File

@ -7,6 +7,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(7,5): error TS2322: Type
tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(8,5): error TS2322: Type 'U' is not assignable to type 'V'.
Type 'Date' is not assignable to type 'V'.
tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type 'Object' is not assignable to type 'T'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
==== tests/cases/compiler/typeParametersShouldNotBeEqual2.ts (6 errors) ====
@ -34,6 +35,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type
x = zz; // Error
~
!!! error TS2322: Type 'Object' is not assignable to type 'T'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
zz = x; // Ok
}

View File

@ -1,6 +1,8 @@
tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'.
Type 'Object' is not assignable to type 'T'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
==== tests/cases/compiler/typeParametersShouldNotBeEqual3.ts (2 errors) ====
@ -11,9 +13,11 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type
~
!!! error TS2322: Type 'U' is not assignable to type 'T'.
!!! error TS2322: Type 'Object' is not assignable to type 'T'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
x = z; // Ok
~
!!! error TS2322: Type 'Object' is not assignable to type 'T'.
!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
z = x; // Ok
}

View File

@ -512,7 +512,7 @@ _.compact([0, 1, false, 2, '', 3]);
>_.compact : <T>(list: T[]) => T[]
>_ : Underscore.Static
>compact : <T>(list: T[]) => T[]
>[0, 1, false, 2, '', 3] : (false | "" | 0 | 1 | 2 | 3)[]
>[0, 1, false, 2, '', 3] : (false | 1 | 2 | 3 | 0 | "")[]
>0 : 0
>1 : 1
>false : false

View File

@ -24,7 +24,7 @@ var species = foge[Symbol.species];
>species : symbol
var stringTag = foge[Symbol.toStringTag];
>stringTag : string
>stringTag : "SharedArrayBuffer"
>foge[Symbol.toStringTag] : "SharedArrayBuffer"
>foge : SharedArrayBuffer
>Symbol.toStringTag : symbol

View File

@ -15,7 +15,7 @@ var species = foge[Symbol.species];
>species : symbol
var stringTag = foge[Symbol.toStringTag];
>stringTag : string
>stringTag : "SharedArrayBuffer"
>foge[Symbol.toStringTag] : "SharedArrayBuffer"
>foge : SharedArrayBuffer
>Symbol.toStringTag : symbol

View File

@ -15,7 +15,7 @@ var species = foge[Symbol.species];
>species : symbol
var stringTag = foge[Symbol.toStringTag];
>stringTag : string
>stringTag : "SharedArrayBuffer"
>foge[Symbol.toStringTag] : "SharedArrayBuffer"
>foge : SharedArrayBuffer
>Symbol.toStringTag : symbol

View File

@ -0,0 +1,22 @@
// @declaration: true
function f<T>(x: T): T {
return x;
}
enum E { A, B, C }
const c1 = "abc";
const c2 = 123;
const c3 = c1;
const c4 = c2;
const c5 = f(123);
const c6 = f(-123);
const c7 = true;
const c8 = E.A;
const c9 = { x: "abc" };
const c10 = [123];
const c11 = "abc" + "def";
const c12 = 123 + 456;
const c13 = Math.random() > 0.5 ? "abc" : "def";
const c14 = Math.random() > 0.5 ? 123 : 456;

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