mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Check destructuring validity the same way element accesses and indexed accesses are checked (#24700)
* Check destructuring validity the same way element accesses and indexed accesses are checked * Accept updated test baseline * Use raw apparent type instead of passing in flag to sometimes make one * Use `checkComputedPropertyName`
This commit is contained in:
+35
-57
@@ -4635,6 +4635,10 @@ namespace ts {
|
||||
if (isTypeAny(parentType)) {
|
||||
return parentType;
|
||||
}
|
||||
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
|
||||
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
|
||||
parentType = getNonNullableType(parentType);
|
||||
}
|
||||
|
||||
let type: Type | undefined;
|
||||
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
@@ -4654,53 +4658,13 @@ namespace ts {
|
||||
else {
|
||||
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
|
||||
const name = declaration.propertyName || <Identifier>declaration.name;
|
||||
const isLate = isLateBindableName(name);
|
||||
const isWellKnown = isComputedPropertyName(name) && isWellKnownSymbolSyntactically(name.expression);
|
||||
if (!isLate && !isWellKnown && isComputedNonLiteralName(name)) {
|
||||
const exprType = checkExpression((name as ComputedPropertyName).expression);
|
||||
if (isTypeAssignableToKind(exprType, TypeFlags.ESSymbolLike)) {
|
||||
if (noImplicitAny) {
|
||||
error(declaration, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(exprType), typeToString(parentType));
|
||||
}
|
||||
return anyType;
|
||||
}
|
||||
const indexerType = isTypeAssignableToKind(exprType, TypeFlags.NumberLike) && getIndexTypeOfType(parentType, IndexKind.Number) || getIndexTypeOfType(parentType, IndexKind.String);
|
||||
if (!indexerType && noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) {
|
||||
if (getIndexTypeOfType(parentType, IndexKind.Number)) {
|
||||
error(declaration, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number);
|
||||
}
|
||||
else {
|
||||
error(declaration, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(parentType));
|
||||
}
|
||||
}
|
||||
return indexerType || anyType;
|
||||
}
|
||||
|
||||
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
|
||||
// or otherwise the type of the string index signature.
|
||||
const nameType = isLate ? checkComputedPropertyName(name as ComputedPropertyName) as LiteralType | UniqueESSymbolType : undefined;
|
||||
const text = isLate ? getLateBoundNameFromType(nameType!) :
|
||||
isWellKnown ? getPropertyNameForKnownSymbolName(idText(((name as ComputedPropertyName).expression as PropertyAccessExpression).name)) :
|
||||
getTextOfPropertyName(name);
|
||||
|
||||
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
|
||||
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
|
||||
parentType = getNonNullableType(parentType);
|
||||
}
|
||||
if (isLate && nameType && !getPropertyOfType(parentType, text) && isTypeAssignableToKind(nameType, TypeFlags.ESSymbolLike)) {
|
||||
if (noImplicitAny) {
|
||||
error(declaration, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(nameType), typeToString(parentType));
|
||||
}
|
||||
return anyType;
|
||||
}
|
||||
const declaredType = getConstraintForLocation(getTypeOfPropertyOfType(parentType, text), declaration.name);
|
||||
type = declaredType && getFlowTypeOfReference(declaration, declaredType) ||
|
||||
isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
|
||||
getIndexTypeOfType(parentType, IndexKind.String);
|
||||
if (!type) {
|
||||
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name));
|
||||
return errorType;
|
||||
}
|
||||
const exprType = isComputedPropertyName(name)
|
||||
? checkComputedPropertyName(name)
|
||||
: isIdentifier(name)
|
||||
? getLiteralType(unescapeLeadingUnderscores(name.escapedText))
|
||||
: checkExpression(name);
|
||||
const declaredType = checkIndexedAccessIndexType(getIndexedAccessType(getApparentType(parentType), exprType, name), name);
|
||||
type = getFlowTypeOfReference(declaration, getConstraintForLocation(declaredType, declaration.name));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -9359,12 +9323,16 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | undefined, cacheSymbol: boolean, missingType: Type) {
|
||||
function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | undefined, cacheSymbol: boolean, missingType: Type) {
|
||||
const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined;
|
||||
const propName = isTypeUsableAsLateBoundName(indexType) ? getLateBoundNameFromType(indexType) :
|
||||
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
|
||||
getPropertyNameForKnownSymbolName(idText((<PropertyAccessExpression>accessExpression.argumentExpression).name)) :
|
||||
undefined;
|
||||
const propName = isTypeUsableAsLateBoundName(indexType)
|
||||
? getLateBoundNameFromType(indexType)
|
||||
: accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false)
|
||||
? getPropertyNameForKnownSymbolName(idText((<PropertyAccessExpression>accessExpression.argumentExpression).name))
|
||||
: accessNode && isPropertyName(accessNode)
|
||||
// late bound names are handled in the first branch, so here we only need to handle normal names
|
||||
? getPropertyNameForPropertyNameNode(accessNode)
|
||||
: undefined;
|
||||
if (propName !== undefined) {
|
||||
const prop = getPropertyOfType(objectType, propName);
|
||||
if (prop) {
|
||||
@@ -9385,7 +9353,7 @@ namespace ts {
|
||||
}
|
||||
if (everyType(objectType, isTupleType) && isNumericLiteralName(propName) && +propName >= 0) {
|
||||
if (accessNode && everyType(objectType, t => !(<TupleTypeReference>t).target.hasRestElement)) {
|
||||
const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode.argumentExpression : accessNode.indexType;
|
||||
const indexNode = getIndexNodeForAccessExpression(accessNode);
|
||||
error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, unescapeLeadingUnderscores(propName), typeToString(objectType));
|
||||
}
|
||||
return mapType(objectType, t => getRestTypeOfTupleType(<TupleTypeReference>t) || undefinedType);
|
||||
@@ -9400,7 +9368,7 @@ namespace ts {
|
||||
undefined;
|
||||
if (indexInfo) {
|
||||
if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) {
|
||||
const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode.argumentExpression : accessNode.indexType;
|
||||
const indexNode = getIndexNodeForAccessExpression(accessNode);
|
||||
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
|
||||
}
|
||||
else if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) {
|
||||
@@ -9441,7 +9409,7 @@ namespace ts {
|
||||
return anyType;
|
||||
}
|
||||
if (accessNode) {
|
||||
const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode.argumentExpression : accessNode.indexType;
|
||||
const indexNode = getIndexNodeForAccessExpression(accessNode);
|
||||
if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
|
||||
error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (<LiteralType>indexType).value, typeToString(objectType));
|
||||
}
|
||||
@@ -9458,6 +9426,16 @@ namespace ts {
|
||||
return missingType;
|
||||
}
|
||||
|
||||
function getIndexNodeForAccessExpression(accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName) {
|
||||
return accessNode.kind === SyntaxKind.ElementAccessExpression
|
||||
? accessNode.argumentExpression
|
||||
: accessNode.kind === SyntaxKind.IndexedAccessType
|
||||
? accessNode.indexType
|
||||
: accessNode.kind === SyntaxKind.ComputedPropertyName
|
||||
? accessNode.expression
|
||||
: accessNode;
|
||||
}
|
||||
|
||||
function isGenericObjectType(type: Type): boolean {
|
||||
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.GenericMappedType);
|
||||
}
|
||||
@@ -9521,7 +9499,7 @@ namespace ts {
|
||||
return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper);
|
||||
}
|
||||
|
||||
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode, missingType = accessNode ? errorType : unknownType): Type {
|
||||
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName, missingType = accessNode ? errorType : unknownType): Type {
|
||||
if (objectType === wildcardType || indexType === wildcardType) {
|
||||
return wildcardType;
|
||||
}
|
||||
@@ -23207,7 +23185,7 @@ namespace ts {
|
||||
forEach(node.types, checkSourceElement);
|
||||
}
|
||||
|
||||
function checkIndexedAccessIndexType(type: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode) {
|
||||
function checkIndexedAccessIndexType(type: Type, accessNode: Node) {
|
||||
if (!(type.flags & TypeFlags.IndexedAccess)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of27.ts(1,11): error TS2459: Type 'number' has no property 'x' and no string index signature.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of27.ts(1,21): error TS2459: Type 'number' has no property 'y' and no string index signature.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of27.ts(1,11): error TS2339: Property 'x' does not exist on type 'Number'.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of27.ts(1,21): error TS2339: Property 'y' does not exist on type 'Number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of27.ts (2 errors) ====
|
||||
for (var {x: a = 0, y: b = 1} of [2, 3]) {
|
||||
~
|
||||
!!! error TS2459: Type 'number' has no property 'x' and no string index signature.
|
||||
!!! error TS2339: Property 'x' does not exist on type 'Number'.
|
||||
~
|
||||
!!! error TS2459: Type 'number' has no property 'y' and no string index signature.
|
||||
!!! error TS2339: Property 'y' does not exist on type 'Number'.
|
||||
a;
|
||||
b;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of29.ts(1,13): error TS2459: Type 'number' has no property 'x' and no string index signature.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of29.ts(1,23): error TS2459: Type 'number' has no property 'y' and no string index signature.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of29.ts(1,13): error TS2339: Property 'x' does not exist on type 'Number'.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of29.ts(1,23): error TS2339: Property 'y' does not exist on type 'Number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of29.ts (2 errors) ====
|
||||
for (const {x: a = 0, y: b = 1} of [2, 3]) {
|
||||
~
|
||||
!!! error TS2459: Type 'number' has no property 'x' and no string index signature.
|
||||
!!! error TS2339: Property 'x' does not exist on type 'Number'.
|
||||
~
|
||||
!!! error TS2459: Type 'number' has no property 'y' and no string index signature.
|
||||
!!! error TS2339: Property 'y' does not exist on type 'Number'.
|
||||
a;
|
||||
b;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts(1,13): error TS2459: Type 'number' has no property 'x' and no string index signature.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts(1,23): error TS2459: Type 'number' has no property 'y' and no string index signature.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts(1,13): error TS2339: Property 'x' does not exist on type 'Number'.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts(1,23): error TS2339: Property 'y' does not exist on type 'Number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of35.ts (2 errors) ====
|
||||
for (const {x: a = 0, y: b = 1} of [2, 3]) {
|
||||
~
|
||||
!!! error TS2459: Type 'number' has no property 'x' and no string index signature.
|
||||
!!! error TS2339: Property 'x' does not exist on type 'Number'.
|
||||
~
|
||||
!!! error TS2459: Type 'number' has no property 'y' and no string index signature.
|
||||
!!! error TS2339: Property 'y' does not exist on type 'Number'.
|
||||
a;
|
||||
b;
|
||||
}
|
||||
@@ -1,23 +1,32 @@
|
||||
tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts(2,12): error TS2448: Block-scoped variable 'a' used before its declaration.
|
||||
tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts(2,12): error TS2538: Type 'any' cannot be used as an index type.
|
||||
tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts(5,12): error TS2448: Block-scoped variable 'a' used before its declaration.
|
||||
tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts(5,12): error TS2538: Type 'any' cannot be used as an index type.
|
||||
tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts(8,7): error TS2448: Block-scoped variable 'b' used before its declaration.
|
||||
tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts(8,7): error TS2538: Type 'any' cannot be used as an index type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts (3 errors) ====
|
||||
==== tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts (6 errors) ====
|
||||
// 1:
|
||||
for (let {[a]: a} of [{ }]) continue;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'a' used before its declaration.
|
||||
!!! related TS2728 tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts:2:16: 'a' is declared here.
|
||||
~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
|
||||
// 2:
|
||||
for (let {[a]: a} = { }; false; ) continue;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'a' used before its declaration.
|
||||
!!! related TS2728 tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts:5:16: 'a' is declared here.
|
||||
~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
|
||||
// 3:
|
||||
let {[b]: b} = { };
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'b' used before its declaration.
|
||||
!!! related TS2728 tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts:8:11: 'b' is declared here.
|
||||
!!! related TS2728 tests/cases/compiler/blockScopedBindingUsedBeforeDef.ts:8:11: 'b' is declared here.
|
||||
~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
@@ -1,33 +1,63 @@
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(3,7): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(8,7): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(10,8): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(11,8): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(14,15): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(15,15): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(16,16): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(17,16): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(20,8): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(20,8): error TS2538: Type 'any' cannot be used as an index type.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(21,8): error TS2538: Type 'any' cannot be used as an index type.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(21,12): error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(33,4): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1.ts(34,5): error TS2365: Operator '+' cannot be applied to types '1' and '{}'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring1.ts (4 errors) ====
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring1.ts (14 errors) ====
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
~~~~~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
|
||||
|
||||
@@ -1,34 +1,64 @@
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(3,7): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(9,7): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(11,8): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(12,8): error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(15,15): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(16,15): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(17,16): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(18,16): error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(21,8): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(21,8): error TS2538: Type 'any' cannot be used as an index type.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(22,8): error TS2538: Type 'any' cannot be used as an index type.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(22,12): error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(34,4): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts(35,5): error TS2365: Operator '+' cannot be applied to types '1' and '{}'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts (4 errors) ====
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring1_ES6.ts (14 errors) ====
|
||||
// destructuring in variable declarations
|
||||
let foo = "bar";
|
||||
let {[foo]: bar} = {bar: "bar"};
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
let {["bar"]: bar2} = {bar: "bar"};
|
||||
let {[11]: bar2_1} = {11: "bar"};
|
||||
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {bar: "bar"};
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
let [{[foo]: bar4}] = [{bar: "bar"}];
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
let [{[foo2()]: bar5}] = [{bar: "bar"}];
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
function f1({["bar"]: x}: { bar: number }) {}
|
||||
function f2({[foo]: x}: { bar: number }) {}
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
function f3({[foo2()]: x}: { bar: number }) {}
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
function f4([{[foo]: x}]: [{ bar: number }]) {}
|
||||
~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
function f5([{[foo2()]: x}]: [{ bar: number }]) {}
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{ bar: number; }' has no matching index signature for type 'string'.
|
||||
|
||||
// report errors on type errors in computed properties used in destructuring
|
||||
let [{[foo()]: bar6}] = [{bar: "bar"}];
|
||||
~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
~~~~~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}];
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2538: Type 'any' cannot be used as an index type.
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'toExponential' does not exist on type 'string'.
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
tests/cases/compiler/computedPropertiesInDestructuring2.ts(2,7): error TS2537: Type '{}' has no matching index signature for type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring2.ts (1 errors) ====
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {};
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{}' has no matching index signature for type 'string'.
|
||||
@@ -0,0 +1,8 @@
|
||||
tests/cases/compiler/computedPropertiesInDestructuring2_ES6.ts(2,7): error TS2537: Type '{}' has no matching index signature for type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/computedPropertiesInDestructuring2_ES6.ts (1 errors) ====
|
||||
let foo2 = () => "bar";
|
||||
let {[foo2()]: bar3} = {};
|
||||
~~~~~~
|
||||
!!! error TS2537: Type '{}' has no matching index signature for type 'string'.
|
||||
@@ -15,8 +15,8 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): e
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ 0: number; 1: number; }' is not an array type.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2459: Type 'undefined[]' has no property 'b' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2339: Property 'a' does not exist on type 'undefined[]'.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2339: Property 'b' does not exist on type 'undefined[]'.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(106,17): error TS2322: Type '{ y: boolean; }' is not assignable to type '{ x: any; y?: boolean; }'.
|
||||
Property 'x' is missing in type '{ y: boolean; }'.
|
||||
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
@@ -133,9 +133,9 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9):
|
||||
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
var { a, b } = []; // Error
|
||||
~
|
||||
!!! error TS2459: Type 'undefined[]' has no property 'a' and no string index signature.
|
||||
!!! error TS2339: Property 'a' does not exist on type 'undefined[]'.
|
||||
~
|
||||
!!! error TS2459: Type 'undefined[]' has no property 'b' and no string index signature.
|
||||
!!! error TS2339: Property 'b' does not exist on type 'undefined[]'.
|
||||
}
|
||||
|
||||
function f11() {
|
||||
|
||||
@@ -18,20 +18,20 @@ class C<T extends Options> {
|
||||
>method : () => void
|
||||
|
||||
let { a, b } = this.foo;
|
||||
>a : T["a"]
|
||||
>b : T["b"]
|
||||
>a : { [P in keyof T]: T[P]; }["a"]
|
||||
>b : { [P in keyof T]: T[P]; }["b"]
|
||||
>this.foo : { [P in keyof T]: T[P]; }
|
||||
>this : this
|
||||
>foo : { [P in keyof T]: T[P]; }
|
||||
|
||||
!(a && b);
|
||||
>!(a && b) : false
|
||||
>(a && b) : T["b"]
|
||||
>a && b : T["b"]
|
||||
>a : T["a"]
|
||||
>b : T["b"]
|
||||
>(a && b) : { [P in keyof T]: T[P]; }["b"]
|
||||
>a && b : { [P in keyof T]: T[P]; }["b"]
|
||||
>a : { [P in keyof T]: T[P]; }["a"]
|
||||
>b : { [P in keyof T]: T[P]; }["b"]
|
||||
|
||||
a;
|
||||
>a : T["a"]
|
||||
>a : { [P in keyof T]: T[P]; }["a"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,7): error TS2459: Type '{ prop: string; }' has no property '[notPresent]' and no string index signature.
|
||||
tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,8): error TS2339: Property 'prop2' does not exist on type '{ prop: string; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts (1 errors) ====
|
||||
@@ -13,6 +13,6 @@ tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,7): error TS
|
||||
const notPresent = "prop2";
|
||||
|
||||
let { [notPresent]: computed2 } = { prop: "b" };
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2459: Type '{ prop: string; }' has no property '[notPresent]' and no string index signature.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2339: Property 'prop2' does not exist on type '{ prop: string; }'.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//// [destructuredMaappedTypeIsNotImplicitlyAny.ts]
|
||||
function foo<T extends string>(key: T, obj: { [_ in T]: number }) {
|
||||
const { [key]: bar } = obj; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature.
|
||||
bar; // bar : any
|
||||
|
||||
// Note: this does work:
|
||||
const lorem = obj[key];
|
||||
}
|
||||
|
||||
//// [destructuredMaappedTypeIsNotImplicitlyAny.js]
|
||||
function foo(key, obj) {
|
||||
var _a = key, bar = obj[_a]; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature.
|
||||
bar; // bar : any
|
||||
// Note: this does work:
|
||||
var lorem = obj[key];
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/destructuredMaappedTypeIsNotImplicitlyAny.ts ===
|
||||
function foo<T extends string>(key: T, obj: { [_ in T]: number }) {
|
||||
>foo : Symbol(foo, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 13))
|
||||
>key : Symbol(key, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 31))
|
||||
>T : Symbol(T, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 13))
|
||||
>obj : Symbol(obj, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 38))
|
||||
>_ : Symbol(_, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 47))
|
||||
>T : Symbol(T, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 13))
|
||||
|
||||
const { [key]: bar } = obj; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature.
|
||||
>key : Symbol(key, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 31))
|
||||
>bar : Symbol(bar, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 1, 11))
|
||||
>obj : Symbol(obj, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 38))
|
||||
|
||||
bar; // bar : any
|
||||
>bar : Symbol(bar, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 1, 11))
|
||||
|
||||
// Note: this does work:
|
||||
const lorem = obj[key];
|
||||
>lorem : Symbol(lorem, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 5, 9))
|
||||
>obj : Symbol(obj, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 38))
|
||||
>key : Symbol(key, Decl(destructuredMaappedTypeIsNotImplicitlyAny.ts, 0, 31))
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
=== tests/cases/compiler/destructuredMaappedTypeIsNotImplicitlyAny.ts ===
|
||||
function foo<T extends string>(key: T, obj: { [_ in T]: number }) {
|
||||
>foo : <T extends string>(key: T, obj: { [_ in T]: number; }) => void
|
||||
>key : T
|
||||
>obj : { [_ in T]: number; }
|
||||
|
||||
const { [key]: bar } = obj; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature.
|
||||
>key : T
|
||||
>bar : { [_ in T]: number; }[T]
|
||||
>obj : { [_ in T]: number; }
|
||||
|
||||
bar; // bar : any
|
||||
>bar : { [_ in T]: number; }[T]
|
||||
|
||||
// Note: this does work:
|
||||
const lorem = obj[key];
|
||||
>lorem : { [_ in T]: number; }[T]
|
||||
>obj[key] : { [_ in T]: number; }[T]
|
||||
>obj : { [_ in T]: number; }
|
||||
>key : T
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,7): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'.
|
||||
Type '{ i: number; }' is not assignable to type 'number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2339: Property 'i' does not exist on type 'string | number'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2339: Property 'i1' does not exist on type 'string | number | {}'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1005: ':' expected.
|
||||
@@ -20,10 +20,10 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs
|
||||
!!! error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'.
|
||||
!!! error TS2322: Type '{ i: number; }' is not assignable to type 'number'.
|
||||
~
|
||||
!!! error TS2459: Type 'string | number' has no property 'i' and no string index signature.
|
||||
!!! error TS2339: Property 'i' does not exist on type 'string | number'.
|
||||
var {i1}: string | number| {} = { i1: 2 };
|
||||
~~
|
||||
!!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature.
|
||||
!!! error TS2339: Property 'i1' does not exist on type 'string | number | {}'.
|
||||
var { f2: {f21} = { f212: "string" } }: any = undefined;
|
||||
~~~
|
||||
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,27): error TS2459: Type 'ObjType1' has no property 'x1' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,31): error TS2459: Type 'ObjType1' has no property 'x2' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,35): error TS2459: Type 'ObjType1' has no property 'x3' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,27): error TS2339: Property 'x1' does not exist on type 'ObjType1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,31): error TS2339: Property 'x2' does not exist on type 'ObjType1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(5,35): error TS2339: Property 'x3' does not exist on type 'ObjType1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,29): error TS2339: Property 'x1' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,40): error TS2339: Property 'x2' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7,51): error TS2339: Property 'x3' does not exist on type 'C1'.
|
||||
@@ -22,11 +22,11 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(1
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
~~
|
||||
!!! error TS2459: Type 'ObjType1' has no property 'x1' and no string index signature.
|
||||
!!! error TS2339: Property 'x1' does not exist on type 'ObjType1'.
|
||||
~~
|
||||
!!! error TS2459: Type 'ObjType1' has no property 'x2' and no string index signature.
|
||||
!!! error TS2339: Property 'x2' does not exist on type 'ObjType1'.
|
||||
~~
|
||||
!!! error TS2459: Type 'ObjType1' has no property 'x3' and no string index signature.
|
||||
!!! error TS2339: Property 'x3' does not exist on type 'ObjType1'.
|
||||
var foo: any = x1 || x2 || x3 || y || z;
|
||||
var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z;
|
||||
~~
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/compiler/downlevelLetConst16.ts(151,15): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(164,17): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(195,14): error TS2461: Type 'undefined' is not an array type.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(202,15): error TS2459: Type 'undefined' has no property 'a' and no string index signature.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(202,15): error TS2339: Property 'a' does not exist on type 'undefined'.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(216,16): error TS2461: Type 'undefined' is not an array type.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefined' has no property 'a' and no string index signature.
|
||||
tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2339: Property 'a' does not exist on type 'undefined'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/downlevelLetConst16.ts (6 errors) ====
|
||||
@@ -216,7 +216,7 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin
|
||||
function foo9() {
|
||||
for (let {a: x} of []) {
|
||||
~
|
||||
!!! error TS2459: Type 'undefined' has no property 'a' and no string index signature.
|
||||
!!! error TS2339: Property 'a' does not exist on type 'undefined'.
|
||||
use(x);
|
||||
}
|
||||
use(x);
|
||||
@@ -241,7 +241,7 @@ tests/cases/compiler/downlevelLetConst16.ts(223,17): error TS2459: Type 'undefin
|
||||
function foo12() {
|
||||
for (const {a: x} of []) {
|
||||
~
|
||||
!!! error TS2459: Type 'undefined' has no property 'a' and no string index signature.
|
||||
!!! error TS2339: Property 'a' does not exist on type 'undefined'.
|
||||
use(x);
|
||||
}
|
||||
use(x);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern.
|
||||
tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,11): error TS2459: Type 'string' has no property 'a' and no string index signature.
|
||||
tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,14): error TS2459: Type 'string' has no property 'b' and no string index signature.
|
||||
tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,11): error TS2339: Property 'a' does not exist on type 'String'.
|
||||
tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,14): error TS2339: Property 'b' does not exist on type 'String'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts (3 errors) ====
|
||||
@@ -8,6 +8,6 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructurin
|
||||
~~~~~~
|
||||
!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern.
|
||||
~
|
||||
!!! error TS2459: Type 'string' has no property 'a' and no string index signature.
|
||||
!!! error TS2339: Property 'a' does not exist on type 'String'.
|
||||
~
|
||||
!!! error TS2459: Type 'string' has no property 'b' and no string index signature.
|
||||
!!! error TS2339: Property 'b' does not exist on type 'String'.
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/conformance/jsdoc/0.js(56,20): error TS8024: JSDoc '@param' tag has name 'obj', but there is no parameter with that name.
|
||||
tests/cases/conformance/jsdoc/0.js(61,19): error TS2459: Type 'string' has no property 'a' and no string index signature.
|
||||
tests/cases/conformance/jsdoc/0.js(61,22): error TS2459: Type 'string' has no property 'b' and no string index signature.
|
||||
tests/cases/conformance/jsdoc/0.js(61,19): error TS2339: Property 'a' does not exist on type 'String'.
|
||||
tests/cases/conformance/jsdoc/0.js(61,22): error TS2339: Property 'b' does not exist on type 'String'.
|
||||
tests/cases/conformance/jsdoc/0.js(63,20): error TS8024: JSDoc '@param' tag has name 'y', but there is no parameter with that name.
|
||||
|
||||
|
||||
@@ -69,9 +69,9 @@ tests/cases/conformance/jsdoc/0.js(63,20): error TS8024: JSDoc '@param' tag has
|
||||
*/
|
||||
function bad1(x, {a, b}) {}
|
||||
~
|
||||
!!! error TS2459: Type 'string' has no property 'a' and no string index signature.
|
||||
!!! error TS2339: Property 'a' does not exist on type 'String'.
|
||||
~
|
||||
!!! error TS2459: Type 'string' has no property 'b' and no string index signature.
|
||||
!!! error TS2339: Property 'b' does not exist on type 'String'.
|
||||
/**
|
||||
* @param {string} y - here, y's type gets ignored but obj's is fine
|
||||
~
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(2,15): error TS7017: Element implicitly has an 'any' type because type '{ prop: string; }' has no index signature.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(13,15): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(21,15): error TS2536: Type 'unique symbol' cannot be used to index type '{ [idx: number]: string; }'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(23,15): error TS2536: Type 'unique symbol' cannot be used to index type '{ [idx: string]: string; }'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(25,16): error TS2536: Type 'symbol' cannot be used to index type '{ [idx: number]: string; }'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(27,16): error TS2536: Type 'symbol' cannot be used to index type '{ [idx: string]: string; }'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(2,7): error TS2537: Type '{ prop: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(13,7): error TS2537: Type '{ [idx: number]: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(21,7): error TS2538: Type 'unique symbol' cannot be used as an index type.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(23,7): error TS2538: Type 'unique symbol' cannot be used as an index type.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(25,7): error TS2538: Type 'symbol' cannot be used as an index type.
|
||||
tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(27,7): error TS2538: Type 'symbol' cannot be used as an index type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts (6 errors) ====
|
||||
let named = "foo";
|
||||
let {[named]: prop} = {prop: "foo"};
|
||||
~~~~
|
||||
!!! error TS7017: Element implicitly has an 'any' type because type '{ prop: string; }' has no index signature.
|
||||
~~~~~
|
||||
!!! error TS2537: Type '{ prop: string; }' has no matching index signature for type 'string'.
|
||||
void prop;
|
||||
|
||||
const numIndexed: {[idx: number]: string} = null as any;
|
||||
@@ -22,8 +22,8 @@ tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(27,16): error TS2
|
||||
let symed2 = Symbol();
|
||||
|
||||
let {[named]: prop2} = numIndexed;
|
||||
~~~~~
|
||||
!!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
|
||||
~~~~~
|
||||
!!! error TS2537: Type '{ [idx: number]: string; }' has no matching index signature for type 'string'.
|
||||
void prop2;
|
||||
let {[numed]: prop3} = numIndexed;
|
||||
void prop3;
|
||||
@@ -32,18 +32,18 @@ tests/cases/compiler/lateBoundDestructuringImplicitAnyError.ts(27,16): error TS2
|
||||
let {[numed]: prop5} = strIndexed;
|
||||
void prop5;
|
||||
let {[symed]: prop6} = numIndexed;
|
||||
~~~~~
|
||||
!!! error TS2536: Type 'unique symbol' cannot be used to index type '{ [idx: number]: string; }'.
|
||||
~~~~~
|
||||
!!! error TS2538: Type 'unique symbol' cannot be used as an index type.
|
||||
void prop6;
|
||||
let {[symed]: prop7} = strIndexed;
|
||||
~~~~~
|
||||
!!! error TS2536: Type 'unique symbol' cannot be used to index type '{ [idx: string]: string; }'.
|
||||
~~~~~
|
||||
!!! error TS2538: Type 'unique symbol' cannot be used as an index type.
|
||||
void prop7;
|
||||
let {[symed2]: prop8} = numIndexed;
|
||||
~~~~~
|
||||
!!! error TS2536: Type 'symbol' cannot be used to index type '{ [idx: number]: string; }'.
|
||||
~~~~~~
|
||||
!!! error TS2538: Type 'symbol' cannot be used as an index type.
|
||||
void prop8;
|
||||
let {[symed2]: prop9} = strIndexed;
|
||||
~~~~~
|
||||
!!! error TS2536: Type 'symbol' cannot be used to index type '{ [idx: string]: string; }'.
|
||||
~~~~~~
|
||||
!!! error TS2538: Type 'symbol' cannot be used as an index type.
|
||||
void prop9;
|
||||
@@ -87,12 +87,12 @@ void prop6;
|
||||
|
||||
let {[symed]: prop7} = strIndexed;
|
||||
>symed : unique symbol
|
||||
>prop7 : any
|
||||
>prop7 : string
|
||||
>strIndexed : { [idx: string]: string; }
|
||||
|
||||
void prop7;
|
||||
>void prop7 : undefined
|
||||
>prop7 : any
|
||||
>prop7 : string
|
||||
|
||||
let {[symed2]: prop8} = numIndexed;
|
||||
>symed2 : symbol
|
||||
@@ -105,10 +105,10 @@ void prop8;
|
||||
|
||||
let {[symed2]: prop9} = strIndexed;
|
||||
>symed2 : symbol
|
||||
>prop9 : any
|
||||
>prop9 : string
|
||||
>strIndexed : { [idx: string]: string; }
|
||||
|
||||
void prop9;
|
||||
>void prop9 : undefined
|
||||
>prop9 : any
|
||||
>prop9 : string
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts(3,3): error TS2339: Property 'nonExist' does not exist on type 'object'.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts(5,7): error TS2459: Type 'object' has no property 'destructuring' and no string index signature.
|
||||
tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts(5,7): error TS2339: Property 'destructuring' does not exist on type '{}'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts (2 errors) ====
|
||||
@@ -11,6 +11,6 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveAccessProperty.ts(5,7): e
|
||||
|
||||
var { destructuring } = a; // error
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2459: Type 'object' has no property 'destructuring' and no string index signature.
|
||||
!!! error TS2339: Property 'destructuring' does not exist on type '{}'.
|
||||
var { ...rest } = a; // ok
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
tests/cases/conformance/types/rest/objectRest.ts(7,12): error TS2339: Property '0' does not exist on type 'String'.
|
||||
tests/cases/conformance/types/rest/objectRest.ts(7,20): error TS2339: Property '1' does not exist on type 'String'.
|
||||
tests/cases/conformance/types/rest/objectRest.ts(43,8): error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'.
|
||||
tests/cases/conformance/types/rest/objectRest.ts(43,35): error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/objectRest.ts (4 errors) ====
|
||||
var o = { a: 1, b: 'no' }
|
||||
var { ...clone } = o;
|
||||
var { a, ...justB } = o;
|
||||
var { a, b: renamed, ...empty } = o;
|
||||
var { ['b']: renamed, ...justA } = o;
|
||||
var { 'b': renamed, ...justA } = o;
|
||||
var { b: { '0': n, '1': oooo }, ...justA } = o;
|
||||
~~~
|
||||
!!! error TS2339: Property '0' does not exist on type 'String'.
|
||||
~~~
|
||||
!!! error TS2339: Property '1' does not exist on type 'String'.
|
||||
|
||||
let o2 = { c: 'terrible idea?', d: 'yes' };
|
||||
var { d: renamed, ...d } = o2;
|
||||
|
||||
let nestedrest: { x: number, n1: { y: number, n2: { z: number, n3: { n4: number } } }, rest: number, restrest: number };
|
||||
var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest;
|
||||
|
||||
let complex: { x: { ka, ki }, y: number };
|
||||
var { x: { ka, ...nested }, y: other, ...rest } = complex;
|
||||
({x: { ka, ...nested }, y: other, ...rest} = complex);
|
||||
var { x, ...fresh } = { x: 1, y: 2 };
|
||||
({ x, ...fresh } = { x: 1, y: 2 });
|
||||
|
||||
class Removable {
|
||||
private x: number;
|
||||
protected y: number;
|
||||
set z(value: number) { }
|
||||
get both(): number { return 12 }
|
||||
set both(value: number) { }
|
||||
m() { }
|
||||
removed: string;
|
||||
remainder: string;
|
||||
}
|
||||
interface I {
|
||||
m(): void;
|
||||
removed: string;
|
||||
remainder: string;
|
||||
}
|
||||
var removable = new Removable();
|
||||
var { removed, ...removableRest } = removable;
|
||||
var i: I = removable;
|
||||
var { removed, ...removableRest2 } = i;
|
||||
|
||||
let computed = 'b';
|
||||
let computed2 = 'a';
|
||||
var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o;
|
||||
~~~~~~~~
|
||||
!!! error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'.
|
||||
~~~~~~~~~
|
||||
!!! error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'.
|
||||
({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o);
|
||||
|
||||
var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject.anythingGoes;
|
||||
|
||||
@@ -36,8 +36,8 @@ var { 'b': renamed, ...justA } = o;
|
||||
|
||||
var { b: { '0': n, '1': oooo }, ...justA } = o;
|
||||
>b : any
|
||||
>n : string
|
||||
>oooo : string
|
||||
>n : any
|
||||
>oooo : any
|
||||
>justA : { a: number; }
|
||||
>o : { a: number; b: string; }
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(13,20): error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
|
||||
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(21,18): error TS2372: Parameter 'a' cannot be referenced in its initializer.
|
||||
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(25,22): error TS2372: Parameter 'async' cannot be referenced in its initializer.
|
||||
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(29,15): error TS2537: Type 'any[]' has no matching index signature for type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts (3 errors) ====
|
||||
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts (4 errors) ====
|
||||
let foo: string = "";
|
||||
|
||||
function f1 (bar = foo) { // unexpected compiler error; works at runtime
|
||||
@@ -39,6 +40,8 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
|
||||
}
|
||||
|
||||
function f7({[foo]: bar}: any[]) {
|
||||
~~~
|
||||
!!! error TS2537: Type 'any[]' has no matching index signature for type 'string'.
|
||||
let foo: number = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts(1,16): error TS2459: Type 'number[]' has no property 'b' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts(1,16): error TS2339: Property 'b' does not exist on type 'number[]'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/restElementWithBindingPattern2.ts (1 errors) ====
|
||||
var [...{0: a, b }] = [0, 1];
|
||||
~
|
||||
!!! error TS2459: Type 'number[]' has no property 'b' and no string index signature.
|
||||
!!! error TS2339: Property 'b' does not exist on type 'number[]'.
|
||||
@@ -0,0 +1,8 @@
|
||||
// @noImplicitAny: true
|
||||
function foo<T extends string>(key: T, obj: { [_ in T]: number }) {
|
||||
const { [key]: bar } = obj; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature.
|
||||
bar; // bar : any
|
||||
|
||||
// Note: this does work:
|
||||
const lorem = obj[key];
|
||||
}
|
||||
Reference in New Issue
Block a user