Merge branch 'master' of https://github.com/Microsoft/TypeScript into typedefForJsdoc

# Conflicts:
#	src/services/services.ts
This commit is contained in:
zhengbli 2016-05-02 15:11:51 -07:00
commit 9ff02b11e9
131 changed files with 3847 additions and 1861 deletions

5
.gitignore vendored
View File

@ -46,5 +46,6 @@ coverage/
internal/
**/.DS_Store
.settings
.vscode/*
!.vscode/tasks.json
**/.vs
**/.vscode
!**/.vscode/tasks.json

View File

@ -45,6 +45,7 @@
"build": "npm run build:compiler && npm run build:tests",
"build:compiler": "jake local",
"build:tests": "jake tests",
"start": "node lib/tsc",
"clean": "jake clean",
"jake": "jake",
"lint": "jake lint",

View File

@ -650,6 +650,13 @@ namespace ts {
};
}
function createFlowLoopLabel(): FlowLabel {
return {
kind: FlowKind.LoopLabel,
antecedents: undefined
};
}
function addAntecedent(label: FlowLabel, antecedent: FlowNode): void {
if (antecedent.kind !== FlowKind.Unreachable && !contains(label.antecedents, antecedent)) {
(label.antecedents || (label.antecedents = [])).push(antecedent);
@ -760,7 +767,7 @@ namespace ts {
}
function bindWhileStatement(node: WhileStatement): void {
const preWhileLabel = createFlowLabel();
const preWhileLabel = createFlowLoopLabel();
const preBodyLabel = createFlowLabel();
const postWhileLabel = createFlowLabel();
addAntecedent(preWhileLabel, currentFlow);
@ -773,7 +780,7 @@ namespace ts {
}
function bindDoStatement(node: DoStatement): void {
const preDoLabel = createFlowLabel();
const preDoLabel = createFlowLoopLabel();
const preConditionLabel = createFlowLabel();
const postDoLabel = createFlowLabel();
addAntecedent(preDoLabel, currentFlow);
@ -786,7 +793,7 @@ namespace ts {
}
function bindForStatement(node: ForStatement): void {
const preLoopLabel = createFlowLabel();
const preLoopLabel = createFlowLoopLabel();
const preBodyLabel = createFlowLabel();
const postLoopLabel = createFlowLabel();
bind(node.initializer);
@ -801,7 +808,7 @@ namespace ts {
}
function bindForInOrForOfStatement(node: ForInStatement | ForOfStatement): void {
const preLoopLabel = createFlowLabel();
const preLoopLabel = createFlowLoopLabel();
const postLoopLabel = createFlowLabel();
addAntecedent(preLoopLabel, currentFlow);
currentFlow = preLoopLabel;
@ -948,7 +955,7 @@ namespace ts {
}
function bindLabeledStatement(node: LabeledStatement): void {
const preStatementLabel = createFlowLabel();
const preStatementLabel = createFlowLoopLabel();
const postStatementLabel = createFlowLabel();
bind(node.label);
addAntecedent(preStatementLabel, currentFlow);
@ -1377,7 +1384,8 @@ namespace ts {
if (inStrictMode &&
node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord &&
node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord &&
!isIdentifierName(node)) {
!isIdentifierName(node) &&
!isInAmbientContext(node)) {
// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length) {

View File

@ -2014,7 +2014,12 @@ namespace ts {
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, flags);
}
else if (type.flags & TypeFlags.Anonymous) {
writeAnonymousType(<ObjectType>type, flags);
if (type === emptyUnionType) {
writer.writeKeyword("nothing");
}
else {
writeAnonymousType(<ObjectType>type, flags);
}
}
else if (type.flags & TypeFlags.StringLiteral) {
writer.writeStringLiteral(`"${escapeString((<StringLiteralType>type).text)}"`);
@ -4251,7 +4256,9 @@ namespace ts {
propTypes.push(getTypeOfSymbol(prop));
}
}
return getUnionType(propTypes);
if (propTypes.length) {
return getUnionType(propTypes);
}
}
return undefined;
}
@ -5506,6 +5513,10 @@ namespace ts {
return !node.typeParameters && areAllParametersUntyped && !isNullaryArrow;
}
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | MethodDeclaration {
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitiveFunctionLikeDeclaration(func);
}
function getTypeWithoutSignatures(type: Type): Type {
if (type.flags & TypeFlags.ObjectType) {
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
@ -5900,9 +5911,14 @@ namespace ts {
if (source.flags & TypeFlags.TypeParameter) {
let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
if (!constraint || constraint.flags & TypeFlags.Any) {
constraint = emptyObjectType;
}
// The constraint may need to be further instantiated with its 'this' type.
constraint = getTypeWithThisArgument(constraint, source);
// Report constraint errors only if the constraint is not the empty object type
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
@ -7329,27 +7345,29 @@ namespace ts {
}
function containsMatchingReference(source: Node, target: Node) {
while (true) {
while (source.kind === SyntaxKind.PropertyAccessExpression) {
source = (<PropertyAccessExpression>source).expression;
if (isMatchingReference(source, target)) {
return true;
}
if (source.kind !== SyntaxKind.PropertyAccessExpression) {
return false;
}
source = (<PropertyAccessExpression>source).expression;
}
return false;
}
function hasMatchingArgument(callExpression: CallExpression, target: Node) {
function isOrContainsMatchingReference(source: Node, target: Node) {
return isMatchingReference(source, target) || containsMatchingReference(source, target);
}
function hasMatchingArgument(callExpression: CallExpression, reference: Node) {
if (callExpression.arguments) {
for (const argument of callExpression.arguments) {
if (isMatchingReference(argument, target)) {
if (isOrContainsMatchingReference(reference, argument)) {
return true;
}
}
}
if (callExpression.expression.kind === SyntaxKind.PropertyAccessExpression &&
isMatchingReference((<PropertyAccessExpression>callExpression.expression).expression, target)) {
isOrContainsMatchingReference(reference, (<PropertyAccessExpression>callExpression.expression).expression)) {
return true;
}
return false;
@ -7363,12 +7381,6 @@ namespace ts {
return flowTypeCaches[flow.id] || (flowTypeCaches[flow.id] = {});
}
function isNarrowableReference(expr: Node): boolean {
return expr.kind === SyntaxKind.Identifier ||
expr.kind === SyntaxKind.ThisKeyword ||
expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
}
function typeMaybeAssignableTo(source: Type, target: Type) {
if (!(source.flags & TypeFlags.Union)) {
return isTypeAssignableTo(source, target);
@ -7559,30 +7571,12 @@ namespace ts {
getInitialTypeOfBindingElement(<BindingElement>node);
}
function getNarrowedTypeOfReference(type: Type, reference: Node) {
if (!(type.flags & TypeFlags.Narrowable) || !isNarrowableReference(reference)) {
return type;
}
const leftmostNode = getLeftmostIdentifierOrThis(reference);
if (!leftmostNode) {
return type;
}
if (leftmostNode.kind === SyntaxKind.Identifier) {
const leftmostSymbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>leftmostNode));
if (!leftmostSymbol) {
return type;
}
const declaration = leftmostSymbol.valueDeclaration;
if (!declaration || declaration.kind !== SyntaxKind.VariableDeclaration && declaration.kind !== SyntaxKind.Parameter && declaration.kind !== SyntaxKind.BindingElement) {
return type;
}
}
return getFlowTypeOfReference(reference, type, type);
}
function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType: Type) {
let key: string;
return reference.flowNode ? getTypeAtFlowNode(reference.flowNode) : declaredType;
if (!reference.flowNode || declaredType === initialType && !(declaredType.flags & TypeFlags.Narrowable)) {
return declaredType;
}
return getTypeAtFlowNode(reference.flowNode);
function getTypeAtFlowNode(flow: FlowNode): Type {
while (true) {
@ -7597,6 +7591,7 @@ namespace ts {
case FlowKind.Condition:
return getTypeAtFlowCondition(<FlowCondition>flow);
case FlowKind.Label:
case FlowKind.LoopLabel:
if ((<FlowLabel>flow).antecedents.length === 1) {
flow = (<FlowLabel>flow).antecedents[0];
continue;
@ -7635,8 +7630,7 @@ namespace ts {
// may be an assignment to a left hand part of the reference. For example, for a
// reference 'x.y.z', we may be at an assignment to 'x.y' or 'x'. In that case,
// return the declared type.
if (reference.kind === SyntaxKind.PropertyAccessExpression &&
containsMatchingReference((<PropertyAccessExpression>reference).expression, node)) {
if (containsMatchingReference(reference, node)) {
return declaredType;
}
// Assignment doesn't affect reference
@ -7644,7 +7638,8 @@ namespace ts {
}
function getTypeAtFlowCondition(flow: FlowCondition) {
return narrowType(getTypeAtFlowNode(flow.antecedent), flow.expression, flow.assumeTrue);
const type = getTypeAtFlowNode(flow.antecedent);
return type && narrowType(type, flow.expression, flow.assumeTrue);
}
function getTypeAtFlowNodeCached(flow: FlowNode) {
@ -7670,33 +7665,36 @@ namespace ts {
flowStackCount--;
// Record the result only if the cache is still empty. If checkExpressionCached was called
// during processing it is possible we've already recorded a result.
return cache[key] || (cache[key] = type);
return cache[key] || type && (cache[key] = type);
}
function getTypeAtFlowLabel(flow: FlowLabel) {
const antecedentTypes: Type[] = [];
for (const antecedent of flow.antecedents) {
const type = getTypeAtFlowNodeCached(antecedent);
if (type) {
// If the type at a particular antecedent path is the declared type and the
// reference is known to always be assigned (i.e. when declared and initial types
// are the same), there is no reason to process more antecedents since the only
// possible outcome is subtypes that will be removed in the final union type anyway.
if (type === declaredType && declaredType === initialType) {
return type;
}
if (!contains(antecedentTypes, type)) {
antecedentTypes.push(type);
}
const type = flow.kind === FlowKind.LoopLabel ?
getTypeAtFlowNodeCached(antecedent) :
getTypeAtFlowNode(antecedent);
if (!type) {
break;
}
// If the type at a particular antecedent path is the declared type and the
// reference is known to always be assigned (i.e. when declared and initial types
// are the same), there is no reason to process more antecedents since the only
// possible outcome is subtypes that will be removed in the final union type anyway.
if (type === declaredType && declaredType === initialType) {
return type;
}
if (!contains(antecedentTypes, type)) {
antecedentTypes.push(type);
}
}
return antecedentTypes.length === 0 ? declaredType :
return antecedentTypes.length === 0 ? undefined :
antecedentTypes.length === 1 ? antecedentTypes[0] :
getUnionType(antecedentTypes);
}
function narrowTypeByTruthiness(type: Type, expr: Expression, assumeTrue: boolean): Type {
return isMatchingReference(expr, reference) ? getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy) : type;
return isMatchingReference(reference, expr) ? getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy) : type;
}
function narrowTypeByBinaryExpression(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
@ -7728,7 +7726,7 @@ namespace ts {
if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) {
assumeTrue = !assumeTrue;
}
if (!strictNullChecks || !isMatchingReference(expr.left, reference)) {
if (!strictNullChecks || !isMatchingReference(reference, expr.left)) {
return type;
}
const doubleEquals = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken;
@ -7745,7 +7743,12 @@ namespace ts {
// and string literal on the right
const left = <TypeOfExpression>expr.left;
const right = <LiteralExpression>expr.right;
if (!isMatchingReference(left.expression, reference)) {
if (!isMatchingReference(reference, left.expression)) {
// For a reference of the form 'x.y', a 'typeof x === ...' type guard resets the
// narrowed type of 'y' to its declared type.
if (containsMatchingReference(reference, left.expression)) {
return declaredType;
}
return type;
}
if (expr.operatorToken.kind === SyntaxKind.ExclamationEqualsToken ||
@ -7768,8 +7771,16 @@ namespace ts {
}
function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
// Check that type is not any, assumed result is true, and we have variable symbol on the left
if (isTypeAny(type) || !isMatchingReference(expr.left, reference)) {
if (!isMatchingReference(reference, expr.left)) {
// For a reference of the form 'x.y', an 'x instanceof T' type guard resets the
// narrowed type of 'y' to its declared type.
if (containsMatchingReference(reference, expr.left)) {
return declaredType;
}
return type;
}
// We never narrow type any in an instanceof guard
if (isTypeAny(type)) {
return type;
}
@ -7844,18 +7855,26 @@ namespace ts {
}
if (isIdentifierTypePredicate(predicate)) {
const predicateArgument = callExpression.arguments[predicate.parameterIndex];
if (predicateArgument && isMatchingReference(predicateArgument, reference)) {
return getNarrowedType(type, predicate.type, assumeTrue);
if (predicateArgument) {
if (isMatchingReference(reference, predicateArgument)) {
return getNarrowedType(type, predicate.type, assumeTrue);
}
if (containsMatchingReference(reference, predicateArgument)) {
return declaredType;
}
}
}
else {
const invokedExpression = skipParenthesizedNodes(callExpression.expression);
if (invokedExpression.kind === SyntaxKind.ElementAccessExpression || invokedExpression.kind === SyntaxKind.PropertyAccessExpression) {
const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression;
const possibleReference= skipParenthesizedNodes(accessExpression.expression);
if (isMatchingReference(possibleReference, reference)) {
const possibleReference = skipParenthesizedNodes(accessExpression.expression);
if (isMatchingReference(reference, possibleReference)) {
return getNarrowedType(type, predicate.type, assumeTrue);
}
if (containsMatchingReference(reference, possibleReference)) {
return declaredType;
}
}
}
return type;
@ -7886,19 +7905,18 @@ namespace ts {
}
function getTypeOfSymbolAtLocation(symbol: Symbol, location: Node) {
// The language service will always care about the narrowed type of a symbol, because that is
// the type the language says the symbol should have.
const type = getTypeOfSymbol(symbol);
// If we have an identifier or a property access at the given location, if the location is
// an dotted name expression, and if the location is not an assignment target, obtain the type
// of the expression (which will reflect control flow analysis). If the expression indeed
// resolved to the given symbol, return the narrowed type.
if (location.kind === SyntaxKind.Identifier) {
if (isRightSideOfQualifiedNameOrPropertyAccess(location)) {
location = location.parent;
}
// If location is an identifier or property access that references the given
// symbol, use the location as the reference with respect to which we narrow.
if (isExpression(location) && !isAssignmentTarget(location)) {
checkExpression(<Expression>location);
const type = checkExpression(<Expression>location);
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
return getNarrowedTypeOfReference(type, <IdentifierOrPropertyAccess>location);
return type;
}
}
}
@ -7907,7 +7925,7 @@ namespace ts {
// to it at the given location. Since we have no control flow information for the
// hypotherical reference (control flow information is created and attached by the
// binder), we simply return the declared type of the symbol.
return type;
return getTypeOfSymbol(symbol);
}
function skipParenthesizedNodes(expression: Expression): Expression {
@ -7973,12 +7991,9 @@ namespace ts {
return type;
}
const declaration = localOrExportSymbol.valueDeclaration;
const defaultsToDeclaredType = !strictNullChecks || !declaration ||
declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
if (defaultsToDeclaredType && !(type.flags & TypeFlags.Narrowable)) {
return type;
}
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType);
if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) {
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
@ -8201,6 +8216,21 @@ namespace ts {
captureLexicalThis(node, container);
}
if (isFunctionLike(container)) {
// If this is a function in a JS file, it might be a class method. Check if it's the RHS
// of a x.prototype.y = function [name]() { .... }
if (container.kind === SyntaxKind.FunctionExpression &&
isInJavaScriptFile(container.parent) &&
getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) {
// Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container')
const className = (((container.parent as BinaryExpression) // x.prototype.y = f
.left as PropertyAccessExpression) // x.prototype.y
.expression as PropertyAccessExpression) // x.prototype
.expression; // x
const classSymbol = checkExpression(className).symbol;
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
return getInferredClassType(classSymbol);
}
}
const type = getContextuallyTypedThisType(container);
if (type) {
return type;
@ -8209,19 +8239,11 @@ namespace ts {
if (signature.thisType) {
return signature.thisType;
}
if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
// Note: this works because object literal methods are deferred,
// which means that the type of the containing object literal is already known.
const type = checkExpressionCached(<ObjectLiteralExpression>container.parent);
if (type) {
return type;
}
}
}
if (isClassLike(container.parent)) {
const symbol = getSymbolOfNode(container.parent);
const type = container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : (<InterfaceType>getDeclaredTypeOfSymbol(symbol)).thisType;
return getNarrowedTypeOfReference(type, node);
return getFlowTypeOfReference(node, type, type);
}
if (isInJavaScriptFile(node)) {
@ -8229,22 +8251,6 @@ namespace ts {
if (type && type !== unknownType) {
return type;
}
// If this is a function in a JS file, it might be a class method. Check if it's the RHS
// of a x.prototype.y = function [name]() { .... }
if (container.kind === SyntaxKind.FunctionExpression) {
if (getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) {
// Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container')
const className = (((container.parent as BinaryExpression) // x.prototype.y = f
.left as PropertyAccessExpression) // x.prototype.y
.expression as PropertyAccessExpression) // x.prototype
.expression; // x
const classSymbol = checkExpression(className).symbol;
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
return getInferredClassType(classSymbol);
}
}
}
}
if (compilerOptions.noImplicitThis) {
@ -8469,9 +8475,7 @@ namespace ts {
}
function getContextuallyTypedThisType(func: FunctionLikeDeclaration): Type {
if ((isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
isContextSensitive(func) &&
func.kind !== SyntaxKind.ArrowFunction) {
if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) {
const contextualSignature = getContextualSignature(func);
if (contextualSignature) {
return contextualSignature.thisType;
@ -8484,24 +8488,21 @@ namespace ts {
// Return contextual type of parameter or undefined if no contextual type is available
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
const func = parameter.parent;
if (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) {
if (isContextSensitive(func)) {
const contextualSignature = getContextualSignature(func);
if (contextualSignature) {
if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
const contextualSignature = getContextualSignature(func);
if (contextualSignature) {
const funcHasRestParameters = hasRestParameter(func);
const len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
const indexOfParameter = indexOf(func.parameters, parameter);
if (indexOfParameter < len) {
return getTypeAtPosition(contextualSignature, indexOfParameter);
}
const funcHasRestParameters = hasRestParameter(func);
const len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
const indexOfParameter = indexOf(func.parameters, parameter);
if (indexOfParameter < len) {
return getTypeAtPosition(contextualSignature, indexOfParameter);
}
// If last parameter is contextually rest parameter get its type
if (funcHasRestParameters &&
indexOfParameter === (func.parameters.length - 1) &&
isRestParameterIndex(contextualSignature, func.parameters.length - 1)) {
return getTypeOfSymbol(lastOrUndefined(contextualSignature.parameters));
}
// If last parameter is contextually rest parameter get its type
if (funcHasRestParameters &&
indexOfParameter === (func.parameters.length - 1) &&
isRestParameterIndex(contextualSignature, func.parameters.length - 1)) {
return getTypeOfSymbol(lastOrUndefined(contextualSignature.parameters));
}
}
}
@ -8509,9 +8510,9 @@ namespace ts {
}
// In a variable, parameter or property declaration with a type annotation,
// the contextual type of an initializer expression is the type of the variable, parameter or property.
// Otherwise, in a parameter declaration of a contextually typed function expression,
// the contextual type of an initializer expression is the contextual type of the parameter.
// the contextual type of an initializer expression is the type of the variable, parameter or property.
// Otherwise, in a parameter declaration of a contextually typed function expression,
// the contextual type of an initializer expression is the contextual type of the parameter.
// Otherwise, in a variable or parameter declaration with a binding pattern name,
// the contextual type of an initializer expression is the type implied by the binding pattern.
// Otherwise, in a binding pattern inside a variable or parameter declaration,
@ -8865,6 +8866,12 @@ namespace ts {
: undefined;
}
function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | MethodDeclaration) {
return isObjectLiteralMethod(node)
? getContextualTypeForObjectLiteralMethod(node)
: getApparentTypeOfContextualType(node);
}
// Return the contextual signature for a given expression node. A contextual type provides a
// contextual signature if it has a single call signature and if that call signature is non-generic.
// If the contextual type is a union type, get the signature from each type possible and if they are
@ -8872,9 +8879,7 @@ namespace ts {
// union type of return types from these signatures
function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature {
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
const type = isObjectLiteralMethod(node)
? getContextualTypeForObjectLiteralMethod(node)
: getApparentTypeOfContextualType(node);
const type = getContextualTypeForFunctionLikeDeclaration(node);
if (!type) {
return undefined;
}
@ -9785,8 +9790,24 @@ namespace ts {
}
const propType = getTypeOfSymbol(prop);
return node.kind === SyntaxKind.PropertyAccessExpression && prop.flags & (SymbolFlags.Variable | SymbolFlags.Property) && !isAssignmentTarget(node) ?
getNarrowedTypeOfReference(propType, <PropertyAccessExpression>node) : propType;
if (node.kind !== SyntaxKind.PropertyAccessExpression || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property)) || isAssignmentTarget(node)) {
return propType;
}
const leftmostNode = getLeftmostIdentifierOrThis(node);
if (!leftmostNode) {
return propType;
}
if (leftmostNode.kind === SyntaxKind.Identifier) {
const leftmostSymbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>leftmostNode));
if (!leftmostSymbol) {
return propType;
}
const declaration = leftmostSymbol.valueDeclaration;
if (!declaration || declaration.kind !== SyntaxKind.VariableDeclaration && declaration.kind !== SyntaxKind.Parameter && declaration.kind !== SyntaxKind.BindingElement) {
return propType;
}
}
return getFlowTypeOfReference(node, propType, propType);
}
function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean {

View File

@ -1753,7 +1753,7 @@ namespace ts {
if (!emitSkipped) {
const declarationOutput = emitDeclarationResult.referencesOutput
+ getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo);
writeFile(host, emitterDiagnostics, declarationFilePath, declarationOutput, host.getCompilerOptions().emitBOM);
writeFile(host, emitterDiagnostics, declarationFilePath, declarationOutput, host.getCompilerOptions().emitBOM, sourceFiles);
}
return emitSkipped;

View File

@ -1524,6 +1524,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
switch (parent.kind) {
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.AsExpression:
case SyntaxKind.AwaitExpression:
case SyntaxKind.BinaryExpression:
case SyntaxKind.CallExpression:
case SyntaxKind.CaseClause:

View File

@ -3,6 +3,11 @@
namespace ts {
export type FileWatcherCallback = (fileName: string, removed?: boolean) => void;
export type DirectoryWatcherCallback = (directoryName: string) => void;
export interface WatchedFile {
fileName: string;
callback: FileWatcherCallback;
mtime?: Date;
}
export interface System {
args: string[];
@ -26,12 +31,6 @@ namespace ts {
exit(exitCode?: number): void;
}
interface WatchedFile {
fileName: string;
callback: FileWatcherCallback;
mtime?: Date;
}
export interface FileWatcher {
close(): void;
}
@ -230,83 +229,7 @@ namespace ts {
const _os = require("os");
const _crypto = require("crypto");
// average async stat takes about 30 microseconds
// set chunk size to do 30 files in < 1 millisecond
function createPollingWatchedFileSet(interval = 2500, chunkSize = 30) {
let watchedFiles: WatchedFile[] = [];
let nextFileToCheck = 0;
let watchTimer: any;
function getModifiedTime(fileName: string): Date {
return _fs.statSync(fileName).mtime;
}
function poll(checkedIndex: number) {
const watchedFile = watchedFiles[checkedIndex];
if (!watchedFile) {
return;
}
_fs.stat(watchedFile.fileName, (err: any, stats: any) => {
if (err) {
watchedFile.callback(watchedFile.fileName);
}
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
watchedFile.mtime = getModifiedTime(watchedFile.fileName);
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
}
});
}
// this implementation uses polling and
// stat due to inconsistencies of fs.watch
// and efficiency of stat on modern filesystems
function startWatchTimer() {
watchTimer = setInterval(() => {
let count = 0;
let nextToCheck = nextFileToCheck;
let firstCheck = -1;
while ((count < chunkSize) && (nextToCheck !== firstCheck)) {
poll(nextToCheck);
if (firstCheck < 0) {
firstCheck = nextToCheck;
}
nextToCheck++;
if (nextToCheck === watchedFiles.length) {
nextToCheck = 0;
}
count++;
}
nextFileToCheck = nextToCheck;
}, interval);
}
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
const file: WatchedFile = {
fileName,
callback,
mtime: getModifiedTime(fileName)
};
watchedFiles.push(file);
if (watchedFiles.length === 1) {
startWatchTimer();
}
return file;
}
function removeFile(file: WatchedFile) {
watchedFiles = copyListRemovingItem(file, watchedFiles);
}
return {
getModifiedTime: getModifiedTime,
poll: poll,
startWatchTimer: startWatchTimer,
addFile: addFile,
removeFile: removeFile
};
}
const useNonPollingWatchers = process.env["TSC_NONPOLLING_WATCHER"];
function createWatchedFileSet() {
const dirWatchers: Map<DirectoryWatcher> = {};
@ -389,26 +312,11 @@ namespace ts {
}
}
}
// REVIEW: for now this implementation uses polling.
// The advantage of polling is that it works reliably
// on all os and with network mounted files.
// For 90 referenced files, the average time to detect
// changes is 2*msInterval (by default 5 seconds).
// The overhead of this is .04 percent (1/2500) with
// average pause of < 1 millisecond (and max
// pause less than 1.5 milliseconds); question is
// do we anticipate reference sets in the 100s and
// do we care about waiting 10-20 seconds to detect
// changes for large reference sets? If so, do we want
// to increase the chunk size or decrease the interval
// time dynamically to match the large reference set?
const pollingWatchedFileSet = createPollingWatchedFileSet();
const watchedFileSet = createWatchedFileSet();
function isNode4OrLater(): boolean {
return parseInt(process.version.charAt(1)) >= 4;
}
return parseInt(process.version.charAt(1)) >= 4;
}
const platform: string = _os.platform();
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
@ -501,7 +409,7 @@ namespace ts {
const files = _fs.readdirSync(path || ".").sort();
const directories: string[] = [];
for (const current of files) {
// This is necessary because on some file system node fails to exclude
// This is necessary because on some file system node fails to exclude
// "." and "..". See https://github.com/nodejs/node/issues/4002
if (current === "." || current === "..") {
continue;
@ -535,15 +443,26 @@ namespace ts {
readFile,
writeFile,
watchFile: (fileName, callback) => {
// Node 4.0 stabilized the `fs.watch` function on Windows which avoids polling
// and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649
// and https://github.com/Microsoft/TypeScript/issues/4643), therefore
// if the current node.js version is newer than 4, use `fs.watch` instead.
const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet;
const watchedFile = watchSet.addFile(fileName, callback);
return {
close: () => watchSet.removeFile(watchedFile)
};
if (useNonPollingWatchers) {
const watchedFile = watchedFileSet.addFile(fileName, callback);
return {
close: () => watchedFileSet.removeFile(watchedFile)
};
}
else {
_fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
return {
close: () => _fs.unwatchFile(fileName, fileChanged)
};
}
function fileChanged(curr: any, prev: any) {
if (+curr.mtime <= +prev.mtime) {
return;
}
callback(fileName);
}
},
watchDirectory: (directoryName, callback, recursive) => {
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows

View File

@ -391,9 +391,21 @@ namespace ts {
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
return;
}
if (isWatchSet(configParseResult.options) && !sys.watchFile) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined);
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
if (isWatchSet(configParseResult.options)) {
if (!sys.watchFile) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined);
sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
if (!directoryWatcher && sys.watchDirectory && configFileName) {
const directory = ts.getDirectoryPath(configFileName);
directoryWatcher = sys.watchDirectory(
// When the configFileName is just "tsconfig.json", the watched directory should be
// the current directory; if there is a given "project" parameter, then the configFileName
// is an absolute file name.
directory == "" ? "." : directory,
watchedDirectoryChanged, /*recursive*/ true);
};
}
return configParseResult;
}

View File

@ -1551,6 +1551,7 @@ namespace ts {
Unreachable,
Start,
Label,
LoopLabel,
Assignment,
Condition
}
@ -2539,19 +2540,19 @@ namespace ts {
// When options come from a config file, its path is recorded here
configFilePath?: string;
/* @internal */
// Path used to used to compute primary search locations
// Path used to used to compute primary search locations
typesRoot?: string;
types?: string[];
list?: string[];
[option: string]: CompilerOptionsValue;
[option: string]: CompilerOptionsValue | undefined;
}
export interface TypingOptions {
enableAutoDiscovery?: boolean;
include?: string[];
exclude?: string[];
[option: string]: string[] | boolean;
[option: string]: string[] | boolean | undefined;
}
export interface DiscoverTypingsInfo {
@ -2856,7 +2857,7 @@ namespace ts {
*/
resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[];
/**
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
*/
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
}

View File

@ -747,7 +747,7 @@ namespace FourSlash {
}
const missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess };
this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(references)})`);
this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(references, undefined, 2)})`);
}
public verifyReferencesCountIs(count: number, localFilesOnly = true) {
@ -801,7 +801,7 @@ namespace FourSlash {
private testDiagnostics(expected: string, diagnostics: ts.Diagnostic[]) {
const realized = ts.realizeDiagnostics(diagnostics, "\r\n");
const actual = JSON.stringify(realized, null, " ");
const actual = JSON.stringify(realized, undefined, 2);
assert.equal(actual, expected);
}
@ -876,7 +876,7 @@ namespace FourSlash {
}
if (ranges.length !== references.length) {
this.raiseError("Rename location count does not match result.\n\nExpected: " + JSON.stringify(ranges) + "\n\nActual:" + JSON.stringify(references));
this.raiseError("Rename location count does not match result.\n\nExpected: " + JSON.stringify(ranges, undefined, 2) + "\n\nActual:" + JSON.stringify(references, undefined, 2));
}
ranges = ranges.sort((r1, r2) => r1.start - r2.start);
@ -889,7 +889,7 @@ namespace FourSlash {
if (reference.textSpan.start !== range.start ||
ts.textSpanEnd(reference.textSpan) !== range.end) {
this.raiseError("Rename location results do not match.\n\nExpected: " + JSON.stringify(ranges) + "\n\nActual:" + JSON.stringify(references));
this.raiseError("Rename location results do not match.\n\nExpected: " + JSON.stringify(ranges, undefined, 2) + "\n\nActual:" + JSON.stringify(references, undefined, 2));
}
}
}
@ -973,7 +973,7 @@ namespace FourSlash {
}
else {
if (actual) {
this.raiseError(`Expected no signature help, but got "${JSON.stringify(actual)}"`);
this.raiseError(`Expected no signature help, but got "${JSON.stringify(actual, undefined, 2)}"`);
}
}
}
@ -1185,7 +1185,7 @@ namespace FourSlash {
public printCurrentParameterHelp() {
const help = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition);
Harness.IO.log(JSON.stringify(help));
Harness.IO.log(JSON.stringify(help, undefined, 2));
}
public printCurrentQuickInfo() {
@ -1227,7 +1227,7 @@ namespace FourSlash {
public printCurrentSignatureHelp() {
const sigHelp = this.getActiveSignatureHelpItem();
Harness.IO.log(JSON.stringify(sigHelp));
Harness.IO.log(JSON.stringify(sigHelp, undefined, 2));
}
public printMemberListMembers() {
@ -1257,7 +1257,7 @@ namespace FourSlash {
public printReferences() {
const references = this.getReferencesAtCaret();
ts.forEach(references, entry => {
Harness.IO.log(JSON.stringify(entry));
Harness.IO.log(JSON.stringify(entry, undefined, 2));
});
}
@ -1748,8 +1748,8 @@ namespace FourSlash {
function jsonMismatchString() {
return Harness.IO.newLine() +
"expected: '" + Harness.IO.newLine() + JSON.stringify(expected, (k, v) => v, 2) + "'" + Harness.IO.newLine() +
"actual: '" + Harness.IO.newLine() + JSON.stringify(actual, (k, v) => v, 2) + "'";
"expected: '" + Harness.IO.newLine() + JSON.stringify(expected, undefined, 2) + "'" + Harness.IO.newLine() +
"actual: '" + Harness.IO.newLine() + JSON.stringify(actual, undefined, 2) + "'";
}
}
@ -1964,7 +1964,7 @@ namespace FourSlash {
// if there was an explicit match kind specified, then it should be validated.
if (matchKind !== undefined) {
const missingItem = { name: name, kind: kind, searchValue: searchValue, matchKind: matchKind, fileName: fileName, parentName: parentName };
this.raiseError(`verifyNavigationItemsListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(items)})`);
this.raiseError(`verifyNavigationItemsListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`);
}
}
@ -2001,7 +2001,7 @@ namespace FourSlash {
}
const missingItem = { name: name, kind: kind };
this.raiseError(`verifyGetScriptLexicalStructureListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(items, null, " ")})`);
this.raiseError(`verifyGetScriptLexicalStructureListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`);
}
private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string) {
@ -2066,7 +2066,7 @@ namespace FourSlash {
}
const missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess };
this.raiseError(`verifyOccurrencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(occurrences)})`);
this.raiseError(`verifyOccurrencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(occurrences, undefined, 2)})`);
}
public verifyOccurrencesAtPositionListCount(expectedCount: number) {
@ -2105,7 +2105,7 @@ namespace FourSlash {
}
const missingItem = { fileName: fileName, start: start, end: end, kind: kind };
this.raiseError(`verifyDocumentHighlightsAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(documentHighlights)})`);
this.raiseError(`verifyDocumentHighlightsAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(documentHighlights, undefined, 2)})`);
}
public verifyDocumentHighlightsAtPositionListCount(expectedCount: number, fileNamesToSearch: string[]) {
@ -2171,9 +2171,9 @@ namespace FourSlash {
}
}
const itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n");
const itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind }, undefined, 2)).join(",\n");
this.raiseError(`Expected "${JSON.stringify({ name, text, documentation, kind })}" to be in list [${itemsString}]`);
this.raiseError(`Expected "${JSON.stringify({ name, text, documentation, kind }, undefined, 2)}" to be in list [${itemsString}]`);
}
private findFile(indexOrName: any) {

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,24 @@
declare type PropertyKey = string | number | symbol;
interface Array<T> {
/**
* Returns the value of the first element in the array where predicate is true, and undefined
/**
* Returns the value of the first element in the array where predicate is true, and undefined
* otherwise.
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* immediately returns that element value. Otherwise, find returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T | undefined;
/**
* Returns the index of the first element in the array where predicate is true, and undefined
/**
* Returns the index of the first element in the array where predicate is true, and undefined
* otherwise.
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* immediately returns that element value. Otherwise, find returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findIndex(predicate: (value: T) => boolean, thisArg?: any): number | undefined;
@ -26,21 +26,21 @@ interface Array<T> {
/**
* Returns the this object after filling the section identified by start and end with value
* @param value value to fill array section with
* @param start index to start filling the array at. If start is negative, it is treated as
* length+start where length is the length of the array.
* @param end index to stop filling the array at. If end is negative, it is treated as
* @param start index to start filling the array at. If start is negative, it is treated as
* length+start where length is the length of the array.
* @param end index to stop filling the array at. If end is negative, it is treated as
* length+end.
*/
fill(value: T, start?: number, end?: number): T[];
/**
/**
* Returns the this object after copying a section of the array identified by start and end
* to the same array starting at position target
* @param target If target is negative, it is treated as length+target where length is the
* length of the array.
* @param start If start is negative, it is treated as length+start. If end is negative, it
* @param target If target is negative, it is treated as length+target where length is the
* length of the array.
* @param start If start is negative, it is treated as length+start. If end is negative, it
* is treated as length+end.
* @param end If not specified, length of the this object is used as its default value.
* @param end If not specified, length of the this object is used as its default value.
*/
copyWithin(target: number, start: number, end?: number): T[];
}
@ -114,7 +114,7 @@ interface Math {
log1p(x: number): number;
/**
* Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of
* Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of
* the natural logarithms).
* @param x A numeric expression.
*/
@ -190,14 +190,14 @@ interface Math {
interface NumberConstructor {
/**
* The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
* that is representable as a Number value, which is approximately:
* that is representable as a Number value, which is approximately:
* 2.2204460492503130808472633361816 x 1016.
*/
readonly EPSILON: number;
/**
* Returns true if passed value is finite.
* Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
* Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
* number. Only finite values of the type number, result in true.
* @param number A numeric value.
*/
@ -210,7 +210,7 @@ interface NumberConstructor {
isInteger(number: number): boolean;
/**
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
* number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
* to a number. Only values of the type number, that are also NaN, result in true.
* @param number A numeric value.
@ -223,30 +223,30 @@ interface NumberConstructor {
*/
isSafeInteger(number: number): boolean;
/**
* The value of the largest integer n such that n and n + 1 are both exactly representable as
* a Number value.
/**
* The value of the largest integer n such that n and n + 1 are both exactly representable as
* a Number value.
* The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 1.
*/
readonly MAX_SAFE_INTEGER: number;
/**
* The value of the smallest integer n such that n and n 1 are both exactly representable as
* a Number value.
/**
* The value of the smallest integer n such that n and n 1 are both exactly representable as
* a Number value.
* The value of Number.MIN_SAFE_INTEGER is 9007199254740991 ((2^53 1)).
*/
readonly MIN_SAFE_INTEGER: number;
/**
* Converts a string to a floating-point number.
* @param string A string that contains a floating-point number.
* Converts a string to a floating-point number.
* @param string A string that contains a floating-point number.
*/
parseFloat(string: string): number;
/**
* Converts A string to an integer.
* @param s A string to convert into a number.
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
* All other strings are considered decimal.
*/
@ -255,12 +255,12 @@ interface NumberConstructor {
interface Object {
/**
* Determines whether an object has a property with the specified name.
* Determines whether an object has a property with the specified name.
* @param v A property name.
*/
hasOwnProperty(v: PropertyKey): boolean
/**
/**
* Determines whether a specified property is enumerable.
* @param v A property name.
*/
@ -269,7 +269,7 @@ interface Object {
interface ObjectConstructor {
/**
* Copy the values of all of the enumerable own properties from one or more source objects to a
* Copy the values of all of the enumerable own properties from one or more source objects to a
* target object. Returns the target object.
* @param target The target object to copy to.
* @param source The source object from which to copy properties.
@ -277,7 +277,7 @@ interface ObjectConstructor {
assign<T, U>(target: T, source: U): T & U;
/**
* Copy the values of all of the enumerable own properties from one or more source objects to a
* Copy the values of all of the enumerable own properties from one or more source objects to a
* target object. Returns the target object.
* @param target The target object to copy to.
* @param source1 The first source object from which to copy properties.
@ -286,7 +286,7 @@ interface ObjectConstructor {
assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
/**
* Copy the values of all of the enumerable own properties from one or more source objects to a
* Copy the values of all of the enumerable own properties from one or more source objects to a
* target object. Returns the target object.
* @param target The target object to copy to.
* @param source1 The first source object from which to copy properties.
@ -296,7 +296,7 @@ interface ObjectConstructor {
assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
/**
* Copy the values of all of the enumerable own properties from one or more source objects to a
* Copy the values of all of the enumerable own properties from one or more source objects to a
* target object. Returns the target object.
* @param target The target object to copy to.
* @param sources One or more source objects from which to copy properties
@ -324,17 +324,17 @@ interface ObjectConstructor {
setPrototypeOf(o: any, proto: any): any;
/**
* Gets the own property descriptor of the specified object.
* An own property descriptor is one that is defined directly on the object and is not
* inherited from the object's prototype.
* Gets the own property descriptor of the specified object.
* An own property descriptor is one that is defined directly on the object and is not
* inherited from the object's prototype.
* @param o Object that contains the property.
* @param p Name of the property.
*/
getOwnPropertyDescriptor(o: any, propertyKey: PropertyKey): PropertyDescriptor;
/**
* Adds a property to an object, or modifies attributes of an existing property.
* @param o Object on which to add or modify the property. This can be a native JavaScript
* Adds a property to an object, or modifies attributes of an existing property.
* @param o Object on which to add or modify the property. This can be a native JavaScript
* object (that is, a user-defined object or a built in object) or a DOM object.
* @param p The property name.
* @param attributes Descriptor for the property. It can be for a data property or an accessor
@ -358,47 +358,52 @@ interface RegExp {
*/
readonly flags: string;
/**
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
* expression. Default is false. Read-only.
/**
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
* expression. Default is false. Read-only.
*/
readonly sticky: boolean;
/**
* Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular
* expression. Default is false. Read-only.
/**
* Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular
* expression. Default is false. Read-only.
*/
readonly unicode: boolean;
}
interface RegExpConstructor {
new (pattern: RegExp, flags?: string): RegExp;
(pattern: RegExp, flags?: string): RegExp;
}
interface String {
/**
* Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
* value of the UTF-16 encoded code point starting at the string element at position pos in
* the String resulting from converting this object to a String.
* If there is no element at that position, the result is undefined.
* Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
* value of the UTF-16 encoded code point starting at the string element at position pos in
* the String resulting from converting this object to a String.
* If there is no element at that position, the result is undefined.
* If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
*/
codePointAt(pos: number): number | undefined;
/**
* Returns true if searchString appears as a substring of the result of converting this
* object to a String, at one or more positions that are
* Returns true if searchString appears as a substring of the result of converting this
* object to a String, at one or more positions that are
* greater than or equal to position; otherwise, returns false.
* @param searchString search string
* @param searchString search string
* @param position If position is undefined, 0 is assumed, so as to search all of the String.
*/
includes(searchString: string, position?: number): boolean;
/**
* Returns true if the sequence of elements of searchString converted to a String is the
* same as the corresponding elements of this object (converted to a String) starting at
* Returns true if the sequence of elements of searchString converted to a String is the
* same as the corresponding elements of this object (converted to a String) starting at
* endPosition length(this). Otherwise returns false.
*/
endsWith(searchString: string, endPosition?: number): boolean;
/**
* Returns the String value result of normalizing the string into the normalization form
* Returns the String value result of normalizing the string into the normalization form
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
* @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
* is "NFC"
@ -406,15 +411,15 @@ interface String {
normalize(form?: string): string;
/**
* Returns a String value that is made from count copies appended together. If count is 0,
* Returns a String value that is made from count copies appended together. If count is 0,
* T is the empty String is returned.
* @param count number of copies to append
*/
repeat(count: number): string;
/**
* Returns true if the sequence of elements of searchString converted to a String is the
* same as the corresponding elements of this object (converted to a String) starting at
* Returns true if the sequence of elements of searchString converted to a String is the
* same as the corresponding elements of this object (converted to a String) starting at
* position. Otherwise returns false.
*/
startsWith(searchString: string, position?: number): boolean;
@ -474,7 +479,7 @@ interface StringConstructor {
/**
* String.raw is intended for use as a tag function of a Tagged Template String. When called
* as such the first argument will be a well formed template call site object and the rest
* as such the first argument will be a well formed template call site object and the rest
* parameter will contain the substitution values.
* @param template A well-formed template string call site representation.
* @param substitutions A set of substitution values.

1497
src/lib/es5.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,16 @@ interface EventInit {
cancelable?: boolean;
}
interface IDBIndexParameters {
multiEntry?: boolean;
unique?: boolean;
}
interface IDBObjectStoreParameters {
autoIncrement?: boolean;
keyPath?: IDBKeyPath;
}
interface EventListener {
(evt: Event): void;
}
@ -84,12 +94,12 @@ declare var Console: {
interface Coordinates {
readonly accuracy: number;
readonly altitude: number;
readonly altitudeAccuracy: number;
readonly heading: number;
readonly altitude: number | null;
readonly altitudeAccuracy: number | null;
readonly heading: number | null;
readonly latitude: number;
readonly longitude: number;
readonly speed: number;
readonly speed: number | null;
}
declare var Coordinates: {
@ -176,7 +186,7 @@ declare var DOMException: {
interface DOMStringList {
readonly length: number;
contains(str: string): boolean;
item(index: number): string;
item(index: number): string | null;
[index: number]: string;
}
@ -459,7 +469,7 @@ declare var IDBTransaction: {
}
interface IDBVersionChangeEvent extends Event {
readonly newVersion: number;
readonly newVersion: number | null;
readonly oldVersion: number;
}
@ -712,7 +722,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
withCredentials: boolean;
abort(): void;
getAllResponseHeaders(): string;
getResponseHeader(header: string): string;
getResponseHeader(header: string): string | null;
msCachingEnabled(): boolean;
open(method: string, url: string, async?: boolean, user?: string, password?: string): void;
overrideMimeType(mime: string): void;
@ -991,4 +1001,5 @@ declare var console: Console;
declare function addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
declare function addEventListener(type: "message", listener: (ev: MessageEvent) => any, useCapture?: boolean): void;
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
type IDBKeyPath = string;
type IDBValidKey = number | string | Date | IDBArrayKey;

View File

@ -919,6 +919,7 @@ namespace ts.server {
configuredProject.updateGraph();
if (configuredProject.getSourceFile(info)) {
info.defaultProject = configuredProject;
referencingProjects.push(configuredProject);
}
}
return referencingProjects;
@ -1684,7 +1685,12 @@ namespace ts.server {
}
reloadFromFile(filename: string, cb?: () => any) {
const content = this.host.readFile(filename);
let content = this.host.readFile(filename);
// If the file doesn't exist or cannot be read, we should
// wipe out its cached content on the server to avoid side effects.
if (!content) {
content = "";
}
this.reload(content);
if (cb)
cb();

View File

@ -153,6 +153,98 @@ namespace ts.server {
// This places log file in the directory containing editorServices.js
// TODO: check that this location is writable
// average async stat takes about 30 microseconds
// set chunk size to do 30 files in < 1 millisecond
function createPollingWatchedFileSet(interval = 2500, chunkSize = 30) {
let watchedFiles: WatchedFile[] = [];
let nextFileToCheck = 0;
let watchTimer: any;
function getModifiedTime(fileName: string): Date {
return fs.statSync(fileName).mtime;
}
function poll(checkedIndex: number) {
const watchedFile = watchedFiles[checkedIndex];
if (!watchedFile) {
return;
}
fs.stat(watchedFile.fileName, (err: any, stats: any) => {
if (err) {
watchedFile.callback(watchedFile.fileName);
}
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
watchedFile.mtime = getModifiedTime(watchedFile.fileName);
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
}
});
}
// this implementation uses polling and
// stat due to inconsistencies of fs.watch
// and efficiency of stat on modern filesystems
function startWatchTimer() {
watchTimer = setInterval(() => {
let count = 0;
let nextToCheck = nextFileToCheck;
let firstCheck = -1;
while ((count < chunkSize) && (nextToCheck !== firstCheck)) {
poll(nextToCheck);
if (firstCheck < 0) {
firstCheck = nextToCheck;
}
nextToCheck++;
if (nextToCheck === watchedFiles.length) {
nextToCheck = 0;
}
count++;
}
nextFileToCheck = nextToCheck;
}, interval);
}
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
const file: WatchedFile = {
fileName,
callback,
mtime: getModifiedTime(fileName)
};
watchedFiles.push(file);
if (watchedFiles.length === 1) {
startWatchTimer();
}
return file;
}
function removeFile(file: WatchedFile) {
watchedFiles = copyListRemovingItem(file, watchedFiles);
}
return {
getModifiedTime: getModifiedTime,
poll: poll,
startWatchTimer: startWatchTimer,
addFile: addFile,
removeFile: removeFile
};
}
// REVIEW: for now this implementation uses polling.
// The advantage of polling is that it works reliably
// on all os and with network mounted files.
// For 90 referenced files, the average time to detect
// changes is 2*msInterval (by default 5 seconds).
// The overhead of this is .04 percent (1/2500) with
// average pause of < 1 millisecond (and max
// pause less than 1.5 milliseconds); question is
// do we anticipate reference sets in the 100s and
// do we care about waiting 10-20 seconds to detect
// changes for large reference sets? If so, do we want
// to increase the chunk size or decrease the interval
// time dynamically to match the large reference set?
const pollingWatchedFileSet = createPollingWatchedFileSet();
const logger = createLoggerFromEnv();
const pending: string[] = [];
@ -176,6 +268,12 @@ namespace ts.server {
// Override sys.write because fs.writeSync is not reliable on Node 4
ts.sys.write = (s: string) => writeMessage(s);
ts.sys.watchFile = (fileName, callback) => {
const watchedFile = pollingWatchedFileSet.addFile(fileName, callback);
return {
close: () => pollingWatchedFileSet.removeFile(watchedFile)
};
};
const ioSession = new IOSession(ts.sys, logger);
process.on("uncaughtException", function(err: Error) {

View File

@ -647,7 +647,7 @@ namespace ts.server {
const editorOptions: ts.EditorOptions = {
IndentSize: formatOptions.IndentSize,
TabSize: formatOptions.TabSize,
NewLineCharacter: "\n",
NewLineCharacter: formatOptions.NewLineCharacter,
ConvertTabsToSpaces: formatOptions.ConvertTabsToSpaces,
IndentStyle: ts.IndentStyle.Smart,
};

View File

@ -758,9 +758,6 @@ namespace ts.NavigationBar {
else if (fnExpr.parent.kind === SyntaxKind.BinaryExpression &&
(fnExpr.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken) {
fnName = (fnExpr.parent as BinaryExpression).left.getText();
if (fnName.length > 20) {
fnName = fnName.substring(0, 17) + "...";
}
}
// See if it is a property assignment, and if so use the property name
else if (fnExpr.parent.kind === SyntaxKind.PropertyAssignment &&

View File

@ -1049,7 +1049,7 @@ namespace ts {
getScriptFileNames(): string[];
getScriptKind?(fileName: string): ScriptKind;
getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): IScriptSnapshot;
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
getLocalizedDiagnosticMessages?(): any;
getCancellationToken?(): HostCancellationToken;
getCurrentDirectory(): string;
@ -4913,8 +4913,8 @@ namespace ts {
node.kind === SyntaxKind.ThisKeyword ||
node.kind === SyntaxKind.ThisType ||
node.kind === SyntaxKind.SuperKeyword ||
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
isNameOfExternalModuleImportOrDeclaration(node)) {
node.kind === SyntaxKind.StringLiteral ||
isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) {
const referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings*/ false, /*findInComments*/ false);
return convertReferencedSymbols(referencedSymbols);
@ -5581,8 +5581,8 @@ namespace ts {
// TODO (drosen): This should be enabled in a later release - currently breaks rename.
// node.kind !== SyntaxKind.ThisKeyword &&
// node.kind !== SyntaxKind.SuperKeyword &&
!isLiteralNameOfPropertyDeclarationOrIndexAccess(node) &&
!isNameOfExternalModuleImportOrDeclaration(node)) {
node.kind !== SyntaxKind.StringLiteral &&
!isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) {
return undefined;
}
@ -5617,6 +5617,10 @@ namespace ts {
const symbol = typeChecker.getSymbolAtLocation(node);
if (!symbol && node.kind === SyntaxKind.StringLiteral) {
return getReferencesForStringLiteral(<StringLiteral>node, sourceFiles);
}
// Could not find a symbol e.g. unknown identifier
if (!symbol) {
// Can't have references to something that we have no symbol for.
@ -6174,6 +6178,52 @@ namespace ts {
}
}
function getReferencesForStringLiteral(node: StringLiteral, sourceFiles: SourceFile[]): ReferencedSymbol[] {
const typeChecker = program.getTypeChecker();
const type = getStringLiteralTypeForNode(node, typeChecker);
if (!type) {
// nothing to do here. moving on
return undefined;
}
const references: ReferenceEntry[] = [];
for (const sourceFile of sourceFiles) {
const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, type.text, sourceFile.getStart(), sourceFile.getEnd());
getReferencesForStringLiteralInFile(sourceFile, type, possiblePositions, references);
}
return [{
definition: {
containerKind: "",
containerName: "",
fileName: node.getSourceFile().fileName,
kind: ScriptElementKind.variableElement,
name: type.text,
textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd())
},
references: references
}];
function getReferencesForStringLiteralInFile(sourceFile: SourceFile, searchType: Type, possiblePositions: number[], references: ReferenceEntry[]): void {
for (const position of possiblePositions) {
cancellationToken.throwIfCancellationRequested();
const node = getTouchingWord(sourceFile, position);
if (!node || node.kind !== SyntaxKind.StringLiteral) {
return;
}
const type = getStringLiteralTypeForNode(<StringLiteral>node, typeChecker);
if (type === searchType) {
references.push(getReferenceEntryFromNode(node));
}
}
}
}
function populateSearchSymbolSet(symbol: Symbol, location: Node): Symbol[] {
// The search set contains at least the current symbol
let result = [symbol];
@ -7694,6 +7744,14 @@ namespace ts {
}
}
function getStringLiteralTypeForNode(node: StringLiteral | StringLiteralTypeNode, typeChecker: TypeChecker): StringLiteralType {
const searchNode = node.parent.kind === SyntaxKind.StringLiteralType ? <StringLiteralTypeNode>node.parent : node;
const type = typeChecker.getTypeAtLocation(searchNode);
if (type && type.flags & TypeFlags.StringLiteral) {
return <StringLiteralType>type;
}
return undefined;
}
function getRenameInfo(fileName: string, position: number): RenameInfo {
synchronizeHostData();
@ -7701,46 +7759,60 @@ namespace ts {
const sourceFile = getValidSourceFile(fileName);
const typeChecker = program.getTypeChecker();
const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings());
const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName));
const node = getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true);
// Can only rename an identifier.
if (node && node.kind === SyntaxKind.Identifier) {
const symbol = typeChecker.getSymbolAtLocation(node);
if (node) {
if (node.kind === SyntaxKind.Identifier ||
node.kind === SyntaxKind.StringLiteral ||
isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) {
const symbol = typeChecker.getSymbolAtLocation(node);
// Only allow a symbol to be renamed if it actually has at least one declaration.
if (symbol) {
const declarations = symbol.getDeclarations();
if (declarations && declarations.length > 0) {
// Disallow rename for elements that are defined in the standard TypeScript library.
const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings());
const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName));
if (defaultLibFileName) {
for (const current of declarations) {
const sourceFile = current.getSourceFile();
// TODO (drosen): When is there no source file?
if (!sourceFile) {
continue;
}
// Only allow a symbol to be renamed if it actually has at least one declaration.
if (symbol) {
const declarations = symbol.getDeclarations();
if (declarations && declarations.length > 0) {
// Disallow rename for elements that are defined in the standard TypeScript library.
if (forEach(declarations, isDefinedInLibraryFile)) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library));
}
const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName));
if (canonicalName === canonicalDefaultLibName) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library));
}
const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node));
const kind = getSymbolKind(symbol, node);
if (kind) {
return {
canRename: true,
kind,
displayName,
localizedErrorMessage: undefined,
fullDisplayName: typeChecker.getFullyQualifiedName(symbol),
kindModifiers: getSymbolModifiers(symbol),
triggerSpan: createTriggerSpanForNode(node, sourceFile)
};
}
}
const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node));
const kind = getSymbolKind(symbol, node);
if (kind) {
return {
canRename: true,
kind,
displayName,
localizedErrorMessage: undefined,
fullDisplayName: typeChecker.getFullyQualifiedName(symbol),
kindModifiers: getSymbolModifiers(symbol),
triggerSpan: createTextSpan(node.getStart(), node.getWidth())
};
}
else if (node.kind === SyntaxKind.StringLiteral) {
const type = getStringLiteralTypeForNode(<StringLiteral>node, typeChecker);
if (type) {
if (isDefinedInLibraryFile(node)) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library));
}
else {
const displayName = stripQuotes(type.text);
return {
canRename: true,
kind: ScriptElementKind.variableElement,
displayName,
localizedErrorMessage: undefined,
fullDisplayName: displayName,
kindModifiers: ScriptElementKindModifier.none,
triggerSpan: createTriggerSpanForNode(node, sourceFile)
};
}
}
}
}
@ -7759,6 +7831,28 @@ namespace ts {
triggerSpan: undefined
};
}
function isDefinedInLibraryFile(declaration: Node) {
if (defaultLibFileName) {
const sourceFile = declaration.getSourceFile();
const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName));
if (canonicalName === canonicalDefaultLibName) {
return true;
}
}
return false;
}
function createTriggerSpanForNode(node: Node, sourceFile: SourceFile) {
let start = node.getStart(sourceFile);
let width = node.getWidth(sourceFile);
if (node.kind === SyntaxKind.StringLiteral) {
// Exclude the quotes
start += 1;
width -= 2;
}
return createTextSpan(start, width);
}
}
return {

View File

@ -55,7 +55,7 @@ export function delint(sourceFile: ts.SourceFile) {
}
}
const fileNames = process.argv.slice(2);
const fileNames: string[] = process.argv.slice(2);
fileNames.forEach(fileName => {
// Parse a file
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);

View File

@ -19,7 +19,7 @@ function printError(error: ts.Diagnostic): void {
console.log(`${error.file && error.file.fileName}: ${error.messageText}`);
}
export function createProgram(rootFiles: string[], compilerOptionsJson: string): ts.Program {
export function createProgram(rootFiles: string[], compilerOptionsJson: string): ts.Program | undefined {
const { config, error } = ts.parseConfigFileTextToJson("tsconfig.json", compilerOptionsJson)
if (error) {
printError(error);

View File

@ -8,7 +8,13 @@
declare var process: any;
declare var console: any;
declare var fs: any;
declare var fs: {
existsSync(path: string): boolean;
readdirSync(path: string): string[];
readFileSync(filename: string, encoding?: string): string;
writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: { mtime: Date }, prev: { mtime: Date }) => void): void;
};
declare var path: any;
import * as ts from "typescript";

View File

@ -0,0 +1,8 @@
//// [ambientNameRestrictions.ts]
export declare namespace Foo {
export var static: any;
}
//// [ambientNameRestrictions.js]
"use strict";

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/ambientNameRestrictions.ts ===
export declare namespace Foo {
>Foo : Symbol(Foo, Decl(ambientNameRestrictions.ts, 0, 0))
export var static: any;
>static : Symbol(static, Decl(ambientNameRestrictions.ts, 1, 12))
}

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/ambientNameRestrictions.ts ===
export declare namespace Foo {
>Foo : typeof Foo
export var static: any;
>static : any
}

View File

@ -5,7 +5,7 @@ tests/cases/compiler/assignmentToObjectAndFunction.ts(8,5): error TS2322: Type '
Property 'apply' is missing in type '{}'.
tests/cases/compiler/assignmentToObjectAndFunction.ts(29,5): error TS2322: Type 'typeof bad' is not assignable to type 'Function'.
Types of property 'apply' are incompatible.
Type 'number' is not assignable to type '{ <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }'.
Type 'number' is not assignable to type '(this: Function, thisArg: any, argArray?: any) => any'.
==== tests/cases/compiler/assignmentToObjectAndFunction.ts (3 errors) ====
@ -48,4 +48,4 @@ tests/cases/compiler/assignmentToObjectAndFunction.ts(29,5): error TS2322: Type
~~~~~~~~~~
!!! error TS2322: Type 'typeof bad' is not assignable to type 'Function'.
!!! error TS2322: Types of property 'apply' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type '{ <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }'.
!!! error TS2322: Type 'number' is not assignable to type '(this: Function, thisArg: any, argArray?: any) => any'.

View File

@ -10,9 +10,9 @@ class C {
var fn = async () => await other.apply(this, arguments);
>fn : Symbol(fn, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 3, 9))
>other.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>other.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
>other : Symbol(other, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 1, 13))
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
>this : Symbol(C, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 0, 0))
>arguments : Symbol(arguments)
}

View File

@ -9,13 +9,13 @@ class C {
>other : () => void
var fn = async () => await other.apply(this, arguments);
>fn : () => Promise<void>
>async () => await other.apply(this, arguments) : () => Promise<void>
>await other.apply(this, arguments) : void
>other.apply(this, arguments) : void
>other.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>fn : () => Promise<any>
>async () => await other.apply(this, arguments) : () => Promise<any>
>await other.apply(this, arguments) : any
>other.apply(this, arguments) : any
>other.apply : (this: Function, thisArg: any, argArray?: any) => any
>other : () => void
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>this : this
>arguments : IArguments
}

View File

@ -21,10 +21,6 @@ var v = {
>a : Symbol(a, Decl(commentsOnObjectLiteral3.ts, 8, 13), Decl(commentsOnObjectLiteral3.ts, 12, 18))
return this.prop;
>this.prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
>this : Symbol(, Decl(commentsOnObjectLiteral3.ts, 1, 7))
>prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
} /*trailing 1*/,
//setter
set a(value) {
@ -32,9 +28,6 @@ var v = {
>value : Symbol(value, Decl(commentsOnObjectLiteral3.ts, 14, 7))
this.prop = value;
>this.prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
>this : Symbol(, Decl(commentsOnObjectLiteral3.ts, 1, 7))
>prop : Symbol(prop, Decl(commentsOnObjectLiteral3.ts, 1, 9))
>value : Symbol(value, Decl(commentsOnObjectLiteral3.ts, 14, 7))
} // trailing 2

View File

@ -24,9 +24,9 @@ var v = {
>a : any
return this.prop;
>this.prop : number
>this : { prop: number; func: () => void; func1(): void; a: any; }
>prop : number
>this.prop : any
>this : any
>prop : any
} /*trailing 1*/,
//setter
@ -36,9 +36,9 @@ var v = {
this.prop = value;
>this.prop = value : any
>this.prop : number
>this : { prop: number; func: () => void; func1(): void; a: any; }
>prop : number
>this.prop : any
>this : any
>prop : any
>value : any
} // trailing 2

View File

@ -0,0 +1,15 @@
//// [controlFlowDestructuringParameters.ts]
// Repro for #8376
[{ x: 1 }].map(
({ x }) => x
);
//// [controlFlowDestructuringParameters.js]
// Repro for #8376
[{ x: 1 }].map(function (_a) {
var x = _a.x;
return x;
});

View File

@ -0,0 +1,15 @@
=== tests/cases/compiler/controlFlowDestructuringParameters.ts ===
// Repro for #8376
[{ x: 1 }].map(
>[{ x: 1 }].map : Symbol(Array.map, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 3, 2))
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
({ x }) => x
>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 4, 4))
>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 4, 4))
);

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/controlFlowDestructuringParameters.ts ===
// Repro for #8376
[{ x: 1 }].map(
>[{ x: 1 }].map( ({ x }) => x) : number[]
>[{ x: 1 }].map : <U>(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any) => U[]
>[{ x: 1 }] : { x: number; }[]
>{ x: 1 } : { x: number; }
>x : number
>1 : number
>map : <U>(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any) => U[]
({ x }) => x
>({ x }) => x : ({x}: { x: number; }) => number
>x : number
>x : number
);

View File

@ -0,0 +1,40 @@
//// [controlFlowIteration.ts]
let cond: boolean;
function ff() {
let x: string | undefined;
while (true) {
if (cond) {
x = "";
}
else {
if (x) {
x.length;
}
if (x) {
x.length;
}
}
}
}
//// [controlFlowIteration.js]
var cond;
function ff() {
var x;
while (true) {
if (cond) {
x = "";
}
else {
if (x) {
x.length;
}
if (x) {
x.length;
}
}
}
}

View File

@ -0,0 +1,39 @@
=== tests/cases/conformance/controlFlow/controlFlowIteration.ts ===
let cond: boolean;
>cond : Symbol(cond, Decl(controlFlowIteration.ts, 1, 3))
function ff() {
>ff : Symbol(ff, Decl(controlFlowIteration.ts, 1, 18))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7))
while (true) {
if (cond) {
>cond : Symbol(cond, Decl(controlFlowIteration.ts, 1, 3))
x = "";
>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7))
}
else {
if (x) {
>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7))
x.length;
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7))
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
}
if (x) {
>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7))
x.length;
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(controlFlowIteration.ts, 4, 7))
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
}
}
}
}

View File

@ -0,0 +1,43 @@
=== tests/cases/conformance/controlFlow/controlFlowIteration.ts ===
let cond: boolean;
>cond : boolean
function ff() {
>ff : () => void
let x: string | undefined;
>x : string | undefined
while (true) {
>true : boolean
if (cond) {
>cond : boolean
x = "";
>x = "" : string
>x : string | undefined
>"" : string
}
else {
if (x) {
>x : string | undefined
x.length;
>x.length : number
>x : string
>length : number
}
if (x) {
>x : string | undefined
x.length;
>x.length : number
>x : string
>length : number
}
}
}
}

View File

@ -0,0 +1,39 @@
tests/cases/compiler/controlFlowLoopAnalysis.ts(13,25): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
Type 'undefined' is not assignable to type 'number'.
==== tests/cases/compiler/controlFlowLoopAnalysis.ts (1 errors) ====
// Repro from #8418
let cond: boolean;
function foo(x: number): number { return 1; }
function test1() {
let x: number | undefined;
while (cond) {
while (cond) {
while (cond) {
x = foo(x);
~
!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
!!! error TS2345: Type 'undefined' is not assignable to type 'number'.
}
}
x = 1;
}
}
// Repro from #8418
function test2() {
let x: number | undefined;
x = 1;
while (cond) {
while (cond) {
x = foo(x);
}
}
}

View File

@ -0,0 +1,58 @@
//// [controlFlowLoopAnalysis.ts]
// Repro from #8418
let cond: boolean;
function foo(x: number): number { return 1; }
function test1() {
let x: number | undefined;
while (cond) {
while (cond) {
while (cond) {
x = foo(x);
}
}
x = 1;
}
}
// Repro from #8418
function test2() {
let x: number | undefined;
x = 1;
while (cond) {
while (cond) {
x = foo(x);
}
}
}
//// [controlFlowLoopAnalysis.js]
// Repro from #8418
var cond;
function foo(x) { return 1; }
function test1() {
var x;
while (cond) {
while (cond) {
while (cond) {
x = foo(x);
}
}
x = 1;
}
}
// Repro from #8418
function test2() {
var x;
x = 1;
while (cond) {
while (cond) {
x = foo(x);
}
}
}

View File

@ -15,9 +15,6 @@ function /*1*/makePoint(x: number) {
set x(a: number) { this.b = a; }
>x : Symbol(x, Decl(declFileObjectLiteralWithAccessors.ts, 3, 14), Decl(declFileObjectLiteralWithAccessors.ts, 4, 30))
>a : Symbol(a, Decl(declFileObjectLiteralWithAccessors.ts, 5, 14))
>this.b : Symbol(b, Decl(declFileObjectLiteralWithAccessors.ts, 2, 12))
>this : Symbol(, Decl(declFileObjectLiteralWithAccessors.ts, 2, 10))
>b : Symbol(b, Decl(declFileObjectLiteralWithAccessors.ts, 2, 12))
>a : Symbol(a, Decl(declFileObjectLiteralWithAccessors.ts, 5, 14))
};

View File

@ -19,9 +19,9 @@ function /*1*/makePoint(x: number) {
>x : number
>a : number
>this.b = a : number
>this.b : number
>this : { b: number; x: number; }
>b : number
>this.b : any
>this : any
>b : any
>a : number
};

View File

@ -11,9 +11,6 @@ function /*1*/makePoint(x: number) {
set x(a: number) { this.b = a; }
>x : Symbol(x, Decl(declFileObjectLiteralWithOnlySetter.ts, 3, 14))
>a : Symbol(a, Decl(declFileObjectLiteralWithOnlySetter.ts, 4, 14))
>this.b : Symbol(b, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 12))
>this : Symbol(, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 10))
>b : Symbol(b, Decl(declFileObjectLiteralWithOnlySetter.ts, 2, 12))
>a : Symbol(a, Decl(declFileObjectLiteralWithOnlySetter.ts, 4, 14))
};

View File

@ -15,9 +15,9 @@ function /*1*/makePoint(x: number) {
>x : number
>a : number
>this.b = a : number
>this.b : number
>this : { b: number; x: number; }
>b : number
>this.b : any
>this : any
>b : any
>a : number
};

View File

@ -68,9 +68,9 @@ export async function runSampleWorks<A, B, C, D, E>(
>T : Symbol(T, Decl(declarationEmitPromise.ts, 8, 16))
f.apply(this, result);
>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
>f : Symbol(f, Decl(declarationEmitPromise.ts, 8, 19))
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
>result : Symbol(result, Decl(declarationEmitPromise.ts, 7, 7))
let rfunc: typeof func & {} = func as any; // <- This is the only difference
@ -140,9 +140,9 @@ export async function runSampleBreaks<A, B, C, D, E>(
>T : Symbol(T, Decl(declarationEmitPromise.ts, 17, 16))
f.apply(this, result);
>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
>f : Symbol(f, Decl(declarationEmitPromise.ts, 17, 19))
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
>result : Symbol(result, Decl(declarationEmitPromise.ts, 16, 7))
let rfunc: typeof func = func as any; // <- This is the only difference

View File

@ -78,10 +78,10 @@ export async function runSampleWorks<A, B, C, D, E>(
>T : T
f.apply(this, result);
>f.apply(this, result) : T
>f.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>f.apply(this, result) : any
>f.apply : (this: Function, thisArg: any, argArray?: any) => any
>f : (a: A, b?: B, c?: C, d?: D, e?: E) => T
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>this : any
>result : any
@ -163,10 +163,10 @@ export async function runSampleBreaks<A, B, C, D, E>(
>T : T
f.apply(this, result);
>f.apply(this, result) : T
>f.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>f.apply(this, result) : any
>f.apply : (this: Function, thisArg: any, argArray?: any) => any
>f : (a: A, b?: B, c?: C, d?: D, e?: E) => T
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>this : any
>result : any

View File

@ -1,9 +1,7 @@
tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts(9,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts(10,19): error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'.
Property 'a' is missing in type '{ m(): this is Foo; }'.
==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts (2 errors) ====
==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts (1 errors) ====
export interface Foo {
a: string;
@ -16,9 +14,6 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredic
~~~~
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
let dis = this as Foo;
~~~~~~~~~~~
!!! error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'.
!!! error TS2352: Property 'a' is missing in type '{ m(): this is Foo; }'.
return dis.a != null && dis.b != null && dis.c != null;
}
}

View File

@ -1,10 +1,8 @@
tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(8,14): error TS4025: Exported variable 'obj' has or is using private name 'Foo'.
tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(9,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(10,19): error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'.
Property 'a' is missing in type '{ m(): this is Foo; }'.
==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (3 errors) ====
==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (2 errors) ====
interface Foo {
a: string;
@ -19,9 +17,6 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredic
~~~~
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
let dis = this as Foo;
~~~~~~~~~~~
!!! error TS2352: Type '{ m(): this is Foo; }' cannot be converted to type 'Foo'.
!!! error TS2352: Property 'a' is missing in type '{ m(): this is Foo; }'.
return dis.a != null && dis.b != null && dis.c != null;
}
}

View File

@ -0,0 +1,53 @@
//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts] ////
//// [a.ts]
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
export default x;
//// [b.ts]
import x from './a';
( async function() {
const value = await x;
}() );
//// [a.js]
(function (factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
}
else if (typeof define === 'function' && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
const x = new Promise((resolve, reject) => { resolve({}); });
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = x;
});
//// [b.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
(function (factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
}
else if (typeof define === 'function' && define.amd) {
define(["require", "exports", './a'], factory);
}
})(function (require, exports) {
"use strict";
const a_1 = require('./a');
(function () {
return __awaiter(this, void 0, void 0, function* () {
const value = yield a_1.default;
});
}());
});

View File

@ -0,0 +1,22 @@
=== tests/cases/conformance/es6/modules/a.ts ===
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
>x : Symbol(x, Decl(a.ts, 0, 5))
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
>reject : Symbol(reject, Decl(a.ts, 0, 33))
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
export default x;
>x : Symbol(x, Decl(a.ts, 0, 5))
=== tests/cases/conformance/es6/modules/b.ts ===
import x from './a';
>x : Symbol(x, Decl(b.ts, 0, 6))
( async function() {
const value = await x;
>value : Symbol(value, Decl(b.ts, 3, 9))
>x : Symbol(x, Decl(b.ts, 0, 6))
}() );

View File

@ -0,0 +1,31 @@
=== tests/cases/conformance/es6/modules/a.ts ===
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
>x : Promise<{}>
>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}>
>Promise : PromiseConstructor
>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void
>resolve : (value?: {} | PromiseLike<{}>) => void
>reject : (reason?: any) => void
>resolve( {} ) : void
>resolve : (value?: {} | PromiseLike<{}>) => void
>{} : {}
export default x;
>x : Promise<{}>
=== tests/cases/conformance/es6/modules/b.ts ===
import x from './a';
>x : Promise<{}>
( async function() {
>( async function() { const value = await x;}() ) : Promise<void>
>async function() { const value = await x;}() : Promise<void>
>async function() { const value = await x;} : () => Promise<void>
const value = await x;
>value : {}
>await x : {}
>x : Promise<{}>
}() );

View File

@ -0,0 +1,35 @@
//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts] ////
//// [a.ts]
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
export default x;
//// [b.ts]
import x from './a';
( async function() {
const value = await x;
}() );
//// [a.js]
"use strict";
const x = new Promise((resolve, reject) => { resolve({}); });
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = x;
//// [b.js]
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
const a_1 = require('./a');
(function () {
return __awaiter(this, void 0, void 0, function* () {
const value = yield a_1.default;
});
}());

View File

@ -0,0 +1,22 @@
=== tests/cases/conformance/es6/modules/a.ts ===
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
>x : Symbol(x, Decl(a.ts, 0, 5))
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
>reject : Symbol(reject, Decl(a.ts, 0, 33))
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
export default x;
>x : Symbol(x, Decl(a.ts, 0, 5))
=== tests/cases/conformance/es6/modules/b.ts ===
import x from './a';
>x : Symbol(x, Decl(b.ts, 0, 6))
( async function() {
const value = await x;
>value : Symbol(value, Decl(b.ts, 3, 9))
>x : Symbol(x, Decl(b.ts, 0, 6))
}() );

View File

@ -0,0 +1,31 @@
=== tests/cases/conformance/es6/modules/a.ts ===
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
>x : Promise<{}>
>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}>
>Promise : PromiseConstructor
>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void
>resolve : (value?: {} | PromiseLike<{}>) => void
>reject : (reason?: any) => void
>resolve( {} ) : void
>resolve : (value?: {} | PromiseLike<{}>) => void
>{} : {}
export default x;
>x : Promise<{}>
=== tests/cases/conformance/es6/modules/b.ts ===
import x from './a';
>x : Promise<{}>
( async function() {
>( async function() { const value = await x;}() ) : Promise<void>
>async function() { const value = await x;}() : Promise<void>
>async function() { const value = await x;} : () => Promise<void>
const value = await x;
>value : {}
>await x : {}
>x : Promise<{}>
}() );

View File

@ -0,0 +1,22 @@
//// [defaultOfAnyInStrictNullChecks.ts]
// Regression test for #8295
function foo() {
try {
}
catch (e) {
let s = e.message;
}
}
//// [defaultOfAnyInStrictNullChecks.js]
// Regression test for #8295
function foo() {
try {
}
catch (e) {
var s = e.message;
}
}

View File

@ -0,0 +1,18 @@
=== tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts ===
// Regression test for #8295
function foo() {
>foo : Symbol(foo, Decl(defaultOfAnyInStrictNullChecks.ts, 0, 0))
try {
}
catch (e) {
>e : Symbol(e, Decl(defaultOfAnyInStrictNullChecks.ts, 6, 11))
let s = e.message;
>s : Symbol(s, Decl(defaultOfAnyInStrictNullChecks.ts, 7, 11))
>e : Symbol(e, Decl(defaultOfAnyInStrictNullChecks.ts, 6, 11))
}
}

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts ===
// Regression test for #8295
function foo() {
>foo : () => void
try {
}
catch (e) {
>e : any
let s = e.message;
>s : any
>e.message : any
>e : any
>message : any
}
}

View File

@ -8,18 +8,11 @@ var object = {
get 0() {
return this._0;
>this._0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
>this : Symbol(, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 12))
>_0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
},
set 0(x: number) {
>x : Symbol(x, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 6, 10))
this._0 = x;
>this._0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
>this : Symbol(, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 12))
>_0 : Symbol(_0, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 1, 14))
>x : Symbol(x, Decl(emitCompoundExponentiationAssignmentWithIndexingOnLHS3.ts, 6, 10))
},

View File

@ -10,9 +10,9 @@ var object = {
get 0() {
return this._0;
>this._0 : number
>this : { 0: number; _0: number; }
>_0 : number
>this._0 : any
>this : any
>_0 : any
},
set 0(x: number) {
@ -20,9 +20,9 @@ var object = {
this._0 = x;
>this._0 = x : number
>this._0 : number
>this : { 0: number; _0: number; }
>_0 : number
>this._0 : any
>this : any
>_0 : any
>x : number
},

View File

@ -12,7 +12,7 @@ function fn(x = () => this, y = x()) {
}
fn.call(4); // Should be 4
>fn.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>fn.call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>fn : Symbol(fn, Decl(fatarrowfunctionsInFunctionParameterDefaults.ts, 0, 0))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --))

View File

@ -16,8 +16,8 @@ function fn(x = () => this, y = x()) {
fn.call(4); // Should be 4
>fn.call(4) : any
>fn.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>fn.call : (this: Function, thisArg: any, ...argArray: any[]) => any
>fn : (x?: () => any, y?: any) => any
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>call : (this: Function, thisArg: any, ...argArray: any[]) => any
>4 : number

View File

@ -3,9 +3,9 @@ function salt() {}
>salt : Symbol(salt, Decl(functionType.ts, 0, 0))
salt.apply("hello", []);
>salt.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>salt.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>salt : Symbol(salt, Decl(functionType.ts, 0, 0))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
(new Function("return 5"))();
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

View File

@ -3,10 +3,10 @@ function salt() {}
>salt : () => void
salt.apply("hello", []);
>salt.apply("hello", []) : void
>salt.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>salt.apply("hello", []) : any
>salt.apply : (this: Function, thisArg: any, argArray?: any) => any
>salt : () => void
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>"hello" : string
>[] : undefined[]

View File

@ -4,7 +4,6 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on
Types of property 'oneI' are incompatible.
Type 'this' is not assignable to type 'I'.
Type 'C' is not assignable to type 'I'.
Property 'alsoWorks' is missing in type 'C'.
tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Type '{ oneI: this; }' cannot be converted to type 'R'.
Property 'anything' is missing in type '{ oneI: this; }'.
@ -39,7 +38,6 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Type '{ oneI: this; }' canno
!!! error TS2322: Types of property 'oneI' are incompatible.
!!! error TS2322: Type 'this' is not assignable to type 'I'.
!!! error TS2322: Type 'C' is not assignable to type 'I'.
!!! error TS2322: Property 'alsoWorks' is missing in type 'C'.
}
worksToo():R {

View File

@ -24,9 +24,9 @@ function compose<A, B, C>(f: (b: B) => C, g: (a:A) => B): (a:A) => C {
return f(g.apply(null, a));
>f : Symbol(f, Decl(genericTypeParameterEquivalence2.ts, 1, 26))
>g.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>g.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>g : Symbol(g, Decl(genericTypeParameterEquivalence2.ts, 1, 41))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(genericTypeParameterEquivalence2.ts, 2, 21))
};

View File

@ -26,10 +26,10 @@ function compose<A, B, C>(f: (b: B) => C, g: (a:A) => B): (a:A) => C {
return f(g.apply(null, a));
>f(g.apply(null, a)) : C
>f : (b: B) => C
>g.apply(null, a) : B
>g.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>g.apply(null, a) : any
>g.apply : (this: Function, thisArg: any, argArray?: any) => any
>g : (a: A) => B
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>null : null
>a : A

View File

@ -133,8 +133,8 @@ function fn5(x: Derived1) {
// 1.5: y: Derived1
// Want: ???
let y = x;
>y : {}
>x : {}
>y : nothing
>x : nothing
}
}

View File

@ -26,39 +26,39 @@ function apply(func, thisArg, args) {
>length : Symbol(length, Decl(_apply.js, 12, 7))
case 0: return func.call(thisArg);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
case 1: return func.call(thisArg, args[0]);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
case 2: return func.call(thisArg, args[0], args[1]);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>args : Symbol(args, Decl(_apply.js, 11, 29))
case 3: return func.call(thisArg, args[0], args[1], args[2]);
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func.call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>call : Symbol(Function.call, Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>args : Symbol(args, Decl(_apply.js, 11, 29))
>args : Symbol(args, Decl(_apply.js, 11, 29))
}
return func.apply(thisArg, args);
>func.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>func.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>func : Symbol(func, Decl(_apply.js, 11, 15))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>thisArg : Symbol(thisArg, Decl(_apply.js, 11, 20))
>args : Symbol(args, Decl(_apply.js, 11, 29))
}

View File

@ -28,17 +28,17 @@ function apply(func, thisArg, args) {
case 0: return func.call(thisArg);
>0 : number
>func.call(thisArg) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>call : (this: Function, thisArg: any, ...argArray: any[]) => any
>thisArg : any
case 1: return func.call(thisArg, args[0]);
>1 : number
>func.call(thisArg, args[0]) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>call : (this: Function, thisArg: any, ...argArray: any[]) => any
>thisArg : any
>args[0] : any
>args : any[]
@ -47,9 +47,9 @@ function apply(func, thisArg, args) {
case 2: return func.call(thisArg, args[0], args[1]);
>2 : number
>func.call(thisArg, args[0], args[1]) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>call : (this: Function, thisArg: any, ...argArray: any[]) => any
>thisArg : any
>args[0] : any
>args : any[]
@ -61,9 +61,9 @@ function apply(func, thisArg, args) {
case 3: return func.call(thisArg, args[0], args[1], args[2]);
>3 : number
>func.call(thisArg, args[0], args[1], args[2]) : any
>func.call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>func.call : (this: Function, thisArg: any, ...argArray: any[]) => any
>func : Function
>call : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; (this: Function, thisArg: any, ...argArray: any[]): any; }
>call : (this: Function, thisArg: any, ...argArray: any[]) => any
>thisArg : any
>args[0] : any
>args : any[]
@ -77,9 +77,9 @@ function apply(func, thisArg, args) {
}
return func.apply(thisArg, args);
>func.apply(thisArg, args) : any
>func.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>func.apply : (this: Function, thisArg: any, argArray?: any) => any
>func : Function
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>thisArg : any
>args : any[]
}

View File

@ -32,12 +32,12 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error
!!! error TS2322: Type '(this: C, m: number) => number' is not assignable to type '(this: void, m: number) => number'.
!!! error TS2322: The 'this' types of each signature are incompatible.
!!! error TS2322: Type 'void' is not assignable to type 'C'.
let o = {
let o = {
n: 101,
explicitThis: function (m: number) {
return m + this.n.length; // ok, this.n: any
explicitThis: function (m: number) {
return m + this.n.length; // error, 'length' does not exist on 'number'
},
implicitThis(m: number): number { return m; }
implicitThis(m: number): number { return m; }
};
let i: I = o;
let o2: I = {
@ -63,4 +63,5 @@ tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error
return this.n.length; // error, this.n: number
~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'number'.
}
}

View File

@ -20,12 +20,12 @@ class C implements I {
}
let c = new C();
c.explicitVoid = c.explicitThis; // error, 'void' is missing everything
let o = {
let o = {
n: 101,
explicitThis: function (m: number) {
return m + this.n.length; // ok, this.n: any
explicitThis: function (m: number) {
return m + this.n.length; // error, 'length' does not exist on 'number'
},
implicitThis(m: number): number { return m; }
implicitThis(m: number): number { return m; }
};
let i: I = o;
let o2: I = {
@ -45,7 +45,8 @@ o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to
o.implicitThis = i.explicitThis;
i.explicitThis = function(m) {
return this.n.length; // error, this.n: number
}
}
//// [looseThisTypeInFunctions.js]
var C = (function () {
@ -67,7 +68,7 @@ c.explicitVoid = c.explicitThis; // error, 'void' is missing everything
var o = {
n: 101,
explicitThis: function (m) {
return m + this.n.length; // ok, this.n: any
return m + this.n.length; // error, 'length' does not exist on 'number'
},
implicitThis: function (m) { return m; }
};

View File

@ -0,0 +1,80 @@
//// [narrowingOfDottedNames.ts]
// Repro from #8383
class A {
prop: { a: string; };
}
class B {
prop: { b: string; }
}
function isA(x: any): x is A {
return x instanceof A;
}
function isB(x: any): x is B {
return x instanceof B;
}
function f1(x: A | B) {
while (true) {
if (x instanceof A) {
x.prop.a;
}
else if (x instanceof B) {
x.prop.b;
}
}
}
function f2(x: A | B) {
while (true) {
if (isA(x)) {
x.prop.a;
}
else if (isB(x)) {
x.prop.b;
}
}
}
//// [narrowingOfDottedNames.js]
// Repro from #8383
var A = (function () {
function A() {
}
return A;
}());
var B = (function () {
function B() {
}
return B;
}());
function isA(x) {
return x instanceof A;
}
function isB(x) {
return x instanceof B;
}
function f1(x) {
while (true) {
if (x instanceof A) {
x.prop.a;
}
else if (x instanceof B) {
x.prop.b;
}
}
}
function f2(x) {
while (true) {
if (isA(x)) {
x.prop.a;
}
else if (isB(x)) {
x.prop.b;
}
}
}

View File

@ -0,0 +1,105 @@
=== tests/cases/compiler/narrowingOfDottedNames.ts ===
// Repro from #8383
class A {
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
prop: { a: string; };
>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
}
class B {
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
prop: { b: string; }
>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
}
function isA(x: any): x is A {
>isA : Symbol(isA, Decl(narrowingOfDottedNames.ts, 8, 1))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13))
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
return x instanceof A;
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13))
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
}
function isB(x: any): x is B {
>isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13))
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
return x instanceof B;
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13))
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
}
function f1(x: A | B) {
>f1 : Symbol(f1, Decl(narrowingOfDottedNames.ts, 16, 1))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
while (true) {
if (x instanceof A) {
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
x.prop.a;
>x.prop.a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
>x.prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
}
else if (x instanceof B) {
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
x.prop.b;
>x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
>x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
}
}
}
function f2(x: A | B) {
>f2 : Symbol(f2, Decl(narrowingOfDottedNames.ts, 27, 1))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
while (true) {
if (isA(x)) {
>isA : Symbol(isA, Decl(narrowingOfDottedNames.ts, 8, 1))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
x.prop.a;
>x.prop.a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
>x.prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
}
else if (isB(x)) {
>isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
x.prop.b;
>x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
>x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
}
}
}

View File

@ -0,0 +1,115 @@
=== tests/cases/compiler/narrowingOfDottedNames.ts ===
// Repro from #8383
class A {
>A : A
prop: { a: string; };
>prop : { a: string; }
>a : string
}
class B {
>B : B
prop: { b: string; }
>prop : { b: string; }
>b : string
}
function isA(x: any): x is A {
>isA : (x: any) => x is A
>x : any
>x : any
>A : A
return x instanceof A;
>x instanceof A : boolean
>x : any
>A : typeof A
}
function isB(x: any): x is B {
>isB : (x: any) => x is B
>x : any
>x : any
>B : B
return x instanceof B;
>x instanceof B : boolean
>x : any
>B : typeof B
}
function f1(x: A | B) {
>f1 : (x: A | B) => void
>x : A | B
>A : A
>B : B
while (true) {
>true : boolean
if (x instanceof A) {
>x instanceof A : boolean
>x : A | B
>A : typeof A
x.prop.a;
>x.prop.a : string
>x.prop : { a: string; }
>x : A
>prop : { a: string; }
>a : string
}
else if (x instanceof B) {
>x instanceof B : boolean
>x : B
>B : typeof B
x.prop.b;
>x.prop.b : string
>x.prop : { b: string; }
>x : B
>prop : { b: string; }
>b : string
}
}
}
function f2(x: A | B) {
>f2 : (x: A | B) => void
>x : A | B
>A : A
>B : B
while (true) {
>true : boolean
if (isA(x)) {
>isA(x) : boolean
>isA : (x: any) => x is A
>x : A | B
x.prop.a;
>x.prop.a : string
>x.prop : { a: string; }
>x : A
>prop : { a: string; }
>a : string
}
else if (isB(x)) {
>isB(x) : boolean
>isB : (x: any) => x is B
>x : B
x.prop.b;
>x.prop.b : string
>x.prop : { b: string; }
>x : B
>prop : { b: string; }
>b : string
}
}
}

View File

@ -0,0 +1,22 @@
tests/cases/compiler/noImplicitThisObjectLiterals.ts(2,8): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/compiler/noImplicitThisObjectLiterals.ts(4,16): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/compiler/noImplicitThisObjectLiterals.ts(7,16): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
==== tests/cases/compiler/noImplicitThisObjectLiterals.ts (3 errors) ====
let o = {
d: this, // error, this: any
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
m() {
return this.d.length; // error, this: any
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
},
f: function() {
return this.d.length; // error, this: any
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
}
}

View File

@ -0,0 +1,22 @@
//// [noImplicitThisObjectLiterals.ts]
let o = {
d: this, // error, this: any
m() {
return this.d.length; // error, this: any
},
f: function() {
return this.d.length; // error, this: any
}
}
//// [noImplicitThisObjectLiterals.js]
var o = {
d: this,
m: function () {
return this.d.length; // error, this: any
},
f: function () {
return this.d.length; // error, this: any
}
};

View File

@ -20,9 +20,9 @@ var r2b: (x: any, y?: any) => any = i.apply;
>r2b : Symbol(r2b, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 9, 3))
>x : Symbol(x, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 9, 10))
>y : Symbol(y, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 9, 17))
>i.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>i.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>i : Symbol(i, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 7, 3))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
var b: {
>b : Symbol(b, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 11, 3))
@ -38,7 +38,7 @@ var rb4: (x: any, y?: any) => any = b.apply;
>rb4 : Symbol(rb4, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 16, 3))
>x : Symbol(x, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 16, 10))
>y : Symbol(y, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 16, 17))
>b.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>b.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>b : Symbol(b, Decl(objectTypeWithCallSignatureAppearsToBeFunctionType.ts, 11, 3))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))

View File

@ -21,9 +21,9 @@ var r2b: (x: any, y?: any) => any = i.apply;
>r2b : (x: any, y?: any) => any
>x : any
>y : any
>i.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>i.apply : (this: Function, thisArg: any, argArray?: any) => any
>i : I
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
var b: {
>b : () => void
@ -40,7 +40,7 @@ var rb4: (x: any, y?: any) => any = b.apply;
>rb4 : (x: any, y?: any) => any
>x : any
>y : any
>b.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>b.apply : (this: Function, thisArg: any, argArray?: any) => any
>b : () => void
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any

View File

@ -0,0 +1,27 @@
//// [recurringTypeParamForContainerOfBase01.ts]
interface BoxOfFoo<T extends Foo<T>> {
item: T
}
interface Foo<T extends Foo<T>> {
self: T;
}
interface Bar<T extends Bar<T>> extends Foo<T> {
other: BoxOfFoo<T>;
}
//// [recurringTypeParamForContainerOfBase01.js]
//// [recurringTypeParamForContainerOfBase01.d.ts]
interface BoxOfFoo<T extends Foo<T>> {
item: T;
}
interface Foo<T extends Foo<T>> {
self: T;
}
interface Bar<T extends Bar<T>> extends Foo<T> {
other: BoxOfFoo<T>;
}

View File

@ -0,0 +1,37 @@
=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts ===
interface BoxOfFoo<T extends Foo<T>> {
>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19))
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19))
item: T
>item : Symbol(BoxOfFoo.item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19))
}
interface Foo<T extends Foo<T>> {
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14))
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14))
self: T;
>self : Symbol(Foo.self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14))
}
interface Bar<T extends Bar<T>> extends Foo<T> {
>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
other: BoxOfFoo<T>;
>other : Symbol(Bar.other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48))
>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0))
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
}

View File

@ -0,0 +1,37 @@
=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts ===
interface BoxOfFoo<T extends Foo<T>> {
>BoxOfFoo : BoxOfFoo<T>
>T : T
>Foo : Foo<T>
>T : T
item: T
>item : T
>T : T
}
interface Foo<T extends Foo<T>> {
>Foo : Foo<T>
>T : T
>Foo : Foo<T>
>T : T
self: T;
>self : T
>T : T
}
interface Bar<T extends Bar<T>> extends Foo<T> {
>Bar : Bar<T>
>T : T
>Bar : Bar<T>
>T : T
>Foo : Foo<T>
>T : T
other: BoxOfFoo<T>;
>other : BoxOfFoo<T>
>BoxOfFoo : BoxOfFoo<T>
>T : T
}

View File

@ -12,13 +12,13 @@ module M1 {
>A : Symbol(A, Decl(returnTypeParameterWithModules.ts, 1, 27))
return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]);
>Array.prototype.reduce.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>Array.prototype.reduce.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>Array.prototype.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>Array.prototype : Symbol(ArrayConstructor.prototype, Decl(lib.d.ts, --, --))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>prototype : Symbol(ArrayConstructor.prototype, Decl(lib.d.ts, --, --))
>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>ar : Symbol(ar, Decl(returnTypeParameterWithModules.ts, 1, 30))
>e : Symbol(e, Decl(returnTypeParameterWithModules.ts, 1, 36))
>f : Symbol(f, Decl(returnTypeParameterWithModules.ts, 1, 33))

View File

@ -13,13 +13,13 @@ module M1 {
return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]);
>Array.prototype.reduce.apply(ar, e ? [f, e] : [f]) : any
>Array.prototype.reduce.apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>Array.prototype.reduce.apply : (this: Function, thisArg: any, argArray?: any) => any
>Array.prototype.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
>Array.prototype : any[]
>Array : ArrayConstructor
>prototype : any[]
>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; <U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; }
>apply : { <T, U>(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; (this: Function, thisArg: any, argArray?: any): any; }
>apply : (this: Function, thisArg: any, argArray?: any) => any
>ar : any
>e ? [f, e] : [f] : any[]
>e : any

View File

@ -116,6 +116,6 @@ if (!hasKind(x, "B")) {
}
else {
let d = x;
>d : {}
>x : {}
>d : nothing
>x : nothing
}

View File

@ -110,6 +110,6 @@ if (!hasKind(x, "B")) {
}
else {
let d = x;
>d : {}
>x : {}
>d : nothing
>x : nothing
}

View File

@ -113,6 +113,6 @@ if (!hasKind(x, "B")) {
}
else {
let d = x;
>d : {}
>x : {}
>d : nothing
>x : nothing
}

View File

@ -1,8 +1,7 @@
tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(7,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type '{ x: this; y: number; }', but here has type '{ x: MyClass; y: number; }'.
tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(14,21): error TS2339: Property 'spaaace' does not exist on type '{ f(): any; }'.
==== tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts (2 errors) ====
==== tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts (1 errors) ====
class MyClass {
t: number;
@ -19,8 +18,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(14,21):
var obj = {
f() {
return this.spaaace;
~~~~~~~
!!! error TS2339: Property 'spaaace' does not exist on type '{ f(): any; }'.
}
};
var obj: { f: () => any; };

View File

@ -0,0 +1,27 @@
//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.ts]
interface BoxOfFoo<T extends Foo> {
item: T
}
interface Foo {
self: this;
}
interface Bar extends Foo {
other: BoxOfFoo<this>;
}
//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.js]
//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.d.ts]
interface BoxOfFoo<T extends Foo> {
item: T;
}
interface Foo {
self: this;
}
interface Bar extends Foo {
other: BoxOfFoo<this>;
}

View File

@ -0,0 +1,27 @@
=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts ===
interface BoxOfFoo<T extends Foo> {
>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0))
>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19))
>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1))
item: T
>item : Symbol(BoxOfFoo.item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35))
>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19))
}
interface Foo {
>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1))
self: this;
>self : Symbol(Foo.self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15))
}
interface Bar extends Foo {
>Bar : Symbol(Bar, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 7, 1))
>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1))
other: BoxOfFoo<this>;
>other : Symbol(Bar.other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27))
>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0))
}

View File

@ -0,0 +1,27 @@
=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts ===
interface BoxOfFoo<T extends Foo> {
>BoxOfFoo : BoxOfFoo<T>
>T : T
>Foo : Foo
item: T
>item : T
>T : T
}
interface Foo {
>Foo : Foo
self: this;
>self : this
}
interface Bar extends Foo {
>Bar : Bar
>Foo : Foo
other: BoxOfFoo<this>;
>other : BoxOfFoo<this>
>BoxOfFoo : BoxOfFoo<T>
}

View File

@ -0,0 +1,91 @@
//// [thisTypeInFunctions2.ts]
interface IndexedWithThis {
// this is a workaround for React
init?: (this: this) => void;
willDestroy?: (this: any) => void;
[propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any);
}
interface IndexedWithoutThis {
// this is what React would like to write (and what they write today)
init?: () => void;
willDestroy?: () => void;
[propName: string]: any;
}
interface SimpleInterface {
foo(n: string);
bar(): number;
}
declare function extend1(args: IndexedWithThis): void;
declare function extend2(args: IndexedWithoutThis): void;
declare function simple(arg: SimpleInterface): void;
extend1({
init() {
this // this: IndexedWithThis because of contextual typing.
// this.mine
this.willDestroy
},
mine: 12,
foo() {
this.url; // this: any because 'foo' matches the string indexer
this.willDestroy;
}
});
extend2({
init() {
this // this: any because the contextual signature of init doesn't specify this' type
this.mine
this.willDestroy
},
mine: 13,
foo() {
this // this: any because of the string indexer
this.mine
this.willDestroy
}
});
simple({
foo(n) {
return n.length + this.bar();
},
bar() {
return 14;
}
})
//// [thisTypeInFunctions2.js]
extend1({
init: function () {
this; // this: IndexedWithThis because of contextual typing.
// this.mine
this.willDestroy;
},
mine: 12,
foo: function () {
this.url; // this: any because 'foo' matches the string indexer
this.willDestroy;
}
});
extend2({
init: function () {
this; // this: any because the contextual signature of init doesn't specify this' type
this.mine;
this.willDestroy;
},
mine: 13,
foo: function () {
this; // this: any because of the string indexer
this.mine;
this.willDestroy;
}
});
simple({
foo: function (n) {
return n.length + this.bar();
},
bar: function () {
return 14;
}
});

View File

@ -0,0 +1,124 @@
=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts ===
interface IndexedWithThis {
>IndexedWithThis : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0))
// this is a workaround for React
init?: (this: this) => void;
>init : Symbol(IndexedWithThis.init, Decl(thisTypeInFunctions2.ts, 0, 27))
>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 2, 12))
willDestroy?: (this: any) => void;
>willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32))
>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 3, 19))
[propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any);
>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 4, 5))
>this : Symbol(this, Decl(thisTypeInFunctions2.ts, 4, 87))
>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 4, 97))
}
interface IndexedWithoutThis {
>IndexedWithoutThis : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1))
// this is what React would like to write (and what they write today)
init?: () => void;
>init : Symbol(IndexedWithoutThis.init, Decl(thisTypeInFunctions2.ts, 6, 30))
willDestroy?: () => void;
>willDestroy : Symbol(IndexedWithoutThis.willDestroy, Decl(thisTypeInFunctions2.ts, 8, 22))
[propName: string]: any;
>propName : Symbol(propName, Decl(thisTypeInFunctions2.ts, 10, 5))
}
interface SimpleInterface {
>SimpleInterface : Symbol(SimpleInterface, Decl(thisTypeInFunctions2.ts, 11, 1))
foo(n: string);
>foo : Symbol(SimpleInterface.foo, Decl(thisTypeInFunctions2.ts, 12, 27))
>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 13, 8))
bar(): number;
>bar : Symbol(SimpleInterface.bar, Decl(thisTypeInFunctions2.ts, 13, 19))
}
declare function extend1(args: IndexedWithThis): void;
>extend1 : Symbol(extend1, Decl(thisTypeInFunctions2.ts, 15, 1))
>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 16, 25))
>IndexedWithThis : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0))
declare function extend2(args: IndexedWithoutThis): void;
>extend2 : Symbol(extend2, Decl(thisTypeInFunctions2.ts, 16, 54))
>args : Symbol(args, Decl(thisTypeInFunctions2.ts, 17, 25))
>IndexedWithoutThis : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1))
declare function simple(arg: SimpleInterface): void;
>simple : Symbol(simple, Decl(thisTypeInFunctions2.ts, 17, 57))
>arg : Symbol(arg, Decl(thisTypeInFunctions2.ts, 18, 24))
>SimpleInterface : Symbol(SimpleInterface, Decl(thisTypeInFunctions2.ts, 11, 1))
extend1({
>extend1 : Symbol(extend1, Decl(thisTypeInFunctions2.ts, 15, 1))
init() {
>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 20, 9))
this // this: IndexedWithThis because of contextual typing.
>this : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0))
// this.mine
this.willDestroy
>this.willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32))
>this : Symbol(IndexedWithThis, Decl(thisTypeInFunctions2.ts, 0, 0))
>willDestroy : Symbol(IndexedWithThis.willDestroy, Decl(thisTypeInFunctions2.ts, 2, 32))
},
mine: 12,
>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 25, 6))
foo() {
>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 26, 13))
this.url; // this: any because 'foo' matches the string indexer
this.willDestroy;
}
});
extend2({
>extend2 : Symbol(extend2, Decl(thisTypeInFunctions2.ts, 16, 54))
init() {
>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 32, 9))
this // this: any because the contextual signature of init doesn't specify this' type
this.mine
this.willDestroy
},
mine: 13,
>mine : Symbol(mine, Decl(thisTypeInFunctions2.ts, 37, 6))
foo() {
>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 38, 13))
this // this: any because of the string indexer
this.mine
this.willDestroy
}
});
simple({
>simple : Symbol(simple, Decl(thisTypeInFunctions2.ts, 17, 57))
foo(n) {
>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 46, 8))
>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 47, 8))
return n.length + this.bar();
>n.length : Symbol(String.length, Decl(lib.d.ts, --, --))
>n : Symbol(n, Decl(thisTypeInFunctions2.ts, 47, 8))
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
},
bar() {
>bar : Symbol(bar, Decl(thisTypeInFunctions2.ts, 49, 6))
return 14;
}
})

View File

@ -0,0 +1,165 @@
=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts ===
interface IndexedWithThis {
>IndexedWithThis : IndexedWithThis
// this is a workaround for React
init?: (this: this) => void;
>init : (this: this) => void
>this : this
willDestroy?: (this: any) => void;
>willDestroy : (this: any) => void
>this : any
[propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any);
>propName : string
>null : null
>this : any
>args : any[]
}
interface IndexedWithoutThis {
>IndexedWithoutThis : IndexedWithoutThis
// this is what React would like to write (and what they write today)
init?: () => void;
>init : () => void
willDestroy?: () => void;
>willDestroy : () => void
[propName: string]: any;
>propName : string
}
interface SimpleInterface {
>SimpleInterface : SimpleInterface
foo(n: string);
>foo : (n: string) => any
>n : string
bar(): number;
>bar : () => number
}
declare function extend1(args: IndexedWithThis): void;
>extend1 : (args: IndexedWithThis) => void
>args : IndexedWithThis
>IndexedWithThis : IndexedWithThis
declare function extend2(args: IndexedWithoutThis): void;
>extend2 : (args: IndexedWithoutThis) => void
>args : IndexedWithoutThis
>IndexedWithoutThis : IndexedWithoutThis
declare function simple(arg: SimpleInterface): void;
>simple : (arg: SimpleInterface) => void
>arg : SimpleInterface
>SimpleInterface : SimpleInterface
extend1({
>extend1({ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; }}) : void
>extend1 : (args: IndexedWithThis) => void
>{ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; }} : { init(): void; mine: number; foo(): void; }
init() {
>init : () => void
this // this: IndexedWithThis because of contextual typing.
>this : IndexedWithThis
// this.mine
this.willDestroy
>this.willDestroy : (this: any) => void
>this : IndexedWithThis
>willDestroy : (this: any) => void
},
mine: 12,
>mine : number
>12 : number
foo() {
>foo : () => void
this.url; // this: any because 'foo' matches the string indexer
>this.url : any
>this : any
>url : any
this.willDestroy;
>this.willDestroy : any
>this : any
>willDestroy : any
}
});
extend2({
>extend2({ init() { this // this: any because the contextual signature of init doesn't specify this' type this.mine this.willDestroy }, mine: 13, foo() { this // this: any because of the string indexer this.mine this.willDestroy }}) : void
>extend2 : (args: IndexedWithoutThis) => void
>{ init() { this // this: any because the contextual signature of init doesn't specify this' type this.mine this.willDestroy }, mine: 13, foo() { this // this: any because of the string indexer this.mine this.willDestroy }} : { init(): void; mine: number; foo(): void; }
init() {
>init : () => void
this // this: any because the contextual signature of init doesn't specify this' type
>this : any
this.mine
>this.mine : any
>this : any
>mine : any
this.willDestroy
>this.willDestroy : any
>this : any
>willDestroy : any
},
mine: 13,
>mine : number
>13 : number
foo() {
>foo : () => void
this // this: any because of the string indexer
>this : any
this.mine
>this.mine : any
>this : any
>mine : any
this.willDestroy
>this.willDestroy : any
>this : any
>willDestroy : any
}
});
simple({
>simple({ foo(n) { return n.length + this.bar(); }, bar() { return 14; }}) : void
>simple : (arg: SimpleInterface) => void
>{ foo(n) { return n.length + this.bar(); }, bar() { return 14; }} : { foo(n: string): any; bar(): number; }
foo(n) {
>foo : (n: string) => any
>n : string
return n.length + this.bar();
>n.length + this.bar() : any
>n.length : number
>n : string
>length : number
>this.bar() : any
>this.bar : any
>this : any
>bar : any
},
bar() {
>bar : () => number
return 14;
>14 : number
}
})

View File

@ -3,8 +3,12 @@ let o = {
d: "bar",
m() {
return this.d.length;
},
f: function() {
return this.d.length;
}
}
let mutuallyRecursive = {
a: 100,
start() {
@ -35,6 +39,9 @@ var o = {
d: "bar",
m: function () {
return this.d.length;
},
f: function () {
return this.d.length;
}
};
var mutuallyRecursive = {

View File

@ -9,84 +9,72 @@ let o = {
>m : Symbol(m, Decl(thisTypeInObjectLiterals.ts, 1, 13))
return this.d.length;
>this.d.length : Symbol(String.length, Decl(lib.d.ts, --, --))
>this.d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9))
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 0, 7))
>d : Symbol(d, Decl(thisTypeInObjectLiterals.ts, 0, 9))
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
},
f: function() {
>f : Symbol(f, Decl(thisTypeInObjectLiterals.ts, 4, 6))
return this.d.length;
}
}
let mutuallyRecursive = {
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3))
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 10, 3))
a: 100,
>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25))
>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 10, 25))
start() {
>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11))
>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11))
return this.passthrough(this.a);
>this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
>this.a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25))
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25))
},
passthrough(n: number) {
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 11, 16))
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 14, 6))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 15, 16))
return this.sub1(n);
>this.sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6))
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 11, 16))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 15, 16))
},
sub1(n: number): number {
>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 17, 6))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9))
if (n > 0) {
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9))
return this.passthrough(n - 1);
>this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9))
}
return n;
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 18, 9))
}
}
var i: number = mutuallyRecursive.start();
>i : Symbol(i, Decl(thisTypeInObjectLiterals.ts, 21, 3))
>mutuallyRecursive.start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11))
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3))
>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11))
>i : Symbol(i, Decl(thisTypeInObjectLiterals.ts, 25, 3))
>mutuallyRecursive.start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11))
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 10, 3))
>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 11, 11))
interface I {
>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 21, 42))
>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 25, 42))
a: number;
>a : Symbol(I.a, Decl(thisTypeInObjectLiterals.ts, 22, 13))
>a : Symbol(I.a, Decl(thisTypeInObjectLiterals.ts, 26, 13))
start(): number;
>start : Symbol(I.start, Decl(thisTypeInObjectLiterals.ts, 23, 14))
>start : Symbol(I.start, Decl(thisTypeInObjectLiterals.ts, 27, 14))
passthrough(n: number): number;
>passthrough : Symbol(I.passthrough, Decl(thisTypeInObjectLiterals.ts, 24, 20))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 25, 16))
>passthrough : Symbol(I.passthrough, Decl(thisTypeInObjectLiterals.ts, 28, 20))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 29, 16))
sub1(n: number): number;
>sub1 : Symbol(I.sub1, Decl(thisTypeInObjectLiterals.ts, 25, 35))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 26, 9))
>sub1 : Symbol(I.sub1, Decl(thisTypeInObjectLiterals.ts, 29, 35))
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 30, 9))
}
var impl: I = mutuallyRecursive;
>impl : Symbol(impl, Decl(thisTypeInObjectLiterals.ts, 28, 3))
>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 21, 42))
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3))
>impl : Symbol(impl, Decl(thisTypeInObjectLiterals.ts, 32, 3))
>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 25, 42))
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 10, 3))

View File

@ -1,53 +1,66 @@
=== tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts ===
let o = {
>o : { d: string; m(): number; }
>{ d: "bar", m() { return this.d.length; }} : { d: string; m(): number; }
>o : { d: string; m(): any; f: () => any; }
>{ d: "bar", m() { return this.d.length; }, f: function() { return this.d.length; }} : { d: string; m(): any; f: () => any; }
d: "bar",
>d : string
>"bar" : string
m() {
>m : () => number
>m : () => any
return this.d.length;
>this.d.length : number
>this.d : string
>this : { d: string; m(): number; }
>d : string
>length : number
>this.d.length : any
>this.d : any
>this : any
>d : any
>length : any
},
f: function() {
>f : () => any
>function() { return this.d.length; } : () => any
return this.d.length;
>this.d.length : any
>this.d : any
>this : any
>d : any
>length : any
}
}
let mutuallyRecursive = {
>mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>{ a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; }} : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>mutuallyRecursive : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; }
>{ a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; }} : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; }
a: 100,
>a : number
>100 : number
start() {
>start : () => number
>start : () => any
return this.passthrough(this.a);
>this.passthrough(this.a) : number
>this.passthrough : (n: number) => number
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>passthrough : (n: number) => number
>this.a : number
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>a : number
>this.passthrough(this.a) : any
>this.passthrough : any
>this : any
>passthrough : any
>this.a : any
>this : any
>a : any
},
passthrough(n: number) {
>passthrough : (n: number) => number
>passthrough : (n: number) => any
>n : number
return this.sub1(n);
>this.sub1(n) : number
>this.sub1 : (n: number) => number
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>sub1 : (n: number) => number
>this.sub1(n) : any
>this.sub1 : any
>this : any
>sub1 : any
>n : number
},
@ -61,10 +74,10 @@ let mutuallyRecursive = {
>0 : number
return this.passthrough(n - 1);
>this.passthrough(n - 1) : number
>this.passthrough : (n: number) => number
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>passthrough : (n: number) => number
>this.passthrough(n - 1) : any
>this.passthrough : any
>this : any
>passthrough : any
>n - 1 : number
>n : number
>1 : number
@ -75,10 +88,10 @@ let mutuallyRecursive = {
}
var i: number = mutuallyRecursive.start();
>i : number
>mutuallyRecursive.start() : number
>mutuallyRecursive.start : () => number
>mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>start : () => number
>mutuallyRecursive.start() : any
>mutuallyRecursive.start : () => any
>mutuallyRecursive : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; }
>start : () => any
interface I {
>I : I
@ -100,5 +113,5 @@ interface I {
var impl: I = mutuallyRecursive;
>impl : I
>I : I
>mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
>mutuallyRecursive : { a: number; start(): any; passthrough(n: number): any; sub1(n: number): number; }

View File

@ -89,7 +89,6 @@ var aa = {
>biz : Symbol(biz, Decl(throwInEnclosingStatements.ts, 41, 10))
throw this;
>this : Symbol(, Decl(throwInEnclosingStatements.ts, 40, 8))
}
}

View File

@ -104,7 +104,7 @@ var aa = {
>biz : () => void
throw this;
>this : { id: number; biz(): void; }
>this : any
}
}

View File

@ -121,7 +121,7 @@ if (typeof strOrNum === "boolean") {
let z1: {} = strOrNum; // {}
>z1 : {}
>strOrNum : {}
>strOrNum : nothing
}
else {
let z2: string | number = strOrNum; // string | number
@ -215,6 +215,6 @@ if (typeof strOrNum !== "boolean") {
else {
let z2: {} = strOrNum; // {}
>z2 : {}
>strOrNum : {}
>strOrNum : nothing
}

View File

@ -120,7 +120,7 @@ if (typeof strOrBool === "number") {
let y1: {} = strOrBool; // {}
>y1 : {}
>strOrBool : {}
>strOrBool : nothing
}
else {
let y2: string | boolean = strOrBool; // string | boolean
@ -212,6 +212,6 @@ if (typeof strOrBool !== "number") {
else {
let y2: {} = strOrBool; // {}
>y2 : {}
>strOrBool : {}
>strOrBool : nothing
}

View File

@ -105,7 +105,7 @@ if (typeof strOrNumOrBool === "Object") {
let q1: {} = strOrNumOrBool; // {}
>q1 : {}
>strOrNumOrBool : {}
>strOrNumOrBool : nothing
}
else {
let q2: string | number | boolean = strOrNumOrBool; // string | number | boolean
@ -178,6 +178,6 @@ if (typeof strOrNumOrBool !== "Object") {
else {
let q2: {} = strOrNumOrBool; // {}
>q2 : {}
>strOrNumOrBool : {}
>strOrNumOrBool : nothing
}

View File

@ -121,7 +121,7 @@ if (typeof numOrBool === "string") {
let x1: {} = numOrBool; // {}
>x1 : {}
>numOrBool : {}
>numOrBool : nothing
}
else {
let x2: number | boolean = numOrBool; // number | boolean
@ -214,6 +214,6 @@ if (typeof numOrBool !== "string") {
else {
let x2: {} = numOrBool; // {}
>x2 : {}
>numOrBool : {}
>numOrBool : nothing
}

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