mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 02:15:10 -05:00
Distribute indexed accesses when simplifying them (#26281)
* unknownify accesses * Move to simplify to break less with fewer changes * Accept baselines for now * Always propegate any as an index type * Fix flow control in the presence of simplifiable types * Add spy repro from #25181 * Retain errorType when it is used as a marker for the lack of a constraint * Small refinement * Add new test * Move most potentially recursive types from isIdenticalTo into structuredTypeRelatedTo to match the non-identity relations * Fix nits * Doesnt need to be undefineable at all
This commit is contained in:
@@ -6901,7 +6901,7 @@ namespace ts {
|
||||
function getConstraintOfIndexedAccess(type: IndexedAccessType) {
|
||||
const objectType = getBaseConstraintOfType(type.objectType) || type.objectType;
|
||||
const indexType = getBaseConstraintOfType(type.indexType) || type.indexType;
|
||||
const constraint = !isGenericObjectType(objectType) && !isGenericIndexType(indexType) ? getIndexedAccessType(objectType, indexType) : undefined;
|
||||
const constraint = !isGenericObjectType(objectType) && !isGenericIndexType(indexType) ? getIndexedAccessType(objectType, indexType, /*accessNode*/ undefined, errorType) : undefined;
|
||||
return constraint && constraint !== errorType ? constraint : undefined;
|
||||
}
|
||||
|
||||
@@ -7064,7 +7064,7 @@ namespace ts {
|
||||
if (t.flags & TypeFlags.IndexedAccess) {
|
||||
const baseObjectType = getBaseConstraint((<IndexedAccessType>t).objectType);
|
||||
const baseIndexType = getBaseConstraint((<IndexedAccessType>t).indexType);
|
||||
const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType) : undefined;
|
||||
const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType, /*accessNode*/ undefined, errorType) : undefined;
|
||||
return baseIndexedAccess && baseIndexedAccess !== errorType ? getBaseConstraint(baseIndexedAccess) : undefined;
|
||||
}
|
||||
if (t.flags & TypeFlags.Conditional) {
|
||||
@@ -9149,7 +9149,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | undefined, cacheSymbol: boolean) {
|
||||
function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | 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) ?
|
||||
@@ -9162,7 +9162,7 @@ namespace ts {
|
||||
markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword);
|
||||
if (isAssignmentTarget(accessExpression) && (isReferenceToReadonlyEntity(accessExpression, prop) || isReferenceThroughNamespaceImport(accessExpression))) {
|
||||
error(accessExpression.argumentExpression, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(prop));
|
||||
return errorType;
|
||||
return missingType;
|
||||
}
|
||||
if (cacheSymbol) {
|
||||
getNodeLinks(accessNode!).resolvedSymbol = prop;
|
||||
@@ -9221,7 +9221,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
return anyType;
|
||||
return missingType;
|
||||
}
|
||||
}
|
||||
if (isJSLiteralType(objectType)) {
|
||||
@@ -9239,7 +9239,10 @@ namespace ts {
|
||||
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
|
||||
}
|
||||
}
|
||||
return errorType;
|
||||
if (isTypeAny(indexType)) {
|
||||
return indexType;
|
||||
}
|
||||
return missingType;
|
||||
}
|
||||
|
||||
function isGenericObjectType(type: Type): boolean {
|
||||
@@ -9250,22 +9253,6 @@ namespace ts {
|
||||
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index);
|
||||
}
|
||||
|
||||
// Return true if the given type is a non-generic object type with a string index signature and no
|
||||
// other members.
|
||||
function isStringIndexOnlyType(type: Type): boolean {
|
||||
if (type.flags & TypeFlags.Object && !isGenericMappedType(type)) {
|
||||
const t = resolveStructuredTypeMembers(<ObjectType>type);
|
||||
return t.properties.length === 0 &&
|
||||
t.callSignatures.length === 0 && t.constructSignatures.length === 0 &&
|
||||
!!t.stringIndexInfo && !t.numberIndexInfo;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isMappedTypeToNever(type: Type): boolean {
|
||||
return !!(getObjectFlags(type) & ObjectFlags.Mapped) && getTemplateTypeFromMappedType(type as MappedType) === neverType;
|
||||
}
|
||||
|
||||
function getSimplifiedType(type: Type): Type {
|
||||
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(<IndexedAccessType>type) : type;
|
||||
}
|
||||
@@ -9280,35 +9267,12 @@ namespace ts {
|
||||
// We recursively simplify the object type as it may in turn be an indexed access type. For example, with
|
||||
// '{ [P in T]: { [Q in U]: number } }[T][U]' we want to first simplify the inner indexed access type.
|
||||
const objectType = getSimplifiedType(type.objectType);
|
||||
if (objectType.flags & TypeFlags.Intersection && isGenericObjectType(objectType)) {
|
||||
// Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or
|
||||
// more object types with only a string index signature, e.g. '(U & V & { [x: string]: D })[K]', return a
|
||||
// transformed type of the form '(U & V)[K] | D'. This allows us to properly reason about higher order indexed
|
||||
// access types with default property values as expressed by D.
|
||||
if (some((<IntersectionType>objectType).types, isStringIndexOnlyType)) {
|
||||
const regularTypes: Type[] = [];
|
||||
const stringIndexTypes: Type[] = [];
|
||||
for (const t of (<IntersectionType>objectType).types) {
|
||||
if (isStringIndexOnlyType(t)) {
|
||||
stringIndexTypes.push(getIndexTypeOfType(t, IndexKind.String)!);
|
||||
}
|
||||
else {
|
||||
regularTypes.push(t);
|
||||
}
|
||||
}
|
||||
return type.simplified = getUnionType([
|
||||
getSimplifiedType(getIndexedAccessType(getIntersectionType(regularTypes), type.indexType)),
|
||||
getIntersectionType(stringIndexTypes)
|
||||
]);
|
||||
}
|
||||
// Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or
|
||||
// more mapped types with a template type `never`, '(U & V & { [P in T]: never })[K]', return a
|
||||
// transformed type that removes the never-mapped type: '(U & V)[K]'. This mirrors what would happen
|
||||
// eventually anyway, but it easier to reason about.
|
||||
if (some((<IntersectionType>objectType).types, isMappedTypeToNever)) {
|
||||
const nonNeverTypes = filter((<IntersectionType>objectType).types, t => !isMappedTypeToNever(t));
|
||||
return type.simplified = getSimplifiedType(getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType));
|
||||
}
|
||||
const indexType = getSimplifiedType(type.indexType);
|
||||
if (objectType.flags & TypeFlags.Union) {
|
||||
return type.simplified = mapType(objectType, t => getSimplifiedType(getIndexedAccessType(t, indexType)));
|
||||
}
|
||||
if (objectType.flags & TypeFlags.Intersection) {
|
||||
return type.simplified = getIntersectionType(map((objectType as IntersectionType).types, t => getSimplifiedType(getIndexedAccessType(t, indexType))));
|
||||
}
|
||||
// If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper
|
||||
// that substitutes the index type for P. For example, for an index access { [P in K]: Box<T[P]> }[X], we
|
||||
@@ -9332,7 +9296,7 @@ namespace ts {
|
||||
return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper);
|
||||
}
|
||||
|
||||
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode): Type {
|
||||
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode, missingType = accessNode ? errorType : unknownType): Type {
|
||||
if (objectType === wildcardType || indexType === wildcardType) {
|
||||
return wildcardType;
|
||||
}
|
||||
@@ -9360,15 +9324,15 @@ namespace ts {
|
||||
if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Boolean)) {
|
||||
const propTypes: Type[] = [];
|
||||
for (const t of (<UnionType>indexType).types) {
|
||||
const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false);
|
||||
if (propType === errorType) {
|
||||
return errorType;
|
||||
const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false, missingType);
|
||||
if (propType === missingType) {
|
||||
return missingType;
|
||||
}
|
||||
propTypes.push(propType);
|
||||
}
|
||||
return getUnionType(propTypes);
|
||||
}
|
||||
return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true);
|
||||
return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true, missingType);
|
||||
}
|
||||
|
||||
function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) {
|
||||
@@ -10532,8 +10496,12 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isOrHasGenericConditional(type: Type): boolean {
|
||||
return !!(type.flags & TypeFlags.Conditional || (type.flags & TypeFlags.Intersection && some((type as IntersectionType).types, isOrHasGenericConditional)));
|
||||
}
|
||||
|
||||
function elaborateError(node: Expression | undefined, source: Type, target: Type): boolean {
|
||||
if (!node) return false;
|
||||
if (!node || isOrHasGenericConditional(target)) return false;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.JsxExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
@@ -10566,9 +10534,9 @@ namespace ts {
|
||||
let reportedError = false;
|
||||
for (let status = iterator.next(); !status.done; status = iterator.next()) {
|
||||
const { errorNode: prop, innerExpression: next, nameType, errorMessage } = status.value;
|
||||
const sourcePropType = getIndexedAccessType(source, nameType);
|
||||
const targetPropType = getIndexedAccessType(target, nameType);
|
||||
if (!isTypeAssignableTo(sourcePropType, targetPropType)) {
|
||||
const sourcePropType = getIndexedAccessType(source, nameType, /*accessNode*/ undefined, errorType);
|
||||
const targetPropType = getIndexedAccessType(target, nameType, /*accessNode*/ undefined, errorType);
|
||||
if (sourcePropType !== errorType && targetPropType !== errorType && !isTypeAssignableTo(sourcePropType, targetPropType)) {
|
||||
const elaborated = next && elaborateError(next, sourcePropType, targetPropType);
|
||||
if (elaborated) {
|
||||
reportedError = true;
|
||||
@@ -11287,7 +11255,7 @@ namespace ts {
|
||||
function isIdenticalTo(source: Type, target: Type): Ternary {
|
||||
let result: Ternary;
|
||||
const flags = source.flags & target.flags;
|
||||
if (flags & TypeFlags.Object) {
|
||||
if (flags & TypeFlags.Object || flags & TypeFlags.IndexedAccess || flags & TypeFlags.Conditional || flags & TypeFlags.Index || flags & TypeFlags.Substitution) {
|
||||
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false);
|
||||
}
|
||||
if (flags & (TypeFlags.Union | TypeFlags.Intersection)) {
|
||||
@@ -11297,32 +11265,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags & TypeFlags.Index) {
|
||||
return isRelatedTo((<IndexType>source).type, (<IndexType>target).type, /*reportErrors*/ false);
|
||||
}
|
||||
if (flags & TypeFlags.IndexedAccess) {
|
||||
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo((<IndexedAccessType>source).indexType, (<IndexedAccessType>target).indexType, /*reportErrors*/ false)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags & TypeFlags.Conditional) {
|
||||
if ((<ConditionalType>source).root.isDistributive === (<ConditionalType>target).root.isDistributive) {
|
||||
if (result = isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType, /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType, /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo(getTrueTypeFromConditionalType(<ConditionalType>source), getTrueTypeFromConditionalType(<ConditionalType>target), /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo(getFalseTypeFromConditionalType(<ConditionalType>source), getFalseTypeFromConditionalType(<ConditionalType>target), /*reportErrors*/ false)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags & TypeFlags.Substitution) {
|
||||
return isRelatedTo((<SubstitutionType>source).substitute, (<SubstitutionType>target).substitute, /*reportErrors*/ false);
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
|
||||
@@ -11634,6 +11576,37 @@ namespace ts {
|
||||
}
|
||||
|
||||
function structuredTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary {
|
||||
const flags = source.flags & target.flags;
|
||||
if (relation === identityRelation && !(flags & TypeFlags.Object)) {
|
||||
if (flags & TypeFlags.Index) {
|
||||
return isRelatedTo((<IndexType>source).type, (<IndexType>target).type, /*reportErrors*/ false);
|
||||
}
|
||||
let result = Ternary.False;
|
||||
if (flags & TypeFlags.IndexedAccess) {
|
||||
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo((<IndexedAccessType>source).indexType, (<IndexedAccessType>target).indexType, /*reportErrors*/ false)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags & TypeFlags.Conditional) {
|
||||
if ((<ConditionalType>source).root.isDistributive === (<ConditionalType>target).root.isDistributive) {
|
||||
if (result = isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType, /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType, /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo(getTrueTypeFromConditionalType(<ConditionalType>source), getTrueTypeFromConditionalType(<ConditionalType>target), /*reportErrors*/ false)) {
|
||||
if (result &= isRelatedTo(getFalseTypeFromConditionalType(<ConditionalType>source), getFalseTypeFromConditionalType(<ConditionalType>target), /*reportErrors*/ false)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags & TypeFlags.Substitution) {
|
||||
return isRelatedTo((<SubstitutionType>source).substitute, (<SubstitutionType>target).substitute, /*reportErrors*/ false);
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
let result: Ternary;
|
||||
let originalErrorInfo: DiagnosticMessageChain | undefined;
|
||||
const saveErrorInfo = errorInfo;
|
||||
@@ -14151,10 +14124,10 @@ namespace ts {
|
||||
getInitialTypeOfBindingElement(node);
|
||||
}
|
||||
|
||||
function getInitialOrAssignedType(node: VariableDeclaration | BindingElement | Expression) {
|
||||
return node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement ?
|
||||
function getInitialOrAssignedType(node: VariableDeclaration | BindingElement | Expression, reference: Node) {
|
||||
return getConstraintForLocation(node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement ?
|
||||
getInitialType(<VariableDeclaration | BindingElement>node) :
|
||||
getAssignedType(node);
|
||||
getAssignedType(node), reference);
|
||||
}
|
||||
|
||||
function isEmptyArrayAssignment(node: VariableDeclaration | BindingElement | Expression) {
|
||||
@@ -14540,11 +14513,11 @@ namespace ts {
|
||||
if (isEmptyArrayAssignment(node)) {
|
||||
return getEvolvingArrayType(neverType);
|
||||
}
|
||||
const assignedType = getBaseTypeOfLiteralType(getInitialOrAssignedType(node));
|
||||
const assignedType = getBaseTypeOfLiteralType(getInitialOrAssignedType(node, reference));
|
||||
return isTypeAssignableTo(assignedType, declaredType) ? assignedType : anyArrayType;
|
||||
}
|
||||
if (declaredType.flags & TypeFlags.Union) {
|
||||
return getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType(node));
|
||||
return getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType(node, reference));
|
||||
}
|
||||
return declaredType;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ function foo() {
|
||||
|
||||
var x: TokenType = list['one'];
|
||||
>x : TokenType
|
||||
>list['one'] : any
|
||||
>list['one'] : error
|
||||
>list : {}
|
||||
>'one' : "one"
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ interface Function {
|
||||
}
|
||||
|
||||
var a = {}[0]; // Should be Foo
|
||||
>a : any
|
||||
>{}[0] : any
|
||||
>a : error
|
||||
>{}[0] : error
|
||||
>{} : {}
|
||||
>0 : 0
|
||||
|
||||
var b = (() => { })[0]; // Should be Bar
|
||||
>b : any
|
||||
>(() => { })[0] : any
|
||||
>b : error
|
||||
>(() => { })[0] : error
|
||||
>(() => { }) : () => void
|
||||
>() => { } : () => void
|
||||
>0 : 0
|
||||
|
||||
@@ -22,8 +22,8 @@ var r1 = o['data']; // Should be number
|
||||
>'data' : "data"
|
||||
|
||||
var r2 = o['functionData']; // Should be any (no property found)
|
||||
>r2 : any
|
||||
>o['functionData'] : any
|
||||
>r2 : error
|
||||
>o['functionData'] : error
|
||||
>o : {}
|
||||
>'functionData' : "functionData"
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ obj1["26"]; // string
|
||||
>"26" : "26"
|
||||
|
||||
obj1["0b11010"]; // any
|
||||
>obj1["0b11010"] : any
|
||||
>obj1["0b11010"] : error
|
||||
>obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
|
||||
>"0b11010" : "0b11010"
|
||||
|
||||
@@ -119,7 +119,7 @@ obj2["26"]; // string
|
||||
>"26" : "26"
|
||||
|
||||
obj2["0B11010"]; // any
|
||||
>obj2["0B11010"] : any
|
||||
>obj2["0B11010"] : error
|
||||
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
|
||||
>"0B11010" : "0B11010"
|
||||
|
||||
@@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean
|
||||
>"9.671406556917009e+24" : "9.671406556917009e+24"
|
||||
|
||||
obj2["Infinity"]; // any
|
||||
>obj2["Infinity"] : any
|
||||
>obj2["Infinity"] : error
|
||||
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
|
||||
>"Infinity" : "Infinity"
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ obj1["26"]; // string
|
||||
>"26" : "26"
|
||||
|
||||
obj1["0b11010"]; // any
|
||||
>obj1["0b11010"] : any
|
||||
>obj1["0b11010"] : error
|
||||
>obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
|
||||
>"0b11010" : "0b11010"
|
||||
|
||||
@@ -119,7 +119,7 @@ obj2["26"]; // string
|
||||
>"26" : "26"
|
||||
|
||||
obj2["0B11010"]; // any
|
||||
>obj2["0B11010"] : any
|
||||
>obj2["0B11010"] : error
|
||||
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
|
||||
>"0B11010" : "0B11010"
|
||||
|
||||
@@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean
|
||||
>"9.671406556917009e+24" : "9.671406556917009e+24"
|
||||
|
||||
obj2["Infinity"]; // any
|
||||
>obj2["Infinity"] : any
|
||||
>obj2["Infinity"] : error
|
||||
>obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; }
|
||||
>"Infinity" : "Infinity"
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//// [circularlySimplifyingConditionalTypesNoCrash.ts]
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
type Shared< // Circularly self constraining type, defered thanks to mapping
|
||||
InjectedProps,
|
||||
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
|
||||
> = {
|
||||
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
|
||||
};
|
||||
|
||||
interface ComponentClass<P> {
|
||||
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
|
||||
}
|
||||
|
||||
interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
|
||||
<P extends Shared<TInjectedProps, P>>(
|
||||
component: ComponentClass<P>
|
||||
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
|
||||
} // Then intersected with and indexed via Omit and &
|
||||
|
||||
interface Connect { // Then strictly compared with another signature in its context
|
||||
<TStateProps, TOwnProps>(
|
||||
mapStateToProps: unknown,
|
||||
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;
|
||||
|
||||
<TDispatchProps, TOwnProps>(
|
||||
mapStateToProps: null | undefined,
|
||||
mapDispatchToProps: unknown,
|
||||
mergeProps: null | undefined,
|
||||
options: unknown
|
||||
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
|
||||
}
|
||||
|
||||
declare var connect: Connect;
|
||||
|
||||
const myStoreConnect: Connect = function(
|
||||
mapStateToProps?: any,
|
||||
mapDispatchToProps?: any,
|
||||
mergeProps?: any,
|
||||
options: unknown = {},
|
||||
) {
|
||||
return connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps,
|
||||
mergeProps,
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
//// [circularlySimplifyingConditionalTypesNoCrash.js]
|
||||
"use strict";
|
||||
var myStoreConnect = function (mapStateToProps, mapDispatchToProps, mergeProps, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
|
||||
};
|
||||
@@ -0,0 +1,154 @@
|
||||
=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts ===
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
>Omit : Symbol(Omit, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10))
|
||||
>K : Symbol(K, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 12))
|
||||
>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10))
|
||||
>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10))
|
||||
>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10))
|
||||
>K : Symbol(K, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 12))
|
||||
|
||||
type Shared< // Circularly self constraining type, defered thanks to mapping
|
||||
>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63))
|
||||
|
||||
InjectedProps,
|
||||
>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12))
|
||||
|
||||
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
|
||||
>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18))
|
||||
>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63))
|
||||
>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12))
|
||||
>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18))
|
||||
|
||||
> = {
|
||||
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9))
|
||||
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
|
||||
>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12))
|
||||
>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18))
|
||||
>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9))
|
||||
>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9))
|
||||
>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9))
|
||||
|
||||
};
|
||||
|
||||
interface ComponentClass<P> {
|
||||
>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 9, 25))
|
||||
|
||||
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
|
||||
>defaultProps : Symbol(ComponentClass.defaultProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 9, 29))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 9, 25))
|
||||
}
|
||||
|
||||
interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
|
||||
>InferableComponentEnhancerWithProps : Symbol(InferableComponentEnhancerWithProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 11, 1))
|
||||
>TInjectedProps : Symbol(TInjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 46))
|
||||
>TNeedsProps : Symbol(TNeedsProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 61))
|
||||
|
||||
<P extends Shared<TInjectedProps, P>>(
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5))
|
||||
>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63))
|
||||
>TInjectedProps : Symbol(TInjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 46))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5))
|
||||
|
||||
component: ComponentClass<P>
|
||||
>component : Symbol(component, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 42))
|
||||
>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5))
|
||||
|
||||
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
|
||||
>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6))
|
||||
>Omit : Symbol(Omit, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 0))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5))
|
||||
>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63))
|
||||
>TInjectedProps : Symbol(TInjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 46))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5))
|
||||
>TNeedsProps : Symbol(TNeedsProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 61))
|
||||
>WrappedComponent : Symbol(WrappedComponent, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 16, 81))
|
||||
>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6))
|
||||
>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5))
|
||||
|
||||
} // Then intersected with and indexed via Omit and &
|
||||
|
||||
interface Connect { // Then strictly compared with another signature in its context
|
||||
>Connect : Symbol(Connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 17, 1))
|
||||
|
||||
<TStateProps, TOwnProps>(
|
||||
>TStateProps : Symbol(TStateProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 5))
|
||||
>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 17))
|
||||
|
||||
mapStateToProps: unknown,
|
||||
>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 29))
|
||||
|
||||
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;
|
||||
>InferableComponentEnhancerWithProps : Symbol(InferableComponentEnhancerWithProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 11, 1))
|
||||
>TStateProps : Symbol(TStateProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 5))
|
||||
>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 17))
|
||||
|
||||
<TDispatchProps, TOwnProps>(
|
||||
>TDispatchProps : Symbol(TDispatchProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 5))
|
||||
>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 20))
|
||||
|
||||
mapStateToProps: null | undefined,
|
||||
>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 32))
|
||||
|
||||
mapDispatchToProps: unknown,
|
||||
>mapDispatchToProps : Symbol(mapDispatchToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 25, 42))
|
||||
|
||||
mergeProps: null | undefined,
|
||||
>mergeProps : Symbol(mergeProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 26, 36))
|
||||
|
||||
options: unknown
|
||||
>options : Symbol(options, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 27, 37))
|
||||
|
||||
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
|
||||
>InferableComponentEnhancerWithProps : Symbol(InferableComponentEnhancerWithProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 11, 1))
|
||||
>TDispatchProps : Symbol(TDispatchProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 5))
|
||||
>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 20))
|
||||
}
|
||||
|
||||
declare var connect: Connect;
|
||||
>connect : Symbol(connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 32, 11))
|
||||
>Connect : Symbol(Connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 17, 1))
|
||||
|
||||
const myStoreConnect: Connect = function(
|
||||
>myStoreConnect : Symbol(myStoreConnect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 34, 5))
|
||||
>Connect : Symbol(Connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 17, 1))
|
||||
|
||||
mapStateToProps?: any,
|
||||
>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 34, 41))
|
||||
|
||||
mapDispatchToProps?: any,
|
||||
>mapDispatchToProps : Symbol(mapDispatchToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 35, 26))
|
||||
|
||||
mergeProps?: any,
|
||||
>mergeProps : Symbol(mergeProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 36, 29))
|
||||
|
||||
options: unknown = {},
|
||||
>options : Symbol(options, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 37, 21))
|
||||
|
||||
) {
|
||||
return connect(
|
||||
>connect : Symbol(connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 32, 11))
|
||||
|
||||
mapStateToProps,
|
||||
>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 34, 41))
|
||||
|
||||
mapDispatchToProps,
|
||||
>mapDispatchToProps : Symbol(mapDispatchToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 35, 26))
|
||||
|
||||
mergeProps,
|
||||
>mergeProps : Symbol(mergeProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 36, 29))
|
||||
|
||||
options,
|
||||
>options : Symbol(options, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 37, 21))
|
||||
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts ===
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
>Omit : Pick<T, Exclude<keyof T, K>>
|
||||
|
||||
type Shared< // Circularly self constraining type, defered thanks to mapping
|
||||
>Shared : Shared<InjectedProps, DecorationTargetProps>
|
||||
|
||||
InjectedProps,
|
||||
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
|
||||
> = {
|
||||
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
|
||||
};
|
||||
|
||||
interface ComponentClass<P> {
|
||||
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
|
||||
>defaultProps : Partial<P> | undefined
|
||||
}
|
||||
|
||||
interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
|
||||
<P extends Shared<TInjectedProps, P>>(
|
||||
component: ComponentClass<P>
|
||||
>component : ComponentClass<P>
|
||||
|
||||
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
|
||||
>WrappedComponent : ComponentClass<P>
|
||||
|
||||
} // Then intersected with and indexed via Omit and &
|
||||
|
||||
interface Connect { // Then strictly compared with another signature in its context
|
||||
<TStateProps, TOwnProps>(
|
||||
mapStateToProps: unknown,
|
||||
>mapStateToProps : unknown
|
||||
|
||||
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;
|
||||
|
||||
<TDispatchProps, TOwnProps>(
|
||||
mapStateToProps: null | undefined,
|
||||
>mapStateToProps : null | undefined
|
||||
>null : null
|
||||
|
||||
mapDispatchToProps: unknown,
|
||||
>mapDispatchToProps : unknown
|
||||
|
||||
mergeProps: null | undefined,
|
||||
>mergeProps : null | undefined
|
||||
>null : null
|
||||
|
||||
options: unknown
|
||||
>options : unknown
|
||||
|
||||
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
|
||||
}
|
||||
|
||||
declare var connect: Connect;
|
||||
>connect : Connect
|
||||
|
||||
const myStoreConnect: Connect = function(
|
||||
>myStoreConnect : Connect
|
||||
>function( mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options: unknown = {},) { return connect( mapStateToProps, mapDispatchToProps, mergeProps, options, );} : (mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options?: unknown) => InferableComponentEnhancerWithProps<{}, {}>
|
||||
|
||||
mapStateToProps?: any,
|
||||
>mapStateToProps : any
|
||||
|
||||
mapDispatchToProps?: any,
|
||||
>mapDispatchToProps : any
|
||||
|
||||
mergeProps?: any,
|
||||
>mergeProps : any
|
||||
|
||||
options: unknown = {},
|
||||
>options : unknown
|
||||
>{} : {}
|
||||
|
||||
) {
|
||||
return connect(
|
||||
>connect( mapStateToProps, mapDispatchToProps, mergeProps, options, ) : InferableComponentEnhancerWithProps<{}, {}>
|
||||
>connect : Connect
|
||||
|
||||
mapStateToProps,
|
||||
>mapStateToProps : any
|
||||
|
||||
mapDispatchToProps,
|
||||
>mapDispatchToProps : any
|
||||
|
||||
mergeProps,
|
||||
>mergeProps : any
|
||||
|
||||
options,
|
||||
>options : unknown
|
||||
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(8,5): error TS2322: Type '{ test: string; arg: A; }' is not assignable to type 'Something<A>'.
|
||||
Type '{ test: string; arg: A; }' is not assignable to type 'A extends object ? { arg: A; } : { arg?: undefined; }'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(9,33): error TS2322: Type 'A' is not assignable to type 'Something<A>["arr"]'.
|
||||
Type 'object' is not assignable to type 'Something<A>["arr"]'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(9,33): error TS2322: Type '{ test: string; arg: A; arr: A; }' is not assignable to type 'Something<A>'.
|
||||
Object literal may only specify known properties, and 'arr' does not exist in type 'Something<A>'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts (2 errors) ====
|
||||
@@ -17,8 +17,8 @@ tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(9,
|
||||
!!! error TS2322: Type '{ test: string; arg: A; }' is not assignable to type 'Something<A>'.
|
||||
!!! error TS2322: Type '{ test: string; arg: A; }' is not assignable to type 'A extends object ? { arg: A; } : { arg?: undefined; }'.
|
||||
sa = { test: 'bye', arg: a, arr: a } // excess
|
||||
~~~
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'Something<A>["arr"]'.
|
||||
!!! error TS2322: Type 'object' is not assignable to type 'Something<A>["arr"]'.
|
||||
~~~~~~
|
||||
!!! error TS2322: Type '{ test: string; arg: A; arr: A; }' is not assignable to type 'Something<A>'.
|
||||
!!! error TS2322: Object literal may only specify known properties, and 'arr' does not exist in type 'Something<A>'.
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ var o = {v:"Yo2"};
|
||||
// WScript.Echo(o[0]);
|
||||
|
||||
1[0];
|
||||
>1[0] : any
|
||||
>1[0] : error
|
||||
>1 : 1
|
||||
>0 : 0
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
tests/cases/compiler/deferredLookupTypeResolution2.ts(14,13): error TS2536: Type '({ [K in Extract<keyof T, string>]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'.
|
||||
tests/cases/compiler/deferredLookupTypeResolution2.ts(19,21): error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract<keyof T, string>]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/deferredLookupTypeResolution2.ts (2 errors) ====
|
||||
// Repro from #17456
|
||||
|
||||
type StringContains<S extends string, L extends string> = ({ [K in S]: 'true' } & { [key: string]: 'false'})[L];
|
||||
|
||||
type ObjectHasKey<O, L extends string> = StringContains<Extract<keyof O, string>, L>;
|
||||
|
||||
type A<T> = ObjectHasKey<T, '0'>;
|
||||
|
||||
type B = ObjectHasKey<[string, number], '1'>; // "true"
|
||||
type C = ObjectHasKey<[string, number], '2'>; // "false"
|
||||
type D = A<[string]>; // "true"
|
||||
|
||||
// Error, "false" not handled
|
||||
type E<T> = { true: 'true' }[ObjectHasKey<T, '1'>];
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2536: Type '({ [K in Extract<keyof T, string>]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'.
|
||||
|
||||
type Juxtapose<T> = ({ true: 'otherwise' } & { [k: string]: 'true' })[ObjectHasKey<T, '1'>];
|
||||
|
||||
// Error, "otherwise" is missing
|
||||
type DeepError<T> = { true: 'true' }[Juxtapose<T>];
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract<keyof T, string>]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'.
|
||||
|
||||
type DeepOK<T> = { true: 'true', otherwise: 'false' }[Juxtapose<T>];
|
||||
|
||||
@@ -141,7 +141,7 @@ enum E7 {
|
||||
|
||||
A = 'foo'['foo']
|
||||
>A : E7
|
||||
>'foo'['foo'] : any
|
||||
>'foo'['foo'] : error
|
||||
>'foo' : "foo"
|
||||
>'foo' : "foo"
|
||||
}
|
||||
@@ -152,7 +152,7 @@ enum E8 {
|
||||
|
||||
B = 'foo'['foo']
|
||||
>B : E8
|
||||
>'foo'['foo'] : any
|
||||
>'foo'['foo'] : error
|
||||
>'foo' : "foo"
|
||||
>'foo' : "foo"
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ var x = _arr.map(o => MyEnumType[o.key] === enumValue); // these are not same ty
|
||||
>o => MyEnumType[o.key] === enumValue : (o: { key: string; }) => boolean
|
||||
>o : { key: string; }
|
||||
>MyEnumType[o.key] === enumValue : boolean
|
||||
>MyEnumType[o.key] : any
|
||||
>MyEnumType[o.key] : error
|
||||
>MyEnumType : typeof MyEnumType
|
||||
>o.key : string
|
||||
>o : { key: string; }
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
//// [genericIndexedAccessMethodIntersectionCanBeAccessed.ts]
|
||||
type ExtendedService<T> = {
|
||||
[K in keyof T]: T[K] & {
|
||||
__$daemonMode?: string;
|
||||
__$action?: string;
|
||||
};
|
||||
};
|
||||
|
||||
type Service<T> = {
|
||||
[K in keyof T]: T[K] & {id?: string};
|
||||
};
|
||||
|
||||
export const createService = <T>(
|
||||
ServiceCtr: ExtendedService<T> & Service<T>
|
||||
) => {
|
||||
Object.keys(ServiceCtr).forEach(key => {
|
||||
const method = (ServiceCtr)[key as keyof T];
|
||||
const {__$daemonMode, __$action, id} = method;
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//// [genericIndexedAccessMethodIntersectionCanBeAccessed.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.createService = function (ServiceCtr) {
|
||||
Object.keys(ServiceCtr).forEach(function (key) {
|
||||
var method = (ServiceCtr)[key];
|
||||
var __$daemonMode = method.__$daemonMode, __$action = method.__$action, id = method.id;
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
=== tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts ===
|
||||
type ExtendedService<T> = {
|
||||
>ExtendedService : Symbol(ExtendedService, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 21))
|
||||
|
||||
[K in keyof T]: T[K] & {
|
||||
>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 1, 5))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 21))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 21))
|
||||
>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 1, 5))
|
||||
|
||||
__$daemonMode?: string;
|
||||
>__$daemonMode : Symbol(__$daemonMode, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 1, 28))
|
||||
|
||||
__$action?: string;
|
||||
>__$action : Symbol(__$action, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 2, 31))
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
type Service<T> = {
|
||||
>Service : Symbol(Service, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 5, 2))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 7, 13))
|
||||
|
||||
[K in keyof T]: T[K] & {id?: string};
|
||||
>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 8, 5))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 7, 13))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 7, 13))
|
||||
>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 8, 5))
|
||||
>id : Symbol(id, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 8, 28))
|
||||
|
||||
};
|
||||
|
||||
export const createService = <T>(
|
||||
>createService : Symbol(createService, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 12))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30))
|
||||
|
||||
ServiceCtr: ExtendedService<T> & Service<T>
|
||||
>ServiceCtr : Symbol(ServiceCtr, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 33))
|
||||
>ExtendedService : Symbol(ExtendedService, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30))
|
||||
>Service : Symbol(Service, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 5, 2))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30))
|
||||
|
||||
) => {
|
||||
Object.keys(ServiceCtr).forEach(key => {
|
||||
>Object.keys(ServiceCtr).forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
|
||||
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
|
||||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --))
|
||||
>ServiceCtr : Symbol(ServiceCtr, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 33))
|
||||
>forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
|
||||
>key : Symbol(key, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 14, 36))
|
||||
|
||||
const method = (ServiceCtr)[key as keyof T];
|
||||
>method : Symbol(method, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 15, 13))
|
||||
>ServiceCtr : Symbol(ServiceCtr, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 33))
|
||||
>key : Symbol(key, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 14, 36))
|
||||
>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30))
|
||||
|
||||
const {__$daemonMode, __$action, id} = method;
|
||||
>__$daemonMode : Symbol(__$daemonMode, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 16, 15))
|
||||
>__$action : Symbol(__$action, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 16, 29))
|
||||
>id : Symbol(id, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 16, 40))
|
||||
>method : Symbol(method, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 15, 13))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
=== tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts ===
|
||||
type ExtendedService<T> = {
|
||||
>ExtendedService : ExtendedService<T>
|
||||
|
||||
[K in keyof T]: T[K] & {
|
||||
__$daemonMode?: string;
|
||||
>__$daemonMode : string | undefined
|
||||
|
||||
__$action?: string;
|
||||
>__$action : string | undefined
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
type Service<T> = {
|
||||
>Service : Service<T>
|
||||
|
||||
[K in keyof T]: T[K] & {id?: string};
|
||||
>id : string | undefined
|
||||
|
||||
};
|
||||
|
||||
export const createService = <T>(
|
||||
>createService : <T>(ServiceCtr: ExtendedService<T> & Service<T>) => void
|
||||
><T>( ServiceCtr: ExtendedService<T> & Service<T>) => { Object.keys(ServiceCtr).forEach(key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; })} : <T>(ServiceCtr: ExtendedService<T> & Service<T>) => void
|
||||
|
||||
ServiceCtr: ExtendedService<T> & Service<T>
|
||||
>ServiceCtr : ExtendedService<T> & Service<T>
|
||||
|
||||
) => {
|
||||
Object.keys(ServiceCtr).forEach(key => {
|
||||
>Object.keys(ServiceCtr).forEach(key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; }) : void
|
||||
>Object.keys(ServiceCtr).forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void
|
||||
>Object.keys(ServiceCtr) : string[]
|
||||
>Object.keys : (o: {}) => string[]
|
||||
>Object : ObjectConstructor
|
||||
>keys : (o: {}) => string[]
|
||||
>ServiceCtr : ExtendedService<T> & Service<T>
|
||||
>forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void
|
||||
>key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; } : (key: string) => void
|
||||
>key : string
|
||||
|
||||
const method = (ServiceCtr)[key as keyof T];
|
||||
>method : (ExtendedService<T> & Service<T>)[keyof T]
|
||||
>(ServiceCtr)[key as keyof T] : (ExtendedService<T> & Service<T>)[keyof T]
|
||||
>(ServiceCtr) : ExtendedService<T> & Service<T>
|
||||
>ServiceCtr : ExtendedService<T> & Service<T>
|
||||
>key as keyof T : keyof T
|
||||
>key : string
|
||||
|
||||
const {__$daemonMode, __$action, id} = method;
|
||||
>__$daemonMode : string | undefined
|
||||
>__$action : string | undefined
|
||||
>id : string | undefined
|
||||
>method : (ExtendedService<T> & Service<T>)[keyof T]
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ var f = new foo();
|
||||
|
||||
f[0] = 4; // Shouldn't be allowed
|
||||
>f[0] = 4 : 4
|
||||
>f[0] : any
|
||||
>f[0] : error
|
||||
>f : foo
|
||||
>0 : 0
|
||||
>4 : 4
|
||||
|
||||
37
tests/baselines/reference/indexedAccessRelation.errors.txt
Normal file
37
tests/baselines/reference/indexedAccessRelation.errors.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
tests/cases/compiler/indexedAccessRelation.ts(16,23): error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick<S & State<T>, "a">'.
|
||||
Types of property 'a' are incompatible.
|
||||
Type 'T' is not assignable to type 'S["a"] & T'.
|
||||
Type 'Foo' is not assignable to type 'S["a"] & T'.
|
||||
Type 'Foo' is not assignable to type 'S["a"]'.
|
||||
Type 'T' is not assignable to type 'S["a"]'.
|
||||
Type 'Foo' is not assignable to type 'S["a"]'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/indexedAccessRelation.ts (1 errors) ====
|
||||
// Repro from #14723
|
||||
|
||||
class Component<S> {
|
||||
setState<K extends keyof S>(state: Pick<S, K>) {}
|
||||
}
|
||||
|
||||
export interface State<T> {
|
||||
a?: T;
|
||||
}
|
||||
|
||||
class Foo {}
|
||||
|
||||
class Comp<T extends Foo, S> extends Component<S & State<T>>
|
||||
{
|
||||
foo(a: T) {
|
||||
this.setState({ a: a });
|
||||
~~~~~~~~
|
||||
!!! error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick<S & State<T>, "a">'.
|
||||
!!! error TS2345: Types of property 'a' are incompatible.
|
||||
!!! error TS2345: Type 'T' is not assignable to type 'S["a"] & T'.
|
||||
!!! error TS2345: Type 'Foo' is not assignable to type 'S["a"] & T'.
|
||||
!!! error TS2345: Type 'Foo' is not assignable to type 'S["a"]'.
|
||||
!!! error TS2345: Type 'T' is not assignable to type 'S["a"]'.
|
||||
!!! error TS2345: Type 'Foo' is not assignable to type 'S["a"]'.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class Comp<T extends Foo, S> extends Component<S & State<T>>
|
||||
>a : T
|
||||
|
||||
this.setState({ a: a });
|
||||
>this.setState({ a: a }) : void
|
||||
>this.setState({ a: a }) : any
|
||||
>this.setState : <K extends keyof S | "a">(state: Pick<S & State<T>, K>) => void
|
||||
>this : this
|
||||
>setState : <K extends keyof S | "a">(state: Pick<S & State<T>, K>) => void
|
||||
|
||||
@@ -69,8 +69,8 @@ declare function genericFn3<
|
||||
|
||||
// Should be never
|
||||
const result5 = genericFn3({ g: "gtest", h: "htest" }, "g", "h"); // 'g' & 'h' will reduce to never
|
||||
>result5 : error
|
||||
>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : error
|
||||
>result5 : unknown
|
||||
>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : unknown
|
||||
>genericFn3 : <T extends { [K in keyof T]: T[K]; }, U extends keyof T, V extends keyof T>(obj: T, u: U, v: V) => T[U & V]
|
||||
>{ g: "gtest", h: "htest" } : { g: string; h: string; }
|
||||
>g : string
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is referenced directly or indirectly in its own type annotation.
|
||||
tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/limitDeepInstantiations.ts (1 errors) ====
|
||||
==== tests/cases/compiler/limitDeepInstantiations.ts (2 errors) ====
|
||||
// Repro from #14837
|
||||
|
||||
type Foo<T extends "true", B> = { "true": Foo<T, Foo<T, B>> }[T];
|
||||
@@ -9,4 +10,6 @@ tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is
|
||||
!!! error TS2502: '"true"' is referenced directly or indirectly in its own type annotation.
|
||||
let f1: Foo<"true", {}>;
|
||||
let f2: Foo<"false", {}>;
|
||||
~~~~~~~
|
||||
!!! error TS2344: Type '"false"' does not satisfy the constraint '"true"'.
|
||||
|
||||
@@ -9,5 +9,5 @@ let f1: Foo<"true", {}>;
|
||||
>f1 : any
|
||||
|
||||
let f2: Foo<"false", {}>;
|
||||
>f2 : any
|
||||
>f2 : unknown
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ let a = ['c', 'd'];
|
||||
|
||||
a[Symbol.isConcatSpreadable] = false;
|
||||
>a[Symbol.isConcatSpreadable] = false : false
|
||||
>a[Symbol.isConcatSpreadable] : any
|
||||
>a[Symbol.isConcatSpreadable] : error
|
||||
>a : string[]
|
||||
>Symbol.isConcatSpreadable : symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
@@ -445,9 +445,9 @@ new h["a-b"]["a-b"](1, 2, ...a, "string");
|
||||
|
||||
// Element access expression with a number
|
||||
new i["a-b"][1](1, 2, "string");
|
||||
>new i["a-b"][1](1, 2, "string") : any
|
||||
>i["a-b"][1] : any
|
||||
>i["a-b"] : any
|
||||
>new i["a-b"][1](1, 2, "string") : error
|
||||
>i["a-b"][1] : error
|
||||
>i["a-b"] : error
|
||||
>i : C[][]
|
||||
>"a-b" : "a-b"
|
||||
>1 : 1
|
||||
@@ -456,9 +456,9 @@ new i["a-b"][1](1, 2, "string");
|
||||
>"string" : "string"
|
||||
|
||||
new i["a-b"][1](1, 2, ...a);
|
||||
>new i["a-b"][1](1, 2, ...a) : any
|
||||
>i["a-b"][1] : any
|
||||
>i["a-b"] : any
|
||||
>new i["a-b"][1](1, 2, ...a) : error
|
||||
>i["a-b"][1] : error
|
||||
>i["a-b"] : error
|
||||
>i : C[][]
|
||||
>"a-b" : "a-b"
|
||||
>1 : 1
|
||||
@@ -468,9 +468,9 @@ new i["a-b"][1](1, 2, ...a);
|
||||
>a : string[]
|
||||
|
||||
new i["a-b"][1](1, 2, ...a, "string");
|
||||
>new i["a-b"][1](1, 2, ...a, "string") : any
|
||||
>i["a-b"][1] : any
|
||||
>i["a-b"] : any
|
||||
>new i["a-b"][1](1, 2, ...a, "string") : error
|
||||
>i["a-b"][1] : error
|
||||
>i["a-b"] : error
|
||||
>i : C[][]
|
||||
>"a-b" : "a-b"
|
||||
>1 : 1
|
||||
|
||||
@@ -446,9 +446,9 @@ new h["a-b"]["a-b"](1, 2, ...a, "string");
|
||||
|
||||
// Element access expression with a number
|
||||
new i["a-b"][1](1, 2, "string");
|
||||
>new i["a-b"][1](1, 2, "string") : any
|
||||
>i["a-b"][1] : any
|
||||
>i["a-b"] : any
|
||||
>new i["a-b"][1](1, 2, "string") : error
|
||||
>i["a-b"][1] : error
|
||||
>i["a-b"] : error
|
||||
>i : C[][]
|
||||
>"a-b" : "a-b"
|
||||
>1 : 1
|
||||
@@ -457,9 +457,9 @@ new i["a-b"][1](1, 2, "string");
|
||||
>"string" : "string"
|
||||
|
||||
new i["a-b"][1](1, 2, ...a);
|
||||
>new i["a-b"][1](1, 2, ...a) : any
|
||||
>i["a-b"][1] : any
|
||||
>i["a-b"] : any
|
||||
>new i["a-b"][1](1, 2, ...a) : error
|
||||
>i["a-b"][1] : error
|
||||
>i["a-b"] : error
|
||||
>i : C[][]
|
||||
>"a-b" : "a-b"
|
||||
>1 : 1
|
||||
@@ -469,9 +469,9 @@ new i["a-b"][1](1, 2, ...a);
|
||||
>a : string[]
|
||||
|
||||
new i["a-b"][1](1, 2, ...a, "string");
|
||||
>new i["a-b"][1](1, 2, ...a, "string") : any
|
||||
>i["a-b"][1] : any
|
||||
>i["a-b"] : any
|
||||
>new i["a-b"][1](1, 2, ...a, "string") : error
|
||||
>i["a-b"][1] : error
|
||||
>i["a-b"] : error
|
||||
>i : C[][]
|
||||
>"a-b" : "a-b"
|
||||
>1 : 1
|
||||
|
||||
@@ -24,8 +24,8 @@ var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]
|
||||
|
||||
// Should be okay, as we suppress implicit 'any' property access checks
|
||||
var strRepresentation3 = MyEmusEnum["monehh"];
|
||||
>strRepresentation3 : any
|
||||
>MyEmusEnum["monehh"] : any
|
||||
>strRepresentation3 : error
|
||||
>MyEmusEnum["monehh"] : error
|
||||
>MyEmusEnum : typeof MyEmusEnum
|
||||
>"monehh" : "monehh"
|
||||
|
||||
@@ -39,15 +39,15 @@ var strRepresentation4 = MyEmusEnum["emu"];
|
||||
|
||||
// Should be okay, as we suppress implicit 'any' property access checks
|
||||
var x = {}["hi"];
|
||||
>x : any
|
||||
>{}["hi"] : any
|
||||
>x : error
|
||||
>{}["hi"] : error
|
||||
>{} : {}
|
||||
>"hi" : "hi"
|
||||
|
||||
// Should be okay, as we suppress implicit 'any' property access checks
|
||||
var y = {}[10];
|
||||
>y : any
|
||||
>{}[10] : any
|
||||
>y : error
|
||||
>{}[10] : error
|
||||
>{} : {}
|
||||
>10 : 10
|
||||
|
||||
@@ -61,8 +61,8 @@ var emptyObj = {};
|
||||
|
||||
// Should be okay, as we suppress implicit 'any' property access checks
|
||||
var z1 = emptyObj[hi];
|
||||
>z1 : any
|
||||
>emptyObj[hi] : any
|
||||
>z1 : error
|
||||
>emptyObj[hi] : error
|
||||
>emptyObj : {}
|
||||
>hi : any
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ for (var key in a) {
|
||||
>a : object
|
||||
|
||||
var value = a[key];
|
||||
>value : any
|
||||
>a[key] : any
|
||||
>value : error
|
||||
>a[key] : error
|
||||
>a : object
|
||||
>key : string
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ for (var key in a) {
|
||||
>a : object
|
||||
|
||||
var value = a[key];
|
||||
>value : any
|
||||
>a[key] : any
|
||||
>value : error
|
||||
>a[key] : error
|
||||
>a : object
|
||||
>key : string
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ var r2 = c['2'];
|
||||
>'2' : "2"
|
||||
|
||||
var r3 = c['3'];
|
||||
>r3 : any
|
||||
>c['3'] : any
|
||||
>r3 : error
|
||||
>c['3'] : error
|
||||
>c : C
|
||||
>'3' : "3"
|
||||
|
||||
@@ -80,8 +80,8 @@ var r2 = i['2'];
|
||||
>'2' : "2"
|
||||
|
||||
var r3 = i['3'];
|
||||
>r3 : any
|
||||
>i['3'] : any
|
||||
>r3 : error
|
||||
>i['3'] : error
|
||||
>i : I
|
||||
>'3' : "3"
|
||||
|
||||
@@ -129,8 +129,8 @@ var r2 = a['2'];
|
||||
>'2' : "2"
|
||||
|
||||
var r3 = a['3'];
|
||||
>r3 : any
|
||||
>a['3'] : any
|
||||
>r3 : error
|
||||
>a['3'] : error
|
||||
>a : { [x: number]: string; 1: string; "2": string; }
|
||||
>'3' : "3"
|
||||
|
||||
@@ -162,20 +162,20 @@ var b: { [x: number]: string } = { 1: '', "2": '' }
|
||||
>'' : ""
|
||||
|
||||
var r1a = b['1'];
|
||||
>r1a : any
|
||||
>b['1'] : any
|
||||
>r1a : error
|
||||
>b['1'] : error
|
||||
>b : { [x: number]: string; }
|
||||
>'1' : "1"
|
||||
|
||||
var r2a = b['2'];
|
||||
>r2a : any
|
||||
>b['2'] : any
|
||||
>r2a : error
|
||||
>b['2'] : error
|
||||
>b : { [x: number]: string; }
|
||||
>'2' : "2"
|
||||
|
||||
var r3 = b['3'];
|
||||
>r3 : any
|
||||
>b['3'] : any
|
||||
>r3 : error
|
||||
>b['3'] : error
|
||||
>b : { [x: number]: string; }
|
||||
>'3' : "3"
|
||||
|
||||
@@ -221,8 +221,8 @@ var r2b = b2['2'];
|
||||
>'2' : "2"
|
||||
|
||||
var r3 = b2['3'];
|
||||
>r3 : any
|
||||
>b2['3'] : any
|
||||
>r3 : error
|
||||
>b2['3'] : error
|
||||
>b2 : { [x: number]: string; 1: string; "2": string; }
|
||||
>'3' : "3"
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ var r1d = i.data;
|
||||
>data : number
|
||||
|
||||
var r1e = i['hm']; // should be Object
|
||||
>r1e : any
|
||||
>i['hm'] : any
|
||||
>r1e : error
|
||||
>i['hm'] : error
|
||||
>i : I
|
||||
>'hm' : "hm"
|
||||
|
||||
@@ -104,8 +104,8 @@ var r2d = x.data;
|
||||
>data : number
|
||||
|
||||
var r2e = x['hm']; // should be Object
|
||||
>r2e : any
|
||||
>x['hm'] : any
|
||||
>r2e : error
|
||||
>x['hm'] : error
|
||||
>x : { (): void; apply(a: any, b?: any): void; call(thisArg: number, ...argArray: number[]): any; }
|
||||
>'hm' : "hm"
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ var r1d = i.data;
|
||||
>data : number
|
||||
|
||||
var r1e = i['hm']; // should be Object
|
||||
>r1e : any
|
||||
>i['hm'] : any
|
||||
>r1e : error
|
||||
>i['hm'] : error
|
||||
>i : I
|
||||
>'hm' : "hm"
|
||||
|
||||
@@ -101,8 +101,8 @@ var r2d = x.data;
|
||||
>data : number
|
||||
|
||||
var r2e = x['hm']; // should be Object
|
||||
>r2e : any
|
||||
>x['hm'] : any
|
||||
>r2e : error
|
||||
>x['hm'] : error
|
||||
>x : { new (): number; apply(a: any, b?: any): void; call(thisArg: number, ...argArray: number[]): any; }
|
||||
>'hm' : "hm"
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ var r = c[" "];
|
||||
>" " : " "
|
||||
|
||||
var r2 = c[" "];
|
||||
>r2 : any
|
||||
>c[" "] : any
|
||||
>r2 : error
|
||||
>c[" "] : error
|
||||
>c : C
|
||||
>" " : " "
|
||||
|
||||
@@ -67,8 +67,8 @@ var r = i[" "];
|
||||
>" " : " "
|
||||
|
||||
var r2 = i[" "];
|
||||
>r2 : any
|
||||
>i[" "] : any
|
||||
>r2 : error
|
||||
>i[" "] : error
|
||||
>i : I
|
||||
>" " : " "
|
||||
|
||||
@@ -106,8 +106,8 @@ var r = a[" "];
|
||||
>" " : " "
|
||||
|
||||
var r2 = a[" "];
|
||||
>r2 : any
|
||||
>a[" "] : any
|
||||
>r2 : error
|
||||
>a[" "] : error
|
||||
>a : { " ": number; "a b": string; "~!@#$%^&*()_+{}|:'<>?\/.,`": number; }
|
||||
>" " : " "
|
||||
|
||||
@@ -148,8 +148,8 @@ var r = b[" "];
|
||||
>" " : " "
|
||||
|
||||
var r2 = b[" "];
|
||||
>r2 : any
|
||||
>b[" "] : any
|
||||
>r2 : error
|
||||
>b[" "] : error
|
||||
>b : { " ": number; "a b": string; "~!@#$%^&*()_+{}|:'<>?\/.,`": number; }
|
||||
>" " : " "
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ obj1[0o45436]; // string
|
||||
>0o45436 : 19230
|
||||
|
||||
obj1["0o45436"]; // any
|
||||
>obj1["0o45436"] : any
|
||||
>obj1["0o45436"] : error
|
||||
>obj1 : { 0o45436: string; a: number; b: number; oct1: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; }
|
||||
>"0o45436" : "0o45436"
|
||||
|
||||
@@ -109,7 +109,7 @@ obj2[0O45436]; // string
|
||||
>0O45436 : 19230
|
||||
|
||||
obj2["0O45436"]; // any
|
||||
>obj2["0O45436"] : any
|
||||
>obj2["0O45436"] : error
|
||||
>obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; }
|
||||
>"0O45436" : "0O45436"
|
||||
|
||||
@@ -149,7 +149,7 @@ obj2["5.462437423415177e+244"]; // boolean
|
||||
>"5.462437423415177e+244" : "5.462437423415177e+244"
|
||||
|
||||
obj2["Infinity"]; // any
|
||||
>obj2["Infinity"] : any
|
||||
>obj2["Infinity"] : error
|
||||
>obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; }
|
||||
>"Infinity" : "Infinity"
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ obj1[0o45436]; // string
|
||||
>0o45436 : 19230
|
||||
|
||||
obj1["0o45436"]; // any
|
||||
>obj1["0o45436"] : any
|
||||
>obj1["0o45436"] : error
|
||||
>obj1 : { 0o45436: string; a: number; b: number; oct1: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; }
|
||||
>"0o45436" : "0o45436"
|
||||
|
||||
@@ -109,7 +109,7 @@ obj2[0O45436]; // string
|
||||
>0O45436 : 19230
|
||||
|
||||
obj2["0O45436"]; // any
|
||||
>obj2["0O45436"] : any
|
||||
>obj2["0O45436"] : error
|
||||
>obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; }
|
||||
>"0O45436" : "0O45436"
|
||||
|
||||
@@ -149,7 +149,7 @@ obj2["5.462437423415177e+244"]; // boolean
|
||||
>"5.462437423415177e+244" : "5.462437423415177e+244"
|
||||
|
||||
obj2["Infinity"]; // any
|
||||
>obj2["Infinity"] : any
|
||||
>obj2["Infinity"] : error
|
||||
>obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; }
|
||||
>"Infinity" : "Infinity"
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ var WorkspacePrototype = {
|
||||
};
|
||||
WorkspacePrototype['__proto__'] = EntityPrototype;
|
||||
>WorkspacePrototype['__proto__'] = EntityPrototype : any
|
||||
>WorkspacePrototype['__proto__'] : any
|
||||
>WorkspacePrototype['__proto__'] : error
|
||||
>WorkspacePrototype : { serialize: () => any; }
|
||||
>'__proto__' : "__proto__"
|
||||
>EntityPrototype : any
|
||||
|
||||
@@ -5,7 +5,7 @@ class X {
|
||||
constructor() {
|
||||
this['__proto__'] = null; // used to cause ICE
|
||||
>this['__proto__'] = null : null
|
||||
>this['__proto__'] : any
|
||||
>this['__proto__'] : error
|
||||
>this : this
|
||||
>'__proto__' : "__proto__"
|
||||
>null : null
|
||||
|
||||
29
tests/baselines/reference/spyComparisonChecking.errors.txt
Normal file
29
tests/baselines/reference/spyComparisonChecking.errors.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
tests/cases/compiler/spyComparisonChecking.ts(20,32): error TS2339: Property 'returnValue' does not exist on type 'Function'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/spyComparisonChecking.ts (1 errors) ====
|
||||
interface Spy {
|
||||
(...params: any[]): any;
|
||||
|
||||
identity: string;
|
||||
and: Function;
|
||||
mostRecentCall: { args: any[]; };
|
||||
argsForCall: any[];
|
||||
}
|
||||
|
||||
type SpyObj<T> = T & {
|
||||
[k in keyof T]: Spy;
|
||||
}
|
||||
|
||||
declare function createSpyObj<T>(
|
||||
name: string, names: Array<keyof T>): SpyObj<T>;
|
||||
|
||||
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
|
||||
const spyObj = createSpyObj<T>(spyName, methodNames);
|
||||
for (const methodName of methodNames) {
|
||||
spyObj[methodName].and.returnValue(1);
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'returnValue' does not exist on type 'Function'.
|
||||
}
|
||||
return spyObj;
|
||||
}
|
||||
34
tests/baselines/reference/spyComparisonChecking.js
Normal file
34
tests/baselines/reference/spyComparisonChecking.js
Normal file
@@ -0,0 +1,34 @@
|
||||
//// [spyComparisonChecking.ts]
|
||||
interface Spy {
|
||||
(...params: any[]): any;
|
||||
|
||||
identity: string;
|
||||
and: Function;
|
||||
mostRecentCall: { args: any[]; };
|
||||
argsForCall: any[];
|
||||
}
|
||||
|
||||
type SpyObj<T> = T & {
|
||||
[k in keyof T]: Spy;
|
||||
}
|
||||
|
||||
declare function createSpyObj<T>(
|
||||
name: string, names: Array<keyof T>): SpyObj<T>;
|
||||
|
||||
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
|
||||
const spyObj = createSpyObj<T>(spyName, methodNames);
|
||||
for (const methodName of methodNames) {
|
||||
spyObj[methodName].and.returnValue(1);
|
||||
}
|
||||
return spyObj;
|
||||
}
|
||||
|
||||
//// [spyComparisonChecking.js]
|
||||
function mock(spyName, methodNames) {
|
||||
var spyObj = createSpyObj(spyName, methodNames);
|
||||
for (var _i = 0, methodNames_1 = methodNames; _i < methodNames_1.length; _i++) {
|
||||
var methodName = methodNames_1[_i];
|
||||
spyObj[methodName].and.returnValue(1);
|
||||
}
|
||||
return spyObj;
|
||||
}
|
||||
75
tests/baselines/reference/spyComparisonChecking.symbols
Normal file
75
tests/baselines/reference/spyComparisonChecking.symbols
Normal file
@@ -0,0 +1,75 @@
|
||||
=== tests/cases/compiler/spyComparisonChecking.ts ===
|
||||
interface Spy {
|
||||
>Spy : Symbol(Spy, Decl(spyComparisonChecking.ts, 0, 0))
|
||||
|
||||
(...params: any[]): any;
|
||||
>params : Symbol(params, Decl(spyComparisonChecking.ts, 1, 5))
|
||||
|
||||
identity: string;
|
||||
>identity : Symbol(Spy.identity, Decl(spyComparisonChecking.ts, 1, 28))
|
||||
|
||||
and: Function;
|
||||
>and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21))
|
||||
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
mostRecentCall: { args: any[]; };
|
||||
>mostRecentCall : Symbol(Spy.mostRecentCall, Decl(spyComparisonChecking.ts, 4, 18))
|
||||
>args : Symbol(args, Decl(spyComparisonChecking.ts, 5, 21))
|
||||
|
||||
argsForCall: any[];
|
||||
>argsForCall : Symbol(Spy.argsForCall, Decl(spyComparisonChecking.ts, 5, 37))
|
||||
}
|
||||
|
||||
type SpyObj<T> = T & {
|
||||
>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12))
|
||||
|
||||
[k in keyof T]: Spy;
|
||||
>k : Symbol(k, Decl(spyComparisonChecking.ts, 10, 5))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12))
|
||||
>Spy : Symbol(Spy, Decl(spyComparisonChecking.ts, 0, 0))
|
||||
}
|
||||
|
||||
declare function createSpyObj<T>(
|
||||
>createSpyObj : Symbol(createSpyObj, Decl(spyComparisonChecking.ts, 11, 1))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30))
|
||||
|
||||
name: string, names: Array<keyof T>): SpyObj<T>;
|
||||
>name : Symbol(name, Decl(spyComparisonChecking.ts, 13, 33))
|
||||
>names : Symbol(names, Decl(spyComparisonChecking.ts, 14, 17))
|
||||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30))
|
||||
>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30))
|
||||
|
||||
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
|
||||
>mock : Symbol(mock, Decl(spyComparisonChecking.ts, 14, 52))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
|
||||
>spyName : Symbol(spyName, Decl(spyComparisonChecking.ts, 16, 17))
|
||||
>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33))
|
||||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
|
||||
>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
|
||||
|
||||
const spyObj = createSpyObj<T>(spyName, methodNames);
|
||||
>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9))
|
||||
>createSpyObj : Symbol(createSpyObj, Decl(spyComparisonChecking.ts, 11, 1))
|
||||
>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14))
|
||||
>spyName : Symbol(spyName, Decl(spyComparisonChecking.ts, 16, 17))
|
||||
>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33))
|
||||
|
||||
for (const methodName of methodNames) {
|
||||
>methodName : Symbol(methodName, Decl(spyComparisonChecking.ts, 18, 14))
|
||||
>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33))
|
||||
|
||||
spyObj[methodName].and.returnValue(1);
|
||||
>spyObj[methodName].and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21))
|
||||
>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9))
|
||||
>methodName : Symbol(methodName, Decl(spyComparisonChecking.ts, 18, 14))
|
||||
>and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21))
|
||||
}
|
||||
return spyObj;
|
||||
>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9))
|
||||
}
|
||||
62
tests/baselines/reference/spyComparisonChecking.types
Normal file
62
tests/baselines/reference/spyComparisonChecking.types
Normal file
@@ -0,0 +1,62 @@
|
||||
=== tests/cases/compiler/spyComparisonChecking.ts ===
|
||||
interface Spy {
|
||||
(...params: any[]): any;
|
||||
>params : any[]
|
||||
|
||||
identity: string;
|
||||
>identity : string
|
||||
|
||||
and: Function;
|
||||
>and : Function
|
||||
|
||||
mostRecentCall: { args: any[]; };
|
||||
>mostRecentCall : { args: any[]; }
|
||||
>args : any[]
|
||||
|
||||
argsForCall: any[];
|
||||
>argsForCall : any[]
|
||||
}
|
||||
|
||||
type SpyObj<T> = T & {
|
||||
>SpyObj : SpyObj<T>
|
||||
|
||||
[k in keyof T]: Spy;
|
||||
}
|
||||
|
||||
declare function createSpyObj<T>(
|
||||
>createSpyObj : <T>(name: string, names: (keyof T)[]) => SpyObj<T>
|
||||
|
||||
name: string, names: Array<keyof T>): SpyObj<T>;
|
||||
>name : string
|
||||
>names : (keyof T)[]
|
||||
|
||||
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
|
||||
>mock : <T>(spyName: string, methodNames: (keyof T)[]) => SpyObj<T>
|
||||
>spyName : string
|
||||
>methodNames : (keyof T)[]
|
||||
|
||||
const spyObj = createSpyObj<T>(spyName, methodNames);
|
||||
>spyObj : SpyObj<T>
|
||||
>createSpyObj<T>(spyName, methodNames) : SpyObj<T>
|
||||
>createSpyObj : <T>(name: string, names: (keyof T)[]) => SpyObj<T>
|
||||
>spyName : string
|
||||
>methodNames : (keyof T)[]
|
||||
|
||||
for (const methodName of methodNames) {
|
||||
>methodName : keyof T
|
||||
>methodNames : (keyof T)[]
|
||||
|
||||
spyObj[methodName].and.returnValue(1);
|
||||
>spyObj[methodName].and.returnValue(1) : any
|
||||
>spyObj[methodName].and.returnValue : any
|
||||
>spyObj[methodName].and : Function
|
||||
>spyObj[methodName] : SpyObj<T>[keyof T]
|
||||
>spyObj : SpyObj<T>
|
||||
>methodName : keyof T
|
||||
>and : Function
|
||||
>returnValue : any
|
||||
>1 : 1
|
||||
}
|
||||
return spyObj;
|
||||
>spyObj : SpyObj<T>
|
||||
}
|
||||
@@ -28,8 +28,8 @@ class Bar extends Foo {
|
||||
>symbol : symbol
|
||||
|
||||
return super[symbol]();
|
||||
>super[symbol]() : any
|
||||
>super[symbol] : any
|
||||
>super[symbol]() : error
|
||||
>super[symbol] : error
|
||||
>super : Foo
|
||||
>symbol : symbol
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ class Bar extends Foo {
|
||||
>symbol : any
|
||||
|
||||
return super[symbol]();
|
||||
>super[symbol]() : any
|
||||
>super[symbol] : any
|
||||
>super[symbol]() : error
|
||||
>super[symbol] : error
|
||||
>super : Foo
|
||||
>symbol : any
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ class Bar extends Foo {
|
||||
>symbol : any
|
||||
|
||||
return super[symbol]();
|
||||
>super[symbol]() : any
|
||||
>super[symbol] : any
|
||||
>super[symbol]() : error
|
||||
>super[symbol] : error
|
||||
>super : typeof Foo
|
||||
>symbol : any
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ module M {
|
||||
// The following should be of type 'any'. This is because even though obj has a property keyed by Symbol.iterator,
|
||||
// the key passed in here is the *wrong* Symbol.iterator. It is not the iterator property of the global Symbol.
|
||||
obj[Symbol.iterator];
|
||||
>obj[Symbol.iterator] : any
|
||||
>obj[Symbol.iterator] : error
|
||||
>obj : { [Symbol.iterator]: number; }
|
||||
>Symbol.iterator : symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
@@ -21,9 +21,9 @@ module M {
|
||||
// The following should be of type 'any'. This is because even though obj has a property keyed by Symbol.iterator,
|
||||
// the key passed in here is the *wrong* Symbol.iterator. It is not the iterator property of the global Symbol.
|
||||
obj[Symbol["iterator"]];
|
||||
>obj[Symbol["iterator"]] : any
|
||||
>obj[Symbol["iterator"]] : error
|
||||
>obj : { [Symbol.iterator]: number; }
|
||||
>Symbol["iterator"] : any
|
||||
>Symbol["iterator"] : error
|
||||
>Symbol : {}
|
||||
>"iterator" : "iterator"
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ var obj = {
|
||||
|
||||
// Should give type 'any'.
|
||||
obj[Symbol["nonsense"]];
|
||||
>obj[Symbol["nonsense"]] : any
|
||||
>obj[Symbol["nonsense"]] : error
|
||||
>obj : { [Symbol.iterator]: number; }
|
||||
>Symbol["nonsense"] : any
|
||||
>Symbol["nonsense"] : error
|
||||
>Symbol : SymbolConstructor
|
||||
>"nonsense" : "nonsense"
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ for (var key in obj)
|
||||
>console.log : (message?: any, ...optionalParams: any[]) => void
|
||||
>console : Console
|
||||
>log : (message?: any, ...optionalParams: any[]) => void
|
||||
>obj[key] : any
|
||||
>obj[key] : error
|
||||
>obj : { a: number; }
|
||||
>key : string
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
=== tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts ===
|
||||
`abc${0}abc`[`0`];
|
||||
>`abc${0}abc`[`0`] : any
|
||||
>`abc${0}abc`[`0`] : error
|
||||
>`abc${0}abc` : string
|
||||
>0 : 0
|
||||
>`0` : "0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
=== tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts ===
|
||||
`abc${0}abc`[`0`];
|
||||
>`abc${0}abc`[`0`] : any
|
||||
>`abc${0}abc`[`0`] : error
|
||||
>`abc${0}abc` : string
|
||||
>0 : 0
|
||||
>`0` : "0"
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
//// [thisIndexOnExistingReadonlyFieldIsNotNever.ts]
|
||||
declare class Component<P, S = {}> {
|
||||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>;
|
||||
state: Readonly<S>;
|
||||
}
|
||||
interface CoachMarkAnchorProps<C> {
|
||||
anchorRef?: (anchor: C) => void;
|
||||
}
|
||||
type AnchorType<P> = Component<P>;
|
||||
|
||||
class CoachMarkAnchorDecorator {
|
||||
decorateComponent<P>(anchor: P) {
|
||||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> {
|
||||
private _onAnchorRef = (anchor: AnchorType<P>) => {
|
||||
const anchorRef = this.props.anchorRef;
|
||||
if (anchorRef) {
|
||||
anchorRef(anchor);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [thisIndexOnExistingReadonlyFieldIsNotNever.js]
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
}
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var CoachMarkAnchorDecorator = /** @class */ (function () {
|
||||
function CoachMarkAnchorDecorator() {
|
||||
}
|
||||
CoachMarkAnchorDecorator.prototype.decorateComponent = function (anchor) {
|
||||
return /** @class */ (function (_super) {
|
||||
__extends(CoachMarkAnchor, _super);
|
||||
function CoachMarkAnchor() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this._onAnchorRef = function (anchor) {
|
||||
var anchorRef = _this.props.anchorRef;
|
||||
if (anchorRef) {
|
||||
anchorRef(anchor);
|
||||
}
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
return CoachMarkAnchor;
|
||||
}(Component));
|
||||
};
|
||||
return CoachMarkAnchorDecorator;
|
||||
}());
|
||||
@@ -0,0 +1,76 @@
|
||||
=== tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts ===
|
||||
declare class Component<P, S = {}> {
|
||||
>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 24))
|
||||
>S : Symbol(S, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 26))
|
||||
|
||||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>;
|
||||
>props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
>children : Symbol(children, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 1, 30))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 24))
|
||||
|
||||
state: Readonly<S>;
|
||||
>state : Symbol(Component.state, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 1, 67))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 26))
|
||||
}
|
||||
interface CoachMarkAnchorProps<C> {
|
||||
>CoachMarkAnchorProps : Symbol(CoachMarkAnchorProps, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 3, 1))
|
||||
>C : Symbol(C, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 31))
|
||||
|
||||
anchorRef?: (anchor: C) => void;
|
||||
>anchorRef : Symbol(CoachMarkAnchorProps.anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35))
|
||||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 5, 17))
|
||||
>C : Symbol(C, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 31))
|
||||
}
|
||||
type AnchorType<P> = Component<P>;
|
||||
>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 16))
|
||||
>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 16))
|
||||
|
||||
class CoachMarkAnchorDecorator {
|
||||
>CoachMarkAnchorDecorator : Symbol(CoachMarkAnchorDecorator, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 34))
|
||||
|
||||
decorateComponent<P>(anchor: P) {
|
||||
>decorateComponent : Symbol(CoachMarkAnchorDecorator.decorateComponent, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 9, 32))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22))
|
||||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 25))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22))
|
||||
|
||||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> {
|
||||
>CoachMarkAnchor : Symbol(CoachMarkAnchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 14))
|
||||
>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0))
|
||||
>CoachMarkAnchorProps : Symbol(CoachMarkAnchorProps, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 3, 1))
|
||||
>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22))
|
||||
|
||||
private _onAnchorRef = (anchor: AnchorType<P>) => {
|
||||
>_onAnchorRef : Symbol(CoachMarkAnchor._onAnchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 101))
|
||||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 12, 36))
|
||||
>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1))
|
||||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22))
|
||||
|
||||
const anchorRef = this.props.anchorRef;
|
||||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21))
|
||||
>this.props.anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35))
|
||||
>this.props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36))
|
||||
>this : Symbol(CoachMarkAnchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 14))
|
||||
>props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36))
|
||||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35))
|
||||
|
||||
if (anchorRef) {
|
||||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21))
|
||||
|
||||
anchorRef(anchor);
|
||||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21))
|
||||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 12, 36))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
=== tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts ===
|
||||
declare class Component<P, S = {}> {
|
||||
>Component : Component<P, S>
|
||||
|
||||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>;
|
||||
>props : Readonly<{ children?: unknown; }> & Readonly<P>
|
||||
>children : unknown
|
||||
|
||||
state: Readonly<S>;
|
||||
>state : Readonly<S>
|
||||
}
|
||||
interface CoachMarkAnchorProps<C> {
|
||||
anchorRef?: (anchor: C) => void;
|
||||
>anchorRef : ((anchor: C) => void) | undefined
|
||||
>anchor : C
|
||||
}
|
||||
type AnchorType<P> = Component<P>;
|
||||
>AnchorType : Component<P, {}>
|
||||
|
||||
class CoachMarkAnchorDecorator {
|
||||
>CoachMarkAnchorDecorator : CoachMarkAnchorDecorator
|
||||
|
||||
decorateComponent<P>(anchor: P) {
|
||||
>decorateComponent : <P>(anchor: P) => typeof CoachMarkAnchor
|
||||
>anchor : P
|
||||
|
||||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> {
|
||||
>class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> { private _onAnchorRef = (anchor: AnchorType<P>) => { const anchorRef = this.props.anchorRef; if (anchorRef) { anchorRef(anchor); } } } : typeof CoachMarkAnchor
|
||||
>CoachMarkAnchor : typeof CoachMarkAnchor
|
||||
>Component : Component<CoachMarkAnchorProps<Component<P, {}>> & P, {}>
|
||||
|
||||
private _onAnchorRef = (anchor: AnchorType<P>) => {
|
||||
>_onAnchorRef : (anchor: Component<P, {}>) => void
|
||||
>(anchor: AnchorType<P>) => { const anchorRef = this.props.anchorRef; if (anchorRef) { anchorRef(anchor); } } : (anchor: Component<P, {}>) => void
|
||||
>anchor : Component<P, {}>
|
||||
|
||||
const anchorRef = this.props.anchorRef;
|
||||
>anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined
|
||||
>this.props.anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined
|
||||
>this.props : Readonly<{ children?: unknown; }> & Readonly<CoachMarkAnchorProps<Component<P, {}>> & P>
|
||||
>this : this
|
||||
>props : Readonly<{ children?: unknown; }> & Readonly<CoachMarkAnchorProps<Component<P, {}>> & P>
|
||||
>anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined
|
||||
|
||||
if (anchorRef) {
|
||||
>anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined
|
||||
|
||||
anchorRef(anchor);
|
||||
>anchorRef(anchor) : void
|
||||
>anchorRef : (anchor: Component<P, {}>) => void
|
||||
>anchor : Component<P, {}>
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,16 +32,16 @@ var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolea
|
||||
>a : string
|
||||
|
||||
anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : error
|
||||
>anyVar : number
|
||||
>unionOfTypesWithAndWithoutStringSignature["hello"] : any
|
||||
>unionOfTypesWithAndWithoutStringSignature["hello"] : error
|
||||
>unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; }
|
||||
>"hello" : "hello"
|
||||
|
||||
anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature[10] : any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature[10] : error
|
||||
>anyVar : number
|
||||
>unionOfTypesWithAndWithoutStringSignature[10] : any
|
||||
>unionOfTypesWithAndWithoutStringSignature[10] : error
|
||||
>unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; }
|
||||
>10 : 10
|
||||
|
||||
@@ -53,9 +53,9 @@ var unionOfDifferentReturnType1: { [a: number]: number; } | { [a: number]: Date;
|
||||
>a : number
|
||||
|
||||
numOrDate = unionOfDifferentReturnType1["hello"]; // any
|
||||
>numOrDate = unionOfDifferentReturnType1["hello"] : any
|
||||
>numOrDate = unionOfDifferentReturnType1["hello"] : error
|
||||
>numOrDate : number | Date
|
||||
>unionOfDifferentReturnType1["hello"] : any
|
||||
>unionOfDifferentReturnType1["hello"] : error
|
||||
>unionOfDifferentReturnType1 : { [a: number]: number; } | { [a: number]: Date; }
|
||||
>"hello" : "hello"
|
||||
|
||||
@@ -71,16 +71,16 @@ var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boole
|
||||
>a : number
|
||||
|
||||
anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : error
|
||||
>anyVar : number
|
||||
>unionOfTypesWithAndWithoutStringSignature1["hello"] : any
|
||||
>unionOfTypesWithAndWithoutStringSignature1["hello"] : error
|
||||
>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; }
|
||||
>"hello" : "hello"
|
||||
|
||||
anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : any
|
||||
>anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : error
|
||||
>anyVar : number
|
||||
>unionOfTypesWithAndWithoutStringSignature1[10] : any
|
||||
>unionOfTypesWithAndWithoutStringSignature1[10] : error
|
||||
>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; }
|
||||
>10 : 10
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//// [varianceCallbacksAndIndexedAccesses.ts]
|
||||
type Source = {
|
||||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
||||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
}
|
||||
|
||||
interface Action1<T> {
|
||||
(arg: T): void;
|
||||
}
|
||||
interface MessageEventLike<T> {
|
||||
source: WindowLike<T>;
|
||||
origin: string;
|
||||
data: T;
|
||||
}
|
||||
interface PostMessageObject<T> {
|
||||
postMessage(message: T, host: string): void;
|
||||
}
|
||||
interface WindowLike<T> extends PostMessageObject<T> {
|
||||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
addEventListener(type: string, handler: Action1<any>): void;
|
||||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
removeEventListener(type: string, handler: Action1<any>): void;
|
||||
}
|
||||
type Target = {
|
||||
(type: "message", handler: Action1<MessageEventLike<any>>): void;
|
||||
(type: string, handler: Action1<any>): void;
|
||||
};
|
||||
|
||||
function f1(s: Source, t: Target) {
|
||||
t = s;
|
||||
}
|
||||
|
||||
//// [varianceCallbacksAndIndexedAccesses.js]
|
||||
function f1(s, t) {
|
||||
t = s;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
=== tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts ===
|
||||
type Source = {
|
||||
>Source : Symbol(Source, Decl(varianceCallbacksAndIndexedAccesses.ts, 0, 0))
|
||||
|
||||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
||||
>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5))
|
||||
>WindowEventMap : Symbol(WindowEventMap, Decl(lib.dom.d.ts, --, --))
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 37))
|
||||
>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5))
|
||||
>listener : Symbol(listener, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 45))
|
||||
>this : Symbol(this, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 57))
|
||||
>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
|
||||
>ev : Symbol(ev, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 70))
|
||||
>WindowEventMap : Symbol(WindowEventMap, Decl(lib.dom.d.ts, --, --))
|
||||
>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5))
|
||||
>options : Symbol(options, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 101))
|
||||
>AddEventListenerOptions : Symbol(AddEventListenerOptions, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 3))
|
||||
>listener : Symbol(listener, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 16))
|
||||
>EventListenerOrEventListenerObject : Symbol(EventListenerOrEventListenerObject, Decl(lib.dom.d.ts, --, --))
|
||||
>options : Symbol(options, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 62))
|
||||
>AddEventListenerOptions : Symbol(AddEventListenerOptions, Decl(lib.dom.d.ts, --, --))
|
||||
}
|
||||
|
||||
interface Action1<T> {
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 5, 18))
|
||||
|
||||
(arg: T): void;
|
||||
>arg : Symbol(arg, Decl(varianceCallbacksAndIndexedAccesses.ts, 6, 5))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 5, 18))
|
||||
}
|
||||
interface MessageEventLike<T> {
|
||||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27))
|
||||
|
||||
source: WindowLike<T>;
|
||||
>source : Symbol(MessageEventLike.source, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 31))
|
||||
>WindowLike : Symbol(WindowLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 15, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27))
|
||||
|
||||
origin: string;
|
||||
>origin : Symbol(MessageEventLike.origin, Decl(varianceCallbacksAndIndexedAccesses.ts, 9, 26))
|
||||
|
||||
data: T;
|
||||
>data : Symbol(MessageEventLike.data, Decl(varianceCallbacksAndIndexedAccesses.ts, 10, 19))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27))
|
||||
}
|
||||
interface PostMessageObject<T> {
|
||||
>PostMessageObject : Symbol(PostMessageObject, Decl(varianceCallbacksAndIndexedAccesses.ts, 12, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 28))
|
||||
|
||||
postMessage(message: T, host: string): void;
|
||||
>postMessage : Symbol(PostMessageObject.postMessage, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 32))
|
||||
>message : Symbol(message, Decl(varianceCallbacksAndIndexedAccesses.ts, 14, 16))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 28))
|
||||
>host : Symbol(host, Decl(varianceCallbacksAndIndexedAccesses.ts, 14, 27))
|
||||
}
|
||||
interface WindowLike<T> extends PostMessageObject<T> {
|
||||
>WindowLike : Symbol(WindowLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 15, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21))
|
||||
>PostMessageObject : Symbol(PostMessageObject, Decl(varianceCallbacksAndIndexedAccesses.ts, 12, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21))
|
||||
|
||||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
>addEventListener : Symbol(WindowLike.addEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 54), Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 83))
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 21))
|
||||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 37))
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21))
|
||||
|
||||
addEventListener(type: string, handler: Action1<any>): void;
|
||||
>addEventListener : Symbol(WindowLike.addEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 54), Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 83))
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 21))
|
||||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 34))
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
|
||||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
>removeEventListener : Symbol(WindowLike.removeEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 64), Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 86))
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 24))
|
||||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 40))
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21))
|
||||
|
||||
removeEventListener(type: string, handler: Action1<any>): void;
|
||||
>removeEventListener : Symbol(WindowLike.removeEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 64), Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 86))
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 20, 24))
|
||||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 20, 37))
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
}
|
||||
type Target = {
|
||||
>Target : Symbol(Target, Decl(varianceCallbacksAndIndexedAccesses.ts, 21, 1))
|
||||
|
||||
(type: "message", handler: Action1<MessageEventLike<any>>): void;
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 23, 5))
|
||||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 23, 21))
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1))
|
||||
|
||||
(type: string, handler: Action1<any>): void;
|
||||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 24, 5))
|
||||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 24, 18))
|
||||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1))
|
||||
|
||||
};
|
||||
|
||||
function f1(s: Source, t: Target) {
|
||||
>f1 : Symbol(f1, Decl(varianceCallbacksAndIndexedAccesses.ts, 25, 2))
|
||||
>s : Symbol(s, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 12))
|
||||
>Source : Symbol(Source, Decl(varianceCallbacksAndIndexedAccesses.ts, 0, 0))
|
||||
>t : Symbol(t, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 22))
|
||||
>Target : Symbol(Target, Decl(varianceCallbacksAndIndexedAccesses.ts, 21, 1))
|
||||
|
||||
t = s;
|
||||
>t : Symbol(t, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 22))
|
||||
>s : Symbol(s, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 12))
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
=== tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts ===
|
||||
type Source = {
|
||||
>Source : Source
|
||||
|
||||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
||||
>type : K
|
||||
>listener : (this: Window, ev: WindowEventMap[K]) => any
|
||||
>this : Window
|
||||
>ev : WindowEventMap[K]
|
||||
>options : boolean | AddEventListenerOptions
|
||||
|
||||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
>type : string
|
||||
>listener : EventListenerOrEventListenerObject
|
||||
>options : boolean | AddEventListenerOptions
|
||||
}
|
||||
|
||||
interface Action1<T> {
|
||||
(arg: T): void;
|
||||
>arg : T
|
||||
}
|
||||
interface MessageEventLike<T> {
|
||||
source: WindowLike<T>;
|
||||
>source : WindowLike<T>
|
||||
|
||||
origin: string;
|
||||
>origin : string
|
||||
|
||||
data: T;
|
||||
>data : T
|
||||
}
|
||||
interface PostMessageObject<T> {
|
||||
postMessage(message: T, host: string): void;
|
||||
>postMessage : (message: T, host: string) => void
|
||||
>message : T
|
||||
>host : string
|
||||
}
|
||||
interface WindowLike<T> extends PostMessageObject<T> {
|
||||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
>addEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; }
|
||||
>type : "message"
|
||||
>handler : Action1<MessageEventLike<T>>
|
||||
|
||||
addEventListener(type: string, handler: Action1<any>): void;
|
||||
>addEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; }
|
||||
>type : string
|
||||
>handler : Action1<any>
|
||||
|
||||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
>removeEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; }
|
||||
>type : "message"
|
||||
>handler : Action1<MessageEventLike<T>>
|
||||
|
||||
removeEventListener(type: string, handler: Action1<any>): void;
|
||||
>removeEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; }
|
||||
>type : string
|
||||
>handler : Action1<any>
|
||||
}
|
||||
type Target = {
|
||||
>Target : Target
|
||||
|
||||
(type: "message", handler: Action1<MessageEventLike<any>>): void;
|
||||
>type : "message"
|
||||
>handler : Action1<MessageEventLike<any>>
|
||||
|
||||
(type: string, handler: Action1<any>): void;
|
||||
>type : string
|
||||
>handler : Action1<any>
|
||||
|
||||
};
|
||||
|
||||
function f1(s: Source, t: Target) {
|
||||
>f1 : (s: Source, t: Target) => void
|
||||
>s : Source
|
||||
>t : Target
|
||||
|
||||
t = s;
|
||||
>t = s : Source
|
||||
>t : Target
|
||||
>s : Source
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// @strict: true
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
type Shared< // Circularly self constraining type, defered thanks to mapping
|
||||
InjectedProps,
|
||||
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
|
||||
> = {
|
||||
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
|
||||
};
|
||||
|
||||
interface ComponentClass<P> {
|
||||
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
|
||||
}
|
||||
|
||||
interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
|
||||
<P extends Shared<TInjectedProps, P>>(
|
||||
component: ComponentClass<P>
|
||||
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
|
||||
} // Then intersected with and indexed via Omit and &
|
||||
|
||||
interface Connect { // Then strictly compared with another signature in its context
|
||||
<TStateProps, TOwnProps>(
|
||||
mapStateToProps: unknown,
|
||||
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;
|
||||
|
||||
<TDispatchProps, TOwnProps>(
|
||||
mapStateToProps: null | undefined,
|
||||
mapDispatchToProps: unknown,
|
||||
mergeProps: null | undefined,
|
||||
options: unknown
|
||||
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
|
||||
}
|
||||
|
||||
declare var connect: Connect;
|
||||
|
||||
const myStoreConnect: Connect = function(
|
||||
mapStateToProps?: any,
|
||||
mapDispatchToProps?: any,
|
||||
mergeProps?: any,
|
||||
options: unknown = {},
|
||||
) {
|
||||
return connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps,
|
||||
mergeProps,
|
||||
options,
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
// @strict: true
|
||||
type ExtendedService<T> = {
|
||||
[K in keyof T]: T[K] & {
|
||||
__$daemonMode?: string;
|
||||
__$action?: string;
|
||||
};
|
||||
};
|
||||
|
||||
type Service<T> = {
|
||||
[K in keyof T]: T[K] & {id?: string};
|
||||
};
|
||||
|
||||
export const createService = <T>(
|
||||
ServiceCtr: ExtendedService<T> & Service<T>
|
||||
) => {
|
||||
Object.keys(ServiceCtr).forEach(key => {
|
||||
const method = (ServiceCtr)[key as keyof T];
|
||||
const {__$daemonMode, __$action, id} = method;
|
||||
})
|
||||
}
|
||||
23
tests/cases/compiler/spyComparisonChecking.ts
Normal file
23
tests/cases/compiler/spyComparisonChecking.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
interface Spy {
|
||||
(...params: any[]): any;
|
||||
|
||||
identity: string;
|
||||
and: Function;
|
||||
mostRecentCall: { args: any[]; };
|
||||
argsForCall: any[];
|
||||
}
|
||||
|
||||
type SpyObj<T> = T & {
|
||||
[k in keyof T]: Spy;
|
||||
}
|
||||
|
||||
declare function createSpyObj<T>(
|
||||
name: string, names: Array<keyof T>): SpyObj<T>;
|
||||
|
||||
function mock<T>(spyName: string, methodNames: Array<keyof T>): SpyObj<T> {
|
||||
const spyObj = createSpyObj<T>(spyName, methodNames);
|
||||
for (const methodName of methodNames) {
|
||||
spyObj[methodName].and.returnValue(1);
|
||||
}
|
||||
return spyObj;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// @strict: true
|
||||
declare class Component<P, S = {}> {
|
||||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>;
|
||||
state: Readonly<S>;
|
||||
}
|
||||
interface CoachMarkAnchorProps<C> {
|
||||
anchorRef?: (anchor: C) => void;
|
||||
}
|
||||
type AnchorType<P> = Component<P>;
|
||||
|
||||
class CoachMarkAnchorDecorator {
|
||||
decorateComponent<P>(anchor: P) {
|
||||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> {
|
||||
private _onAnchorRef = (anchor: AnchorType<P>) => {
|
||||
const anchorRef = this.props.anchorRef;
|
||||
if (anchorRef) {
|
||||
anchorRef(anchor);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
32
tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts
Normal file
32
tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
type Source = {
|
||||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
||||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
}
|
||||
|
||||
interface Action1<T> {
|
||||
(arg: T): void;
|
||||
}
|
||||
interface MessageEventLike<T> {
|
||||
source: WindowLike<T>;
|
||||
origin: string;
|
||||
data: T;
|
||||
}
|
||||
interface PostMessageObject<T> {
|
||||
postMessage(message: T, host: string): void;
|
||||
}
|
||||
interface WindowLike<T> extends PostMessageObject<T> {
|
||||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
addEventListener(type: string, handler: Action1<any>): void;
|
||||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void;
|
||||
removeEventListener(type: string, handler: Action1<any>): void;
|
||||
}
|
||||
type Target = {
|
||||
(type: "message", handler: Action1<MessageEventLike<any>>): void;
|
||||
(type: string, handler: Action1<any>): void;
|
||||
};
|
||||
|
||||
function f1(s: Source, t: Target) {
|
||||
t = s;
|
||||
}
|
||||
Reference in New Issue
Block a user