Merge pull request #30363 from Microsoft/fixTypeParameterPromotion
Higher order type parameter promotion fixes
This commit is contained in:
commit
36cf12fe0a
10 changed files with 724 additions and 285 deletions
|
@ -8298,7 +8298,7 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
signature.resolvedTypePredicate = type && isTypePredicateNode(type) ?
|
||||
createTypePredicateFromTypePredicateNode(type, signature.declaration!) :
|
||||
createTypePredicateFromTypePredicateNode(type, signature) :
|
||||
jsdocPredicate || noTypePredicate;
|
||||
}
|
||||
Debug.assert(!!signature.resolvedTypePredicate);
|
||||
|
@ -8306,13 +8306,13 @@ namespace ts {
|
|||
return signature.resolvedTypePredicate === noTypePredicate ? undefined : signature.resolvedTypePredicate;
|
||||
}
|
||||
|
||||
function createTypePredicateFromTypePredicateNode(node: TypePredicateNode, func: SignatureDeclaration | JSDocSignature): IdentifierTypePredicate | ThisTypePredicate {
|
||||
function createTypePredicateFromTypePredicateNode(node: TypePredicateNode, signature: Signature): IdentifierTypePredicate | ThisTypePredicate {
|
||||
const { parameterName } = node;
|
||||
const type = getTypeFromTypeNode(node.type);
|
||||
if (parameterName.kind === SyntaxKind.Identifier) {
|
||||
return createIdentifierTypePredicate(
|
||||
parameterName.escapedText as string,
|
||||
getTypePredicateParameterIndex(func.parameters, parameterName),
|
||||
findIndex(signature.parameters, p => p.escapedName === parameterName.escapedText),
|
||||
type);
|
||||
}
|
||||
else {
|
||||
|
@ -8320,16 +8320,6 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function getTypePredicateParameterIndex(parameterList: ReadonlyArray<ParameterDeclaration | JSDocParameterTag>, parameter: Identifier): number {
|
||||
for (let i = 0; i < parameterList.length; i++) {
|
||||
const param = parameterList[i];
|
||||
if (param.name.kind === SyntaxKind.Identifier && param.name.escapedText === parameter.escapedText) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function getReturnTypeOfSignature(signature: Signature): Type {
|
||||
if (!signature.resolvedReturnType) {
|
||||
if (!pushTypeResolution(signature, TypeSystemPropertyName.ResolvedReturnType)) {
|
||||
|
@ -11832,7 +11822,7 @@ namespace ts {
|
|||
if (targetTypePredicate) {
|
||||
const sourceTypePredicate = getTypePredicateOfSignature(source);
|
||||
if (sourceTypePredicate) {
|
||||
result &= compareTypePredicateRelatedTo(sourceTypePredicate, targetTypePredicate, source.declaration!, target.declaration!, reportErrors, errorReporter, compareTypes); // TODO: GH#18217
|
||||
result &= compareTypePredicateRelatedTo(sourceTypePredicate, targetTypePredicate, reportErrors, errorReporter, compareTypes);
|
||||
}
|
||||
else if (isIdentifierTypePredicate(targetTypePredicate)) {
|
||||
if (reportErrors) {
|
||||
|
@ -11857,8 +11847,6 @@ namespace ts {
|
|||
function compareTypePredicateRelatedTo(
|
||||
source: TypePredicate,
|
||||
target: TypePredicate,
|
||||
sourceDeclaration: SignatureDeclaration | JSDocSignature,
|
||||
targetDeclaration: SignatureDeclaration | JSDocSignature,
|
||||
reportErrors: boolean,
|
||||
errorReporter: ErrorReporter | undefined,
|
||||
compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
|
||||
|
@ -11871,12 +11859,9 @@ namespace ts {
|
|||
}
|
||||
|
||||
if (source.kind === TypePredicateKind.Identifier) {
|
||||
const targetPredicate = target as IdentifierTypePredicate;
|
||||
const sourceIndex = source.parameterIndex - (getThisParameter(sourceDeclaration) ? 1 : 0);
|
||||
const targetIndex = targetPredicate.parameterIndex - (getThisParameter(targetDeclaration) ? 1 : 0);
|
||||
if (sourceIndex !== targetIndex) {
|
||||
if (source.parameterIndex !== (target as IdentifierTypePredicate).parameterIndex) {
|
||||
if (reportErrors) {
|
||||
errorReporter!(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, source.parameterName, targetPredicate.parameterName);
|
||||
errorReporter!(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, source.parameterName, (target as IdentifierTypePredicate).parameterName);
|
||||
errorReporter!(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typePredicateToString(source), typePredicateToString(target));
|
||||
}
|
||||
return Ternary.False;
|
||||
|
@ -14283,7 +14268,7 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function forEachMatchingParameterType(source: Signature, target: Signature, callback: (s: Type, t: Type) => void) {
|
||||
function applyToParameterTypes(source: Signature, target: Signature, callback: (s: Type, t: Type) => void) {
|
||||
const sourceCount = getParameterCount(source);
|
||||
const targetCount = getParameterCount(target);
|
||||
const sourceRestType = getEffectiveRestType(source);
|
||||
|
@ -14305,6 +14290,18 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function applyToReturnTypes(source: Signature, target: Signature, callback: (s: Type, t: Type) => void) {
|
||||
const sourceTypePredicate = getTypePredicateOfSignature(source);
|
||||
const targetTypePredicate = getTypePredicateOfSignature(target);
|
||||
if (sourceTypePredicate && targetTypePredicate && sourceTypePredicate.kind === targetTypePredicate.kind &&
|
||||
(sourceTypePredicate.kind === TypePredicateKind.This || sourceTypePredicate.parameterIndex === (<IdentifierTypePredicate>targetTypePredicate).parameterIndex)) {
|
||||
callback(sourceTypePredicate.type, targetTypePredicate.type);
|
||||
}
|
||||
else {
|
||||
callback(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
|
||||
}
|
||||
}
|
||||
|
||||
function createInferenceContext(typeParameters: ReadonlyArray<TypeParameter>, signature: Signature | undefined, flags: InferenceFlags, compareTypes?: TypeComparer): InferenceContext {
|
||||
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
|
||||
}
|
||||
|
@ -14523,10 +14520,9 @@ namespace ts {
|
|||
emptyObjectType;
|
||||
}
|
||||
|
||||
function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0) {
|
||||
function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0, contravariant = false) {
|
||||
let symbolStack: Symbol[];
|
||||
let visited: Map<boolean>;
|
||||
let contravariant = false;
|
||||
let bivariant = false;
|
||||
let propagationType: Type;
|
||||
let allowComplexConstraintInference = true;
|
||||
|
@ -14924,17 +14920,10 @@ namespace ts {
|
|||
const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown;
|
||||
// Once we descend into a bivariant signature we remain bivariant for all nested inferences
|
||||
bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor;
|
||||
forEachMatchingParameterType(source, target, inferFromContravariantTypes);
|
||||
applyToParameterTypes(source, target, inferFromContravariantTypes);
|
||||
bivariant = saveBivariant;
|
||||
}
|
||||
const sourceTypePredicate = getTypePredicateOfSignature(source);
|
||||
const targetTypePredicate = getTypePredicateOfSignature(target);
|
||||
if (sourceTypePredicate && targetTypePredicate && sourceTypePredicate.kind === targetTypePredicate.kind) {
|
||||
inferFromTypes(sourceTypePredicate.type, targetTypePredicate.type);
|
||||
}
|
||||
else {
|
||||
inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
|
||||
}
|
||||
applyToReturnTypes(source, target, inferFromTypes);
|
||||
}
|
||||
|
||||
function inferFromIndexTypes(source: Type, target: Type) {
|
||||
|
@ -16600,7 +16589,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
if (isIdentifierTypePredicate(predicate)) {
|
||||
const predicateArgument = callExpression.arguments[predicate.parameterIndex - (signature.thisParameter ? 1 : 0)];
|
||||
const predicateArgument = callExpression.arguments[predicate.parameterIndex];
|
||||
if (predicateArgument) {
|
||||
if (isMatchingReference(reference, predicateArgument)) {
|
||||
return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
|
||||
|
@ -20170,18 +20159,14 @@ namespace ts {
|
|||
const restType = getEffectiveRestType(contextualSignature);
|
||||
const mapper = inferenceContext && (restType && restType.flags & TypeFlags.TypeParameter ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
|
||||
const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
|
||||
forEachMatchingParameterType(sourceSignature, signature, (source, target) => {
|
||||
applyToParameterTypes(sourceSignature, signature, (source, target) => {
|
||||
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
|
||||
inferTypes(context.inferences, source, target);
|
||||
});
|
||||
if (!inferenceContext) {
|
||||
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType);
|
||||
const signaturePredicate = getTypePredicateOfSignature(signature);
|
||||
const contextualPredicate = getTypePredicateOfSignature(sourceSignature);
|
||||
if (signaturePredicate && contextualPredicate && signaturePredicate.kind === contextualPredicate.kind &&
|
||||
(signaturePredicate.kind === TypePredicateKind.This || signaturePredicate.parameterIndex === (contextualPredicate as IdentifierTypePredicate).parameterIndex)) {
|
||||
inferTypes(context.inferences, contextualPredicate.type, signaturePredicate.type, InferencePriority.ReturnType);
|
||||
}
|
||||
applyToReturnTypes(contextualSignature, signature, (source, target) => {
|
||||
inferTypes(context.inferences, source, target, InferencePriority.ReturnType);
|
||||
});
|
||||
}
|
||||
return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
|
||||
}
|
||||
|
@ -23520,23 +23505,30 @@ namespace ts {
|
|||
// potentially add inferred type parameters to the outer function return type.
|
||||
const returnSignature = context.signature && getSingleCallSignature(getReturnTypeOfSignature(context.signature));
|
||||
if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) {
|
||||
// Instantiate the expression type with its own type parameters as type arguments. This
|
||||
// ensures that the type parameters are not erased to type any during type inference such
|
||||
// that they can be inferred as actual types.
|
||||
// Instantiate the signature with its own type parameters as type arguments, possibly
|
||||
// renaming the type parameters to ensure they have unique names.
|
||||
const uniqueTypeParameters = getUniqueTypeParameters(context, signature.typeParameters);
|
||||
const strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
|
||||
// Infer from the stripped expression type to the contextual type starting with an empty
|
||||
// set of inference candidates.
|
||||
const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters);
|
||||
// Infer from the parameters of the instantiated signature to the parameters of the
|
||||
// contextual signature starting with an empty set of inference candidates.
|
||||
const inferences = map(context.inferences, info => createInferenceInfo(info.typeParameter));
|
||||
inferTypes(inferences, strippedType, contextualType);
|
||||
// If we produced some inference candidates and if the type parameters for which we produced
|
||||
// candidates do not already have existing inferences, we adopt the new inference candidates and
|
||||
// add the type parameters of the expression type to the set of inferred type parameters for
|
||||
// the outer function return type.
|
||||
if (some(inferences, hasInferenceCandidates) && !hasOverlappingInferences(context.inferences, inferences)) {
|
||||
mergeInferences(context.inferences, inferences);
|
||||
context.inferredTypeParameters = concatenate(context.inferredTypeParameters, uniqueTypeParameters);
|
||||
return strippedType;
|
||||
applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => {
|
||||
inferTypes(inferences, source, target, /*priority*/ 0, /*contravariant*/ true);
|
||||
});
|
||||
if (some(inferences, hasInferenceCandidates)) {
|
||||
// We have inference candidates, indicating that one or more type parameters are referenced
|
||||
// in the parameter types of the contextual signature. Now also infer from the return type.
|
||||
applyToReturnTypes(instantiatedSignature, contextualSignature, (source, target) => {
|
||||
inferTypes(inferences, source, target);
|
||||
});
|
||||
// If the type parameters for which we produced candidates do not have any inferences yet,
|
||||
// we adopt the new inference candidates and add the type parameters of the expression type
|
||||
// to the set of inferred type parameters for the outer function return type.
|
||||
if (!hasOverlappingInferences(context.inferences, inferences)) {
|
||||
mergeInferences(context.inferences, inferences);
|
||||
context.inferredTypeParameters = concatenate(context.inferredTypeParameters, uniqueTypeParameters);
|
||||
return getOrCreateTypeFromSignature(instantiatedSignature);
|
||||
}
|
||||
}
|
||||
}
|
||||
return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, context));
|
||||
|
@ -23880,7 +23872,8 @@ namespace ts {
|
|||
return;
|
||||
}
|
||||
|
||||
const typePredicate = getTypePredicateOfSignature(getSignatureFromDeclaration(parent));
|
||||
const signature = getSignatureFromDeclaration(parent);
|
||||
const typePredicate = getTypePredicateOfSignature(signature);
|
||||
if (!typePredicate) {
|
||||
return;
|
||||
}
|
||||
|
@ -23893,14 +23886,13 @@ namespace ts {
|
|||
}
|
||||
else {
|
||||
if (typePredicate.parameterIndex >= 0) {
|
||||
if (parent.parameters[typePredicate.parameterIndex].dotDotDotToken) {
|
||||
error(parameterName,
|
||||
Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
|
||||
if (signature.hasRestParameter && typePredicate.parameterIndex === signature.parameters.length - 1) {
|
||||
error(parameterName, Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
|
||||
}
|
||||
else {
|
||||
const leadingError = () => chainDiagnosticMessages(/*details*/ undefined, Diagnostics.A_type_predicate_s_type_must_be_assignable_to_its_parameter_s_type);
|
||||
checkTypeAssignableTo(typePredicate.type,
|
||||
getTypeOfNode(parent.parameters[typePredicate.parameterIndex]),
|
||||
getTypeOfSymbol(signature.parameters[typePredicate.parameterIndex]),
|
||||
node.type,
|
||||
/*headMessage*/ undefined,
|
||||
leadingError);
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
//// [contravariantInferenceAndTypeGuard.ts]
|
||||
interface ListItem<TData> {
|
||||
prev: ListItem<TData> | null;
|
||||
next: ListItem<TData> | null;
|
||||
data: TData;
|
||||
}
|
||||
type IteratorFn<TData, TResult, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => TResult;
|
||||
type FilterFn<TData, TResult extends TData, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => item is TResult;
|
||||
|
||||
declare class List<TData> {
|
||||
filter<TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>;
|
||||
filter<TResult extends TData>(fn: FilterFn<TData, TResult>): List<TResult>;
|
||||
filter<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>;
|
||||
filter(fn: IteratorFn<TData, boolean>): List<TData>;
|
||||
}
|
||||
interface Test {
|
||||
a: string;
|
||||
}
|
||||
const list2 = new List<Test | null>();
|
||||
const filter1 = list2.filter(function(item, node, list): item is Test {
|
||||
this.b; // $ExpectType string
|
||||
item; // $ExpectType Test | null
|
||||
node; // $ExpectType ListItem<Test | null>
|
||||
list; // $ExpectType List<Test | null>
|
||||
return !!item;
|
||||
}, {b: 'c'});
|
||||
const x: List<Test> = filter1; // $ExpectType List<Test>
|
||||
|
||||
|
||||
//// [contravariantInferenceAndTypeGuard.js]
|
||||
"use strict";
|
||||
var list2 = new List();
|
||||
var filter1 = list2.filter(function (item, node, list) {
|
||||
this.b; // $ExpectType string
|
||||
item; // $ExpectType Test | null
|
||||
node; // $ExpectType ListItem<Test | null>
|
||||
list; // $ExpectType List<Test | null>
|
||||
return !!item;
|
||||
}, { b: 'c' });
|
||||
var x = filter1; // $ExpectType List<Test>
|
|
@ -0,0 +1,157 @@
|
|||
=== tests/cases/compiler/contravariantInferenceAndTypeGuard.ts ===
|
||||
interface ListItem<TData> {
|
||||
>ListItem : Symbol(ListItem, Decl(contravariantInferenceAndTypeGuard.ts, 0, 0))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 0, 19))
|
||||
|
||||
prev: ListItem<TData> | null;
|
||||
>prev : Symbol(ListItem.prev, Decl(contravariantInferenceAndTypeGuard.ts, 0, 27))
|
||||
>ListItem : Symbol(ListItem, Decl(contravariantInferenceAndTypeGuard.ts, 0, 0))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 0, 19))
|
||||
|
||||
next: ListItem<TData> | null;
|
||||
>next : Symbol(ListItem.next, Decl(contravariantInferenceAndTypeGuard.ts, 1, 33))
|
||||
>ListItem : Symbol(ListItem, Decl(contravariantInferenceAndTypeGuard.ts, 0, 0))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 0, 19))
|
||||
|
||||
data: TData;
|
||||
>data : Symbol(ListItem.data, Decl(contravariantInferenceAndTypeGuard.ts, 2, 33))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 0, 19))
|
||||
}
|
||||
type IteratorFn<TData, TResult, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => TResult;
|
||||
>IteratorFn : Symbol(IteratorFn, Decl(contravariantInferenceAndTypeGuard.ts, 4, 1))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 5, 16))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 5, 22))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 5, 31))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 5, 16))
|
||||
>this : Symbol(this, Decl(contravariantInferenceAndTypeGuard.ts, 5, 59))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 5, 31))
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 5, 74))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 5, 16))
|
||||
>node : Symbol(node, Decl(contravariantInferenceAndTypeGuard.ts, 5, 87))
|
||||
>ListItem : Symbol(ListItem, Decl(contravariantInferenceAndTypeGuard.ts, 0, 0))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 5, 16))
|
||||
>list : Symbol(list, Decl(contravariantInferenceAndTypeGuard.ts, 5, 110))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 5, 16))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 5, 22))
|
||||
|
||||
type FilterFn<TData, TResult extends TData, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => item is TResult;
|
||||
>FilterFn : Symbol(FilterFn, Decl(contravariantInferenceAndTypeGuard.ts, 5, 141))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 6, 14))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 6, 20))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 6, 14))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 6, 43))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 6, 14))
|
||||
>this : Symbol(this, Decl(contravariantInferenceAndTypeGuard.ts, 6, 71))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 6, 43))
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 6, 86))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 6, 14))
|
||||
>node : Symbol(node, Decl(contravariantInferenceAndTypeGuard.ts, 6, 99))
|
||||
>ListItem : Symbol(ListItem, Decl(contravariantInferenceAndTypeGuard.ts, 0, 0))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 6, 14))
|
||||
>list : Symbol(list, Decl(contravariantInferenceAndTypeGuard.ts, 6, 122))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 6, 14))
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 6, 86))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 6, 20))
|
||||
|
||||
declare class List<TData> {
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
|
||||
filter<TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>;
|
||||
>filter : Symbol(List.filter, Decl(contravariantInferenceAndTypeGuard.ts, 8, 27), Decl(contravariantInferenceAndTypeGuard.ts, 9, 118), Decl(contravariantInferenceAndTypeGuard.ts, 10, 79), Decl(contravariantInferenceAndTypeGuard.ts, 11, 95))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 9, 11))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 9, 20))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
>fn : Symbol(fn, Decl(contravariantInferenceAndTypeGuard.ts, 9, 44))
|
||||
>FilterFn : Symbol(FilterFn, Decl(contravariantInferenceAndTypeGuard.ts, 5, 141))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 9, 20))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 9, 11))
|
||||
>context : Symbol(context, Decl(contravariantInferenceAndTypeGuard.ts, 9, 83))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 9, 11))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 9, 20))
|
||||
|
||||
filter<TResult extends TData>(fn: FilterFn<TData, TResult>): List<TResult>;
|
||||
>filter : Symbol(List.filter, Decl(contravariantInferenceAndTypeGuard.ts, 8, 27), Decl(contravariantInferenceAndTypeGuard.ts, 9, 118), Decl(contravariantInferenceAndTypeGuard.ts, 10, 79), Decl(contravariantInferenceAndTypeGuard.ts, 11, 95))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 10, 11))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
>fn : Symbol(fn, Decl(contravariantInferenceAndTypeGuard.ts, 10, 34))
|
||||
>FilterFn : Symbol(FilterFn, Decl(contravariantInferenceAndTypeGuard.ts, 5, 141))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 10, 11))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TResult : Symbol(TResult, Decl(contravariantInferenceAndTypeGuard.ts, 10, 11))
|
||||
|
||||
filter<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>;
|
||||
>filter : Symbol(List.filter, Decl(contravariantInferenceAndTypeGuard.ts, 8, 27), Decl(contravariantInferenceAndTypeGuard.ts, 9, 118), Decl(contravariantInferenceAndTypeGuard.ts, 10, 79), Decl(contravariantInferenceAndTypeGuard.ts, 11, 95))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 11, 11))
|
||||
>fn : Symbol(fn, Decl(contravariantInferenceAndTypeGuard.ts, 11, 21))
|
||||
>IteratorFn : Symbol(IteratorFn, Decl(contravariantInferenceAndTypeGuard.ts, 4, 1))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 11, 11))
|
||||
>context : Symbol(context, Decl(contravariantInferenceAndTypeGuard.ts, 11, 62))
|
||||
>TContext : Symbol(TContext, Decl(contravariantInferenceAndTypeGuard.ts, 11, 11))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
|
||||
filter(fn: IteratorFn<TData, boolean>): List<TData>;
|
||||
>filter : Symbol(List.filter, Decl(contravariantInferenceAndTypeGuard.ts, 8, 27), Decl(contravariantInferenceAndTypeGuard.ts, 9, 118), Decl(contravariantInferenceAndTypeGuard.ts, 10, 79), Decl(contravariantInferenceAndTypeGuard.ts, 11, 95))
|
||||
>fn : Symbol(fn, Decl(contravariantInferenceAndTypeGuard.ts, 12, 11))
|
||||
>IteratorFn : Symbol(IteratorFn, Decl(contravariantInferenceAndTypeGuard.ts, 4, 1))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>TData : Symbol(TData, Decl(contravariantInferenceAndTypeGuard.ts, 8, 19))
|
||||
}
|
||||
interface Test {
|
||||
>Test : Symbol(Test, Decl(contravariantInferenceAndTypeGuard.ts, 13, 1))
|
||||
|
||||
a: string;
|
||||
>a : Symbol(Test.a, Decl(contravariantInferenceAndTypeGuard.ts, 14, 16))
|
||||
}
|
||||
const list2 = new List<Test | null>();
|
||||
>list2 : Symbol(list2, Decl(contravariantInferenceAndTypeGuard.ts, 17, 5))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>Test : Symbol(Test, Decl(contravariantInferenceAndTypeGuard.ts, 13, 1))
|
||||
|
||||
const filter1 = list2.filter(function(item, node, list): item is Test {
|
||||
>filter1 : Symbol(filter1, Decl(contravariantInferenceAndTypeGuard.ts, 18, 5))
|
||||
>list2.filter : Symbol(List.filter, Decl(contravariantInferenceAndTypeGuard.ts, 8, 27), Decl(contravariantInferenceAndTypeGuard.ts, 9, 118), Decl(contravariantInferenceAndTypeGuard.ts, 10, 79), Decl(contravariantInferenceAndTypeGuard.ts, 11, 95))
|
||||
>list2 : Symbol(list2, Decl(contravariantInferenceAndTypeGuard.ts, 17, 5))
|
||||
>filter : Symbol(List.filter, Decl(contravariantInferenceAndTypeGuard.ts, 8, 27), Decl(contravariantInferenceAndTypeGuard.ts, 9, 118), Decl(contravariantInferenceAndTypeGuard.ts, 10, 79), Decl(contravariantInferenceAndTypeGuard.ts, 11, 95))
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 18, 38))
|
||||
>node : Symbol(node, Decl(contravariantInferenceAndTypeGuard.ts, 18, 43))
|
||||
>list : Symbol(list, Decl(contravariantInferenceAndTypeGuard.ts, 18, 49))
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 18, 38))
|
||||
>Test : Symbol(Test, Decl(contravariantInferenceAndTypeGuard.ts, 13, 1))
|
||||
|
||||
this.b; // $ExpectType string
|
||||
>this.b : Symbol(b, Decl(contravariantInferenceAndTypeGuard.ts, 24, 4))
|
||||
>this : Symbol(this, Decl(contravariantInferenceAndTypeGuard.ts, 6, 71))
|
||||
>b : Symbol(b, Decl(contravariantInferenceAndTypeGuard.ts, 24, 4))
|
||||
|
||||
item; // $ExpectType Test | null
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 18, 38))
|
||||
|
||||
node; // $ExpectType ListItem<Test | null>
|
||||
>node : Symbol(node, Decl(contravariantInferenceAndTypeGuard.ts, 18, 43))
|
||||
|
||||
list; // $ExpectType List<Test | null>
|
||||
>list : Symbol(list, Decl(contravariantInferenceAndTypeGuard.ts, 18, 49))
|
||||
|
||||
return !!item;
|
||||
>item : Symbol(item, Decl(contravariantInferenceAndTypeGuard.ts, 18, 38))
|
||||
|
||||
}, {b: 'c'});
|
||||
>b : Symbol(b, Decl(contravariantInferenceAndTypeGuard.ts, 24, 4))
|
||||
|
||||
const x: List<Test> = filter1; // $ExpectType List<Test>
|
||||
>x : Symbol(x, Decl(contravariantInferenceAndTypeGuard.ts, 25, 5))
|
||||
>List : Symbol(List, Decl(contravariantInferenceAndTypeGuard.ts, 6, 161))
|
||||
>Test : Symbol(Test, Decl(contravariantInferenceAndTypeGuard.ts, 13, 1))
|
||||
>filter1 : Symbol(filter1, Decl(contravariantInferenceAndTypeGuard.ts, 18, 5))
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
=== tests/cases/compiler/contravariantInferenceAndTypeGuard.ts ===
|
||||
interface ListItem<TData> {
|
||||
prev: ListItem<TData> | null;
|
||||
>prev : ListItem<TData> | null
|
||||
>null : null
|
||||
|
||||
next: ListItem<TData> | null;
|
||||
>next : ListItem<TData> | null
|
||||
>null : null
|
||||
|
||||
data: TData;
|
||||
>data : TData
|
||||
}
|
||||
type IteratorFn<TData, TResult, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => TResult;
|
||||
>IteratorFn : IteratorFn<TData, TResult, TContext>
|
||||
>this : TContext
|
||||
>item : TData
|
||||
>node : ListItem<TData>
|
||||
>list : List<TData>
|
||||
|
||||
type FilterFn<TData, TResult extends TData, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => item is TResult;
|
||||
>FilterFn : FilterFn<TData, TResult, TContext>
|
||||
>this : TContext
|
||||
>item : TData
|
||||
>node : ListItem<TData>
|
||||
>list : List<TData>
|
||||
|
||||
declare class List<TData> {
|
||||
>List : List<TData>
|
||||
|
||||
filter<TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>;
|
||||
>filter : { <TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>; <TResult extends TData>(fn: FilterFn<TData, TResult, List<TData>>): List<TResult>; <TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>; (fn: IteratorFn<TData, boolean, List<TData>>): List<TData>; }
|
||||
>fn : FilterFn<TData, TResult, TContext>
|
||||
>context : TContext
|
||||
|
||||
filter<TResult extends TData>(fn: FilterFn<TData, TResult>): List<TResult>;
|
||||
>filter : { <TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>; <TResult extends TData>(fn: FilterFn<TData, TResult, List<TData>>): List<TResult>; <TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>; (fn: IteratorFn<TData, boolean, List<TData>>): List<TData>; }
|
||||
>fn : FilterFn<TData, TResult, List<TData>>
|
||||
|
||||
filter<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>;
|
||||
>filter : { <TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>; <TResult extends TData>(fn: FilterFn<TData, TResult, List<TData>>): List<TResult>; <TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>; (fn: IteratorFn<TData, boolean, List<TData>>): List<TData>; }
|
||||
>fn : IteratorFn<TData, boolean, TContext>
|
||||
>context : TContext
|
||||
|
||||
filter(fn: IteratorFn<TData, boolean>): List<TData>;
|
||||
>filter : { <TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>; <TResult extends TData>(fn: FilterFn<TData, TResult, List<TData>>): List<TResult>; <TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>; (fn: IteratorFn<TData, boolean, List<TData>>): List<TData>; }
|
||||
>fn : IteratorFn<TData, boolean, List<TData>>
|
||||
}
|
||||
interface Test {
|
||||
a: string;
|
||||
>a : string
|
||||
}
|
||||
const list2 = new List<Test | null>();
|
||||
>list2 : List<Test | null>
|
||||
>new List<Test | null>() : List<Test | null>
|
||||
>List : typeof List
|
||||
>null : null
|
||||
|
||||
const filter1 = list2.filter(function(item, node, list): item is Test {
|
||||
>filter1 : List<Test>
|
||||
>list2.filter(function(item, node, list): item is Test { this.b; // $ExpectType string item; // $ExpectType Test | null node; // $ExpectType ListItem<Test | null> list; // $ExpectType List<Test | null> return !!item;}, {b: 'c'}) : List<Test>
|
||||
>list2.filter : { <TContext, TResult extends Test | null>(fn: FilterFn<Test | null, TResult, TContext>, context: TContext): List<TResult>; <TResult extends Test | null>(fn: FilterFn<Test | null, TResult, List<Test | null>>): List<TResult>; <TContext>(fn: IteratorFn<Test | null, boolean, TContext>, context: TContext): List<Test | null>; (fn: IteratorFn<Test | null, boolean, List<Test | null>>): List<Test | null>; }
|
||||
>list2 : List<Test | null>
|
||||
>filter : { <TContext, TResult extends Test | null>(fn: FilterFn<Test | null, TResult, TContext>, context: TContext): List<TResult>; <TResult extends Test | null>(fn: FilterFn<Test | null, TResult, List<Test | null>>): List<TResult>; <TContext>(fn: IteratorFn<Test | null, boolean, TContext>, context: TContext): List<Test | null>; (fn: IteratorFn<Test | null, boolean, List<Test | null>>): List<Test | null>; }
|
||||
>function(item, node, list): item is Test { this.b; // $ExpectType string item; // $ExpectType Test | null node; // $ExpectType ListItem<Test | null> list; // $ExpectType List<Test | null> return !!item;} : (this: { b: string; }, item: Test | null, node: ListItem<Test | null>, list: List<Test | null>) => item is Test
|
||||
>item : Test | null
|
||||
>node : ListItem<Test | null>
|
||||
>list : List<Test | null>
|
||||
|
||||
this.b; // $ExpectType string
|
||||
>this.b : string
|
||||
>this : { b: string; }
|
||||
>b : string
|
||||
|
||||
item; // $ExpectType Test | null
|
||||
>item : Test | null
|
||||
|
||||
node; // $ExpectType ListItem<Test | null>
|
||||
>node : ListItem<Test | null>
|
||||
|
||||
list; // $ExpectType List<Test | null>
|
||||
>list : List<Test | null>
|
||||
|
||||
return !!item;
|
||||
>!!item : boolean
|
||||
>!item : boolean
|
||||
>item : Test | null
|
||||
|
||||
}, {b: 'c'});
|
||||
>{b: 'c'} : { b: string; }
|
||||
>b : string
|
||||
>'c' : "c"
|
||||
|
||||
const x: List<Test> = filter1; // $ExpectType List<Test>
|
||||
>x : List<Test>
|
||||
>filter1 : List<Test>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
tests/cases/compiler/genericFunctionInference1.ts(83,14): error TS2345: Argument of type '<a>(value: { key: a; }) => a' is not assignable to parameter of type '(value: Data) => string'.
|
||||
tests/cases/compiler/genericFunctionInference1.ts(88,14): error TS2345: Argument of type '<a>(value: { key: a; }) => a' is not assignable to parameter of type '(value: Data) => string'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
|
@ -62,6 +62,11 @@ tests/cases/compiler/genericFunctionInference1.ts(83,14): error TS2345: Argument
|
|||
|
||||
const f50 = pipe5(list); // No higher order inference
|
||||
|
||||
declare function wrap3<A, B, C>(f: (a: A, b1: B, b2: B) => C): (a: A, b1: B, b2: B) => C;
|
||||
declare function baz<T, U extends T>(t1: T, t2: T, u: U): [T, U];
|
||||
|
||||
let f60 = wrap3(baz);
|
||||
|
||||
// #417
|
||||
|
||||
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
|
||||
|
@ -199,3 +204,8 @@ tests/cases/compiler/genericFunctionInference1.ts(83,14): error TS2345: Argument
|
|||
foo2(identity);
|
||||
foo2(identity, 1);
|
||||
|
||||
// Repro from #30324
|
||||
|
||||
declare function times<T>(fn: (i: number) => T): (n: number) => T[];
|
||||
const a2 = times(identity)(5); // => [0, 1, 2, 3, 4]
|
||||
|
|
@ -58,6 +58,11 @@ declare function pipe5<A, B>(f: (a: A) => B): { f: (a: A) => B };
|
|||
|
||||
const f50 = pipe5(list); // No higher order inference
|
||||
|
||||
declare function wrap3<A, B, C>(f: (a: A, b1: B, b2: B) => C): (a: A, b1: B, b2: B) => C;
|
||||
declare function baz<T, U extends T>(t1: T, t2: T, u: U): [T, U];
|
||||
|
||||
let f60 = wrap3(baz);
|
||||
|
||||
// #417
|
||||
|
||||
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
|
||||
|
@ -192,6 +197,11 @@ foo2(() => {});
|
|||
foo2(identity);
|
||||
foo2(identity, 1);
|
||||
|
||||
// Repro from #30324
|
||||
|
||||
declare function times<T>(fn: (i: number) => T): (n: number) => T[];
|
||||
const a2 = times(identity)(5); // => [0, 1, 2, 3, 4]
|
||||
|
||||
|
||||
//// [genericFunctionInference1.js]
|
||||
const f00 = pipe(list);
|
||||
|
@ -231,6 +241,7 @@ const f32 = pipe3(list, list);
|
|||
const f40 = pipe4([list, box]);
|
||||
const f41 = pipe4([box, list]);
|
||||
const f50 = pipe5(list); // No higher order inference
|
||||
let f60 = wrap3(baz);
|
||||
// #417
|
||||
function mirror(f) { return f; }
|
||||
var identityM = mirror(identity);
|
||||
|
@ -276,3 +287,4 @@ const fn62 = pipe(getArray, x => x, x => first(x));
|
|||
foo2(() => { });
|
||||
foo2(identity);
|
||||
foo2(identity, 1);
|
||||
const a2 = times(identity)(5); // => [0, 1, 2, 3, 4]
|
||||
|
|
|
@ -457,299 +457,339 @@ const f50 = pipe5(list); // No higher order inference
|
|||
>pipe5 : Symbol(pipe5, Decl(genericFunctionInference1.ts, 53, 31))
|
||||
>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124))
|
||||
|
||||
declare function wrap3<A, B, C>(f: (a: A, b1: B, b2: B) => C): (a: A, b1: B, b2: B) => C;
|
||||
>wrap3 : Symbol(wrap3, Decl(genericFunctionInference1.ts, 57, 24))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 59, 23))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 59, 25))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 59, 28))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 59, 32))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 59, 36))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 59, 23))
|
||||
>b1 : Symbol(b1, Decl(genericFunctionInference1.ts, 59, 41))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 59, 25))
|
||||
>b2 : Symbol(b2, Decl(genericFunctionInference1.ts, 59, 48))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 59, 25))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 59, 28))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 59, 64))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 59, 23))
|
||||
>b1 : Symbol(b1, Decl(genericFunctionInference1.ts, 59, 69))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 59, 25))
|
||||
>b2 : Symbol(b2, Decl(genericFunctionInference1.ts, 59, 76))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 59, 25))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 59, 28))
|
||||
|
||||
declare function baz<T, U extends T>(t1: T, t2: T, u: U): [T, U];
|
||||
>baz : Symbol(baz, Decl(genericFunctionInference1.ts, 59, 89))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 21))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 60, 23))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 21))
|
||||
>t1 : Symbol(t1, Decl(genericFunctionInference1.ts, 60, 37))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 21))
|
||||
>t2 : Symbol(t2, Decl(genericFunctionInference1.ts, 60, 43))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 21))
|
||||
>u : Symbol(u, Decl(genericFunctionInference1.ts, 60, 50))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 60, 23))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 21))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 60, 23))
|
||||
|
||||
let f60 = wrap3(baz);
|
||||
>f60 : Symbol(f60, Decl(genericFunctionInference1.ts, 62, 3))
|
||||
>wrap3 : Symbol(wrap3, Decl(genericFunctionInference1.ts, 57, 24))
|
||||
>baz : Symbol(baz, Decl(genericFunctionInference1.ts, 59, 89))
|
||||
|
||||
// #417
|
||||
|
||||
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
|
||||
>mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 57, 24))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 61, 16))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 61, 18))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 61, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 61, 26))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 61, 16))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 61, 18))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 61, 40))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 61, 16))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 61, 18))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 61, 22))
|
||||
>mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 62, 21))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 66, 16))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 66, 18))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 66, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 66, 26))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 66, 16))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 66, 18))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 66, 40))
|
||||
>A : Symbol(A, Decl(genericFunctionInference1.ts, 66, 16))
|
||||
>B : Symbol(B, Decl(genericFunctionInference1.ts, 66, 18))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 66, 22))
|
||||
|
||||
var identityM = mirror(identity);
|
||||
>identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 62, 3))
|
||||
>mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 57, 24))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 67, 3))
|
||||
>mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 62, 21))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
var x = 1;
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 64, 3))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 69, 3))
|
||||
|
||||
var y = identity(x);
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 65, 3))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 64, 3))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 70, 3))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 69, 3))
|
||||
|
||||
var z = identityM(x);
|
||||
>z : Symbol(z, Decl(genericFunctionInference1.ts, 66, 3))
|
||||
>identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 62, 3))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 64, 3))
|
||||
>z : Symbol(z, Decl(genericFunctionInference1.ts, 71, 3))
|
||||
>identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 67, 3))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 69, 3))
|
||||
|
||||
// #3038
|
||||
|
||||
export function keyOf<a>(value: { key: a; }): a {
|
||||
>keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 66, 21))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 70, 22))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 70, 25))
|
||||
>key : Symbol(key, Decl(genericFunctionInference1.ts, 70, 33))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 70, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 70, 22))
|
||||
>keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 71, 21))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 75, 22))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 75, 25))
|
||||
>key : Symbol(key, Decl(genericFunctionInference1.ts, 75, 33))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 75, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 75, 22))
|
||||
|
||||
return value.key;
|
||||
>value.key : Symbol(key, Decl(genericFunctionInference1.ts, 70, 33))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 70, 25))
|
||||
>key : Symbol(key, Decl(genericFunctionInference1.ts, 70, 33))
|
||||
>value.key : Symbol(key, Decl(genericFunctionInference1.ts, 75, 33))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 75, 25))
|
||||
>key : Symbol(key, Decl(genericFunctionInference1.ts, 75, 33))
|
||||
}
|
||||
export interface Data {
|
||||
>Data : Symbol(Data, Decl(genericFunctionInference1.ts, 72, 1))
|
||||
>Data : Symbol(Data, Decl(genericFunctionInference1.ts, 77, 1))
|
||||
|
||||
key: number;
|
||||
>key : Symbol(Data.key, Decl(genericFunctionInference1.ts, 73, 23))
|
||||
>key : Symbol(Data.key, Decl(genericFunctionInference1.ts, 78, 23))
|
||||
|
||||
value: Date;
|
||||
>value : Symbol(Data.value, Decl(genericFunctionInference1.ts, 74, 16))
|
||||
>value : Symbol(Data.value, Decl(genericFunctionInference1.ts, 79, 16))
|
||||
>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
|
||||
}
|
||||
|
||||
var data: Data[] = [];
|
||||
>data : Symbol(data, Decl(genericFunctionInference1.ts, 78, 3))
|
||||
>Data : Symbol(Data, Decl(genericFunctionInference1.ts, 72, 1))
|
||||
>data : Symbol(data, Decl(genericFunctionInference1.ts, 83, 3))
|
||||
>Data : Symbol(Data, Decl(genericFunctionInference1.ts, 77, 1))
|
||||
|
||||
declare function toKeys<a>(values: a[], toKey: (value: a) => string): string[];
|
||||
>toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 78, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 80, 24))
|
||||
>values : Symbol(values, Decl(genericFunctionInference1.ts, 80, 27))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 80, 24))
|
||||
>toKey : Symbol(toKey, Decl(genericFunctionInference1.ts, 80, 39))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 80, 48))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 80, 24))
|
||||
>toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 83, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 85, 24))
|
||||
>values : Symbol(values, Decl(genericFunctionInference1.ts, 85, 27))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 85, 24))
|
||||
>toKey : Symbol(toKey, Decl(genericFunctionInference1.ts, 85, 39))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 85, 48))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 85, 24))
|
||||
|
||||
toKeys(data, keyOf); // Error
|
||||
>toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 78, 22))
|
||||
>data : Symbol(data, Decl(genericFunctionInference1.ts, 78, 3))
|
||||
>keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 66, 21))
|
||||
>toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 83, 22))
|
||||
>data : Symbol(data, Decl(genericFunctionInference1.ts, 83, 3))
|
||||
>keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 71, 21))
|
||||
|
||||
// #9366
|
||||
|
||||
function flip<a, b, c>(f: (a: a, b: b) => c): (b: b, a: a) => c {
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 82, 20))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 86, 14))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 86, 16))
|
||||
>c : Symbol(c, Decl(genericFunctionInference1.ts, 86, 19))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 86, 23))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 86, 27))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 86, 14))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 86, 32))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 86, 16))
|
||||
>c : Symbol(c, Decl(genericFunctionInference1.ts, 86, 19))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 86, 47))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 86, 16))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 86, 52))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 86, 14))
|
||||
>c : Symbol(c, Decl(genericFunctionInference1.ts, 86, 19))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16))
|
||||
>c : Symbol(c, Decl(genericFunctionInference1.ts, 91, 19))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 91, 23))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 27))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 32))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16))
|
||||
>c : Symbol(c, Decl(genericFunctionInference1.ts, 91, 19))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 47))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 52))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14))
|
||||
>c : Symbol(c, Decl(genericFunctionInference1.ts, 91, 19))
|
||||
|
||||
return (b: b, a: a) => f(a, b);
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 87, 10))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 86, 16))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 87, 15))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 86, 14))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 86, 23))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 87, 15))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 87, 10))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 92, 10))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 92, 15))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14))
|
||||
>f : Symbol(f, Decl(genericFunctionInference1.ts, 91, 23))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 92, 15))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 92, 10))
|
||||
}
|
||||
function zip<T, U>(x: T, y: U): [T, U] {
|
||||
>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 88, 1))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 89, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 89, 15))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 89, 19))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 89, 13))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 89, 24))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 89, 15))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 89, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 89, 15))
|
||||
>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 93, 1))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 94, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 94, 15))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 94, 19))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 94, 13))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 94, 24))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 94, 15))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 94, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 94, 15))
|
||||
|
||||
return [x, y];
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 89, 19))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 89, 24))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 94, 19))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 94, 24))
|
||||
}
|
||||
|
||||
var expected: <T, U>(y: U, x: T) => [T, U] = flip(zip);
|
||||
>expected : Symbol(expected, Decl(genericFunctionInference1.ts, 93, 3))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 93, 15))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 93, 17))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 93, 21))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 93, 17))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 93, 26))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 93, 15))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 93, 15))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 93, 17))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 82, 20))
|
||||
>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 88, 1))
|
||||
>expected : Symbol(expected, Decl(genericFunctionInference1.ts, 98, 3))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 15))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 17))
|
||||
>y : Symbol(y, Decl(genericFunctionInference1.ts, 98, 21))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 17))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 98, 26))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 15))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 15))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 17))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20))
|
||||
>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 93, 1))
|
||||
|
||||
var actual = flip(zip);
|
||||
>actual : Symbol(actual, Decl(genericFunctionInference1.ts, 94, 3))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 82, 20))
|
||||
>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 88, 1))
|
||||
>actual : Symbol(actual, Decl(genericFunctionInference1.ts, 99, 3))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20))
|
||||
>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 93, 1))
|
||||
|
||||
// #9366
|
||||
|
||||
const map = <T, U>(transform: (t: T) => U) =>
|
||||
>map : Symbol(map, Decl(genericFunctionInference1.ts, 98, 5))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 15))
|
||||
>transform : Symbol(transform, Decl(genericFunctionInference1.ts, 98, 19))
|
||||
>t : Symbol(t, Decl(genericFunctionInference1.ts, 98, 31))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 15))
|
||||
>map : Symbol(map, Decl(genericFunctionInference1.ts, 103, 5))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 103, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 103, 15))
|
||||
>transform : Symbol(transform, Decl(genericFunctionInference1.ts, 103, 19))
|
||||
>t : Symbol(t, Decl(genericFunctionInference1.ts, 103, 31))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 103, 13))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 103, 15))
|
||||
|
||||
(arr: T[]) => arr.map(transform)
|
||||
>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 99, 5))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 13))
|
||||
>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 104, 5))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 103, 13))
|
||||
>arr.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
|
||||
>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 99, 5))
|
||||
>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 104, 5))
|
||||
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
|
||||
>transform : Symbol(transform, Decl(genericFunctionInference1.ts, 98, 19))
|
||||
>transform : Symbol(transform, Decl(genericFunctionInference1.ts, 103, 19))
|
||||
|
||||
const identityStr = (t: string) => t;
|
||||
>identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 101, 5))
|
||||
>t : Symbol(t, Decl(genericFunctionInference1.ts, 101, 21))
|
||||
>t : Symbol(t, Decl(genericFunctionInference1.ts, 101, 21))
|
||||
>identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 106, 5))
|
||||
>t : Symbol(t, Decl(genericFunctionInference1.ts, 106, 21))
|
||||
>t : Symbol(t, Decl(genericFunctionInference1.ts, 106, 21))
|
||||
|
||||
const arr: string[] = map(identityStr)(['a']);
|
||||
>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 103, 5))
|
||||
>map : Symbol(map, Decl(genericFunctionInference1.ts, 98, 5))
|
||||
>identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 101, 5))
|
||||
>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 108, 5))
|
||||
>map : Symbol(map, Decl(genericFunctionInference1.ts, 103, 5))
|
||||
>identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 106, 5))
|
||||
|
||||
const arr1: string[] = map(identity)(['a']);
|
||||
>arr1 : Symbol(arr1, Decl(genericFunctionInference1.ts, 104, 5))
|
||||
>map : Symbol(map, Decl(genericFunctionInference1.ts, 98, 5))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>arr1 : Symbol(arr1, Decl(genericFunctionInference1.ts, 109, 5))
|
||||
>map : Symbol(map, Decl(genericFunctionInference1.ts, 103, 5))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
// #9949
|
||||
|
||||
function of2<a, b>(one: a, two: b): [a, b] {
|
||||
>of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 104, 44))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 108, 13))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 108, 15))
|
||||
>one : Symbol(one, Decl(genericFunctionInference1.ts, 108, 19))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 108, 13))
|
||||
>two : Symbol(two, Decl(genericFunctionInference1.ts, 108, 26))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 108, 15))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 108, 13))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 108, 15))
|
||||
>of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 109, 44))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 13))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 113, 15))
|
||||
>one : Symbol(one, Decl(genericFunctionInference1.ts, 113, 19))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 13))
|
||||
>two : Symbol(two, Decl(genericFunctionInference1.ts, 113, 26))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 113, 15))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 13))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 113, 15))
|
||||
|
||||
return [one, two];
|
||||
>one : Symbol(one, Decl(genericFunctionInference1.ts, 108, 19))
|
||||
>two : Symbol(two, Decl(genericFunctionInference1.ts, 108, 26))
|
||||
>one : Symbol(one, Decl(genericFunctionInference1.ts, 113, 19))
|
||||
>two : Symbol(two, Decl(genericFunctionInference1.ts, 113, 26))
|
||||
}
|
||||
|
||||
const flipped = flip(of2);
|
||||
>flipped : Symbol(flipped, Decl(genericFunctionInference1.ts, 112, 5))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 82, 20))
|
||||
>of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 104, 44))
|
||||
>flipped : Symbol(flipped, Decl(genericFunctionInference1.ts, 117, 5))
|
||||
>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20))
|
||||
>of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 109, 44))
|
||||
|
||||
// #29904.1
|
||||
|
||||
type Component<P> = (props: P) => {};
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 112, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 116, 15))
|
||||
>props : Symbol(props, Decl(genericFunctionInference1.ts, 116, 21))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 116, 15))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 121, 15))
|
||||
>props : Symbol(props, Decl(genericFunctionInference1.ts, 121, 21))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 121, 15))
|
||||
|
||||
declare const myHoc1: <P>(C: Component<P>) => Component<P>;
|
||||
>myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 118, 13))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 118, 23))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 118, 26))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 112, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 118, 23))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 112, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 118, 23))
|
||||
>myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 123, 13))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 123, 23))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 123, 26))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 123, 23))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 123, 23))
|
||||
|
||||
declare const myHoc2: <P>(C: Component<P>) => Component<P>;
|
||||
>myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 119, 13))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 119, 23))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 119, 26))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 112, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 119, 23))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 112, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 119, 23))
|
||||
>myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 124, 13))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 124, 23))
|
||||
>C : Symbol(C, Decl(genericFunctionInference1.ts, 124, 26))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 124, 23))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26))
|
||||
>P : Symbol(P, Decl(genericFunctionInference1.ts, 124, 23))
|
||||
|
||||
declare const MyComponent1: Component<{ foo: 1 }>;
|
||||
>MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 121, 13))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 112, 26))
|
||||
>foo : Symbol(foo, Decl(genericFunctionInference1.ts, 121, 39))
|
||||
>MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 126, 13))
|
||||
>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26))
|
||||
>foo : Symbol(foo, Decl(genericFunctionInference1.ts, 126, 39))
|
||||
|
||||
const enhance = pipe(
|
||||
>enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 123, 5))
|
||||
>enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 128, 5))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
myHoc1,
|
||||
>myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 118, 13))
|
||||
>myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 123, 13))
|
||||
|
||||
myHoc2,
|
||||
>myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 119, 13))
|
||||
>myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 124, 13))
|
||||
|
||||
);
|
||||
|
||||
const MyComponent2 = enhance(MyComponent1);
|
||||
>MyComponent2 : Symbol(MyComponent2, Decl(genericFunctionInference1.ts, 128, 5))
|
||||
>enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 123, 5))
|
||||
>MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 121, 13))
|
||||
>MyComponent2 : Symbol(MyComponent2, Decl(genericFunctionInference1.ts, 133, 5))
|
||||
>enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 128, 5))
|
||||
>MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 126, 13))
|
||||
|
||||
// #29904.2
|
||||
|
||||
const fn20 = pipe((_a?: {}) => 1);
|
||||
>fn20 : Symbol(fn20, Decl(genericFunctionInference1.ts, 132, 5))
|
||||
>fn20 : Symbol(fn20, Decl(genericFunctionInference1.ts, 137, 5))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
>_a : Symbol(_a, Decl(genericFunctionInference1.ts, 132, 19))
|
||||
>_a : Symbol(_a, Decl(genericFunctionInference1.ts, 137, 19))
|
||||
|
||||
// #29904.3
|
||||
|
||||
type Fn = (n: number) => number;
|
||||
>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 132, 34))
|
||||
>n : Symbol(n, Decl(genericFunctionInference1.ts, 136, 11))
|
||||
>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 137, 34))
|
||||
>n : Symbol(n, Decl(genericFunctionInference1.ts, 141, 11))
|
||||
|
||||
const fn30: Fn = pipe(
|
||||
>fn30 : Symbol(fn30, Decl(genericFunctionInference1.ts, 137, 5))
|
||||
>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 132, 34))
|
||||
>fn30 : Symbol(fn30, Decl(genericFunctionInference1.ts, 142, 5))
|
||||
>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 137, 34))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
x => x + 1,
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 137, 22))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 137, 22))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 142, 22))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 142, 22))
|
||||
|
||||
x => x * 2,
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 138, 15))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 138, 15))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 143, 15))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 143, 15))
|
||||
|
||||
);
|
||||
|
||||
const promise = Promise.resolve(1);
|
||||
>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 142, 5))
|
||||
>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 147, 5))
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
|
||||
promise.then(
|
||||
>promise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
|
||||
>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 142, 5))
|
||||
>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 147, 5))
|
||||
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
pipe(
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
x => x + 1,
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 144, 9))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 144, 9))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 149, 9))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 149, 9))
|
||||
|
||||
x => x * 2,
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 145, 19))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 145, 19))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 150, 19))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 150, 19))
|
||||
|
||||
),
|
||||
);
|
||||
|
@ -757,121 +797,137 @@ promise.then(
|
|||
// #29904.4
|
||||
|
||||
declare const getString: () => string;
|
||||
>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 152, 13))
|
||||
>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 157, 13))
|
||||
|
||||
declare const orUndefined: (name: string) => string | undefined;
|
||||
>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 153, 13))
|
||||
>name : Symbol(name, Decl(genericFunctionInference1.ts, 153, 28))
|
||||
>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 158, 13))
|
||||
>name : Symbol(name, Decl(genericFunctionInference1.ts, 158, 28))
|
||||
|
||||
declare const identity: <T>(value: T) => T;
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 154, 25))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 154, 28))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 154, 25))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 154, 25))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 159, 25))
|
||||
>value : Symbol(value, Decl(genericFunctionInference1.ts, 159, 28))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 159, 25))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 159, 25))
|
||||
|
||||
const fn40 = pipe(
|
||||
>fn40 : Symbol(fn40, Decl(genericFunctionInference1.ts, 156, 5))
|
||||
>fn40 : Symbol(fn40, Decl(genericFunctionInference1.ts, 161, 5))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
getString,
|
||||
>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 152, 13))
|
||||
>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 157, 13))
|
||||
|
||||
string => orUndefined(string),
|
||||
>string : Symbol(string, Decl(genericFunctionInference1.ts, 157, 14))
|
||||
>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 153, 13))
|
||||
>string : Symbol(string, Decl(genericFunctionInference1.ts, 157, 14))
|
||||
>string : Symbol(string, Decl(genericFunctionInference1.ts, 162, 14))
|
||||
>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 158, 13))
|
||||
>string : Symbol(string, Decl(genericFunctionInference1.ts, 162, 14))
|
||||
|
||||
identity,
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
);
|
||||
|
||||
// #29904.6
|
||||
|
||||
declare const getArray: () => string[];
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 164, 13))
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13))
|
||||
|
||||
declare const first: <T>(ts: T[]) => T;
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 165, 13))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 165, 22))
|
||||
>ts : Symbol(ts, Decl(genericFunctionInference1.ts, 165, 25))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 165, 22))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 165, 22))
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 170, 22))
|
||||
>ts : Symbol(ts, Decl(genericFunctionInference1.ts, 170, 25))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 170, 22))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 170, 22))
|
||||
|
||||
const fn60 = pipe(
|
||||
>fn60 : Symbol(fn60, Decl(genericFunctionInference1.ts, 167, 5))
|
||||
>fn60 : Symbol(fn60, Decl(genericFunctionInference1.ts, 172, 5))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
getArray,
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 164, 13))
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13))
|
||||
|
||||
x => x,
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 168, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 168, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 173, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 173, 13))
|
||||
|
||||
first,
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 165, 13))
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13))
|
||||
|
||||
);
|
||||
|
||||
const fn61 = pipe(
|
||||
>fn61 : Symbol(fn61, Decl(genericFunctionInference1.ts, 173, 5))
|
||||
>fn61 : Symbol(fn61, Decl(genericFunctionInference1.ts, 178, 5))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
getArray,
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 164, 13))
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13))
|
||||
|
||||
identity,
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
first,
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 165, 13))
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13))
|
||||
|
||||
);
|
||||
|
||||
const fn62 = pipe(
|
||||
>fn62 : Symbol(fn62, Decl(genericFunctionInference1.ts, 179, 5))
|
||||
>fn62 : Symbol(fn62, Decl(genericFunctionInference1.ts, 184, 5))
|
||||
>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104))
|
||||
|
||||
getArray,
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 164, 13))
|
||||
>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13))
|
||||
|
||||
x => x,
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 180, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 180, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 185, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 185, 13))
|
||||
|
||||
x => first(x),
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 181, 11))
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 165, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 181, 11))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 186, 11))
|
||||
>first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13))
|
||||
>x : Symbol(x, Decl(genericFunctionInference1.ts, 186, 11))
|
||||
|
||||
);
|
||||
|
||||
// Repro from #30297
|
||||
|
||||
declare function foo2<T, U = T>(fn: T, a?: U, b?: U): [T, U];
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 183, 2))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 187, 22))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 187, 24))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 187, 22))
|
||||
>fn : Symbol(fn, Decl(genericFunctionInference1.ts, 187, 32))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 187, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 187, 38))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 187, 24))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 187, 45))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 187, 24))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 187, 22))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 187, 24))
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22))
|
||||
>fn : Symbol(fn, Decl(genericFunctionInference1.ts, 192, 32))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22))
|
||||
>a : Symbol(a, Decl(genericFunctionInference1.ts, 192, 38))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24))
|
||||
>b : Symbol(b, Decl(genericFunctionInference1.ts, 192, 45))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22))
|
||||
>U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24))
|
||||
|
||||
foo2(() => {});
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 183, 2))
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2))
|
||||
|
||||
foo2(identity);
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 183, 2))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
foo2(identity, 1);
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 183, 2))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 154, 13))
|
||||
>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
// Repro from #30324
|
||||
|
||||
declare function times<T>(fn: (i: number) => T): (n: number) => T[];
|
||||
>times : Symbol(times, Decl(genericFunctionInference1.ts, 196, 18))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 200, 23))
|
||||
>fn : Symbol(fn, Decl(genericFunctionInference1.ts, 200, 26))
|
||||
>i : Symbol(i, Decl(genericFunctionInference1.ts, 200, 31))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 200, 23))
|
||||
>n : Symbol(n, Decl(genericFunctionInference1.ts, 200, 50))
|
||||
>T : Symbol(T, Decl(genericFunctionInference1.ts, 200, 23))
|
||||
|
||||
const a2 = times(identity)(5); // => [0, 1, 2, 3, 4]
|
||||
>a2 : Symbol(a2, Decl(genericFunctionInference1.ts, 201, 5))
|
||||
>times : Symbol(times, Decl(genericFunctionInference1.ts, 196, 18))
|
||||
>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13))
|
||||
|
||||
|
|
|
@ -421,6 +421,28 @@ const f50 = pipe5(list); // No higher order inference
|
|||
>pipe5 : <A, B>(f: (a: A) => B) => { f: (a: A) => B; }
|
||||
>list : <T>(a: T) => T[]
|
||||
|
||||
declare function wrap3<A, B, C>(f: (a: A, b1: B, b2: B) => C): (a: A, b1: B, b2: B) => C;
|
||||
>wrap3 : <A, B, C>(f: (a: A, b1: B, b2: B) => C) => (a: A, b1: B, b2: B) => C
|
||||
>f : (a: A, b1: B, b2: B) => C
|
||||
>a : A
|
||||
>b1 : B
|
||||
>b2 : B
|
||||
>a : A
|
||||
>b1 : B
|
||||
>b2 : B
|
||||
|
||||
declare function baz<T, U extends T>(t1: T, t2: T, u: U): [T, U];
|
||||
>baz : <T, U extends T>(t1: T, t2: T, u: U) => [T, U]
|
||||
>t1 : T
|
||||
>t2 : T
|
||||
>u : U
|
||||
|
||||
let f60 = wrap3(baz);
|
||||
>f60 : <T, U extends T>(a: T, b1: U, b2: U) => [T, U]
|
||||
>wrap3(baz) : <T, U extends T>(a: T, b1: U, b2: U) => [T, U]
|
||||
>wrap3 : <A, B, C>(f: (a: A, b1: B, b2: B) => C) => (a: A, b1: B, b2: B) => C
|
||||
>baz : <T, U extends T>(t1: T, t2: T, u: U) => [T, U]
|
||||
|
||||
// #417
|
||||
|
||||
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
|
||||
|
@ -823,3 +845,19 @@ foo2(identity, 1);
|
|||
>identity : <T>(value: T) => T
|
||||
>1 : 1
|
||||
|
||||
// Repro from #30324
|
||||
|
||||
declare function times<T>(fn: (i: number) => T): (n: number) => T[];
|
||||
>times : <T>(fn: (i: number) => T) => (n: number) => T[]
|
||||
>fn : (i: number) => T
|
||||
>i : number
|
||||
>n : number
|
||||
|
||||
const a2 = times(identity)(5); // => [0, 1, 2, 3, 4]
|
||||
>a2 : number[]
|
||||
>times(identity)(5) : number[]
|
||||
>times(identity) : (n: number) => number[]
|
||||
>times : <T>(fn: (i: number) => T) => (n: number) => T[]
|
||||
>identity : <T>(value: T) => T
|
||||
>5 : 5
|
||||
|
||||
|
|
27
tests/cases/compiler/contravariantInferenceAndTypeGuard.ts
Normal file
27
tests/cases/compiler/contravariantInferenceAndTypeGuard.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
// @strict: true
|
||||
interface ListItem<TData> {
|
||||
prev: ListItem<TData> | null;
|
||||
next: ListItem<TData> | null;
|
||||
data: TData;
|
||||
}
|
||||
type IteratorFn<TData, TResult, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => TResult;
|
||||
type FilterFn<TData, TResult extends TData, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => item is TResult;
|
||||
|
||||
declare class List<TData> {
|
||||
filter<TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>;
|
||||
filter<TResult extends TData>(fn: FilterFn<TData, TResult>): List<TResult>;
|
||||
filter<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>;
|
||||
filter(fn: IteratorFn<TData, boolean>): List<TData>;
|
||||
}
|
||||
interface Test {
|
||||
a: string;
|
||||
}
|
||||
const list2 = new List<Test | null>();
|
||||
const filter1 = list2.filter(function(item, node, list): item is Test {
|
||||
this.b; // $ExpectType string
|
||||
item; // $ExpectType Test | null
|
||||
node; // $ExpectType ListItem<Test | null>
|
||||
list; // $ExpectType List<Test | null>
|
||||
return !!item;
|
||||
}, {b: 'c'});
|
||||
const x: List<Test> = filter1; // $ExpectType List<Test>
|
|
@ -60,6 +60,11 @@ declare function pipe5<A, B>(f: (a: A) => B): { f: (a: A) => B };
|
|||
|
||||
const f50 = pipe5(list); // No higher order inference
|
||||
|
||||
declare function wrap3<A, B, C>(f: (a: A, b1: B, b2: B) => C): (a: A, b1: B, b2: B) => C;
|
||||
declare function baz<T, U extends T>(t1: T, t2: T, u: U): [T, U];
|
||||
|
||||
let f60 = wrap3(baz);
|
||||
|
||||
// #417
|
||||
|
||||
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
|
||||
|
@ -193,3 +198,8 @@ declare function foo2<T, U = T>(fn: T, a?: U, b?: U): [T, U];
|
|||
foo2(() => {});
|
||||
foo2(identity);
|
||||
foo2(identity, 1);
|
||||
|
||||
// Repro from #30324
|
||||
|
||||
declare function times<T>(fn: (i: number) => T): (n: number) => T[];
|
||||
const a2 = times(identity)(5); // => [0, 1, 2, 3, 4]
|
||||
|
|
Loading…
Reference in a new issue