mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #21292 from Microsoft/fixReverseMappedContravariantInference
Fix reverse mapped contravariant inference
This commit is contained in:
@@ -11029,7 +11029,9 @@ namespace ts {
|
||||
const templateType = getTemplateTypeFromMappedType(target);
|
||||
const inference = createInferenceInfo(typeParameter);
|
||||
inferTypes([inference], sourceType, templateType);
|
||||
return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) : emptyObjectType;
|
||||
return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) :
|
||||
inference.contraCandidates ? getCommonSubtype(inference.contraCandidates) :
|
||||
emptyObjectType;
|
||||
}
|
||||
|
||||
function getUnmatchedProperty(source: Type, target: Type, requireOptionalProperties: boolean) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//// [reverseMappedContravariantInference.ts]
|
||||
// Repro from #21273
|
||||
|
||||
declare function conforms<T>(source: { [K in keyof T]: (val: T[K]) => boolean }): (value: T) => boolean;
|
||||
conforms({ foo: (v: string) => false })({ foo: "hello" });
|
||||
|
||||
|
||||
//// [reverseMappedContravariantInference.js]
|
||||
"use strict";
|
||||
// Repro from #21273
|
||||
conforms({ foo: function (v) { return false; } })({ foo: "hello" });
|
||||
@@ -0,0 +1,21 @@
|
||||
=== tests/cases/compiler/reverseMappedContravariantInference.ts ===
|
||||
// Repro from #21273
|
||||
|
||||
declare function conforms<T>(source: { [K in keyof T]: (val: T[K]) => boolean }): (value: T) => boolean;
|
||||
>conforms : Symbol(conforms, Decl(reverseMappedContravariantInference.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(reverseMappedContravariantInference.ts, 2, 26))
|
||||
>source : Symbol(source, Decl(reverseMappedContravariantInference.ts, 2, 29))
|
||||
>K : Symbol(K, Decl(reverseMappedContravariantInference.ts, 2, 40))
|
||||
>T : Symbol(T, Decl(reverseMappedContravariantInference.ts, 2, 26))
|
||||
>val : Symbol(val, Decl(reverseMappedContravariantInference.ts, 2, 56))
|
||||
>T : Symbol(T, Decl(reverseMappedContravariantInference.ts, 2, 26))
|
||||
>K : Symbol(K, Decl(reverseMappedContravariantInference.ts, 2, 40))
|
||||
>value : Symbol(value, Decl(reverseMappedContravariantInference.ts, 2, 83))
|
||||
>T : Symbol(T, Decl(reverseMappedContravariantInference.ts, 2, 26))
|
||||
|
||||
conforms({ foo: (v: string) => false })({ foo: "hello" });
|
||||
>conforms : Symbol(conforms, Decl(reverseMappedContravariantInference.ts, 0, 0))
|
||||
>foo : Symbol(foo, Decl(reverseMappedContravariantInference.ts, 3, 10))
|
||||
>v : Symbol(v, Decl(reverseMappedContravariantInference.ts, 3, 17))
|
||||
>foo : Symbol(foo, Decl(reverseMappedContravariantInference.ts, 3, 41))
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
=== tests/cases/compiler/reverseMappedContravariantInference.ts ===
|
||||
// Repro from #21273
|
||||
|
||||
declare function conforms<T>(source: { [K in keyof T]: (val: T[K]) => boolean }): (value: T) => boolean;
|
||||
>conforms : <T>(source: { [K in keyof T]: (val: T[K]) => boolean; }) => (value: T) => boolean
|
||||
>T : T
|
||||
>source : { [K in keyof T]: (val: T[K]) => boolean; }
|
||||
>K : K
|
||||
>T : T
|
||||
>val : T[K]
|
||||
>T : T
|
||||
>K : K
|
||||
>value : T
|
||||
>T : T
|
||||
|
||||
conforms({ foo: (v: string) => false })({ foo: "hello" });
|
||||
>conforms({ foo: (v: string) => false })({ foo: "hello" }) : boolean
|
||||
>conforms({ foo: (v: string) => false }) : (value: { foo: any; }) => boolean
|
||||
>conforms : <T>(source: { [K in keyof T]: (val: T[K]) => boolean; }) => (value: T) => boolean
|
||||
>{ foo: (v: string) => false } : { foo: (v: string) => boolean; }
|
||||
>foo : (v: string) => boolean
|
||||
>(v: string) => false : (v: string) => boolean
|
||||
>v : string
|
||||
>false : false
|
||||
>{ foo: "hello" } : { foo: string; }
|
||||
>foo : string
|
||||
>"hello" : "hello"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// @strict: true
|
||||
|
||||
// Repro from #21273
|
||||
|
||||
declare function conforms<T>(source: { [K in keyof T]: (val: T[K]) => boolean }): (value: T) => boolean;
|
||||
conforms({ foo: (v: string) => false })({ foo: "hello" });
|
||||
Reference in New Issue
Block a user