Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19053,7 +19053,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (newConstraint.flags & TypeFlags.AnyOrUnknown || isTypeAssignableTo(getRestrictiveInstantiation(newBaseType), getRestrictiveInstantiation(newConstraint))) {
return newBaseType;
}
return newBaseType.flags & TypeFlags.TypeVariable ? getSubstitutionType(newBaseType, newConstraint) : getIntersectionType([newConstraint, newBaseType]);
return (newBaseType.flags & TypeFlags.TypeVariable || newConstraint.flags & TypeFlags.TypeVariable) ? getSubstitutionType(newBaseType, newConstraint) : getIntersectionType([newConstraint, newBaseType]);
}
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ function fn2<T>(arg: Q2<T>) {
arg(arg => useT(arg));
>arg(arg => useT(arg)) : void
>arg : Q2<T>
>arg => useT(arg) : (arg: T & number) => void
>arg : T & number
>arg => useT(arg) : (arg: number) => void
>arg : number
>useT(arg) : void
>useT : (_arg: T) => void
>arg : T & number
>arg : number
}
// Legal invocations are not problematic
fn2<string | number>(m => m(42));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//// [conditionalSubstitutionInferencesLowerPriority.ts]
type TestType<Keys extends string> = string extends Keys ? Record<Keys, string> : Record<Keys, string>

function inferHelper<Keys extends string>(data: TestType<Keys>) {
return data;
}

export const a = inferHelper({
// key1 is inferred to be value1 here
key1: "value1"
})

//// [conditionalSubstitutionInferencesLowerPriority.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
function inferHelper(data) {
return data;
}
exports.a = inferHelper({
// key1 is inferred to be value1 here
key1: "value1"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/compiler/conditionalSubstitutionInferencesLowerPriority.ts ===
type TestType<Keys extends string> = string extends Keys ? Record<Keys, string> : Record<Keys, string>
>TestType : Symbol(TestType, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 0))
>Keys : Symbol(Keys, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 14))
>Keys : Symbol(Keys, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 14))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>Keys : Symbol(Keys, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 14))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>Keys : Symbol(Keys, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 14))

function inferHelper<Keys extends string>(data: TestType<Keys>) {
>inferHelper : Symbol(inferHelper, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 102))
>Keys : Symbol(Keys, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 2, 21))
>data : Symbol(data, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 2, 42))
>TestType : Symbol(TestType, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 0))
>Keys : Symbol(Keys, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 2, 21))

return data;
>data : Symbol(data, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 2, 42))
}

export const a = inferHelper({
>a : Symbol(a, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 6, 12))
>inferHelper : Symbol(inferHelper, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 0, 102))

// key1 is inferred to be value1 here
key1: "value1"
>key1 : Symbol(key1, Decl(conditionalSubstitutionInferencesLowerPriority.ts, 6, 30))

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/conditionalSubstitutionInferencesLowerPriority.ts ===
type TestType<Keys extends string> = string extends Keys ? Record<Keys, string> : Record<Keys, string>
>TestType : TestType<Keys>

function inferHelper<Keys extends string>(data: TestType<Keys>) {
>inferHelper : <Keys extends string>(data: TestType<Keys>) => TestType<Keys>
>data : TestType<Keys>

return data;
>data : TestType<Keys>
}

export const a = inferHelper({
>a : Record<"key1", string>
>inferHelper({ // key1 is inferred to be value1 here key1: "value1"}) : Record<"key1", string>
>inferHelper : <Keys extends string>(data: TestType<Keys>) => TestType<Keys>
>{ // key1 is inferred to be value1 here key1: "value1"} : { key1: string; }

// key1 is inferred to be value1 here
key1: "value1"
>key1 : string
>"value1" : "value1"

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type TestType<Keys extends string> = string extends Keys ? Record<Keys, string> : Record<Keys, string>

function inferHelper<Keys extends string>(data: TestType<Keys>) {
return data;
}

export const a = inferHelper({
// key1 is inferred to be value1 here
key1: "value1"
})