Skip to content

Add additional tests for intra expression inference #48584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2022
Merged
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
29 changes: 26 additions & 3 deletions tests/baselines/reference/intraExpressionInferences.errors.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts(123,5): error TS2322: Type '(inputs: Unwrap<{ num: Wrapper<number>; str: Wrapper<string>; }>) => { bool: any; str: number; }' is not assignable to type '(inputs: Unwrap<{ num: Wrapper<number>; str: Wrapper<string>; }>) => Unwrap<{ bool: Wrapper<boolean>; str: Wrapper<string>; }>'.
tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts(131,5): error TS2322: Type '(inputs: Unwrap<{ num: Wrapper<number>; str: Wrapper<string>; }>) => { bool: any; str: number; }' is not assignable to type '(inputs: Unwrap<{ num: Wrapper<number>; str: Wrapper<string>; }>) => Unwrap<{ bool: Wrapper<boolean>; str: Wrapper<string>; }>'.
Call signature return types '{ bool: any; str: number; }' and 'Unwrap<{ bool: Wrapper<boolean>; str: Wrapper<string>; }>' are incompatible.
The types of 'str' are incompatible between these types.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts(125,26): error TS2339: Property 'nonexistent' does not exist on type 'Unwrap<{ num: Wrapper<number>; str: Wrapper<string>; }>'.
tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts(133,26): error TS2339: Property 'nonexistent' does not exist on type 'Unwrap<{ num: Wrapper<number>; str: Wrapper<string>; }>'.


==== tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts (2 errors) ====
Expand Down Expand Up @@ -97,6 +97,14 @@ tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInf
}
});

test({
a: () => 0,
b: (a) => a,
c: (b) => {
const x: number = b;
}
});

// Repro from #41712

class Wrapper<T = any> {
Expand Down Expand Up @@ -134,7 +142,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInf
!!! error TS2322: Call signature return types '{ bool: any; str: number; }' and 'Unwrap<{ bool: Wrapper<boolean>; str: Wrapper<string>; }>' are incompatible.
!!! error TS2322: The types of 'str' are incompatible between these types.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
!!! related TS6500 tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts:105:5: The expected type comes from property 'map' which is declared here on type 'MappingComponent<{ num: Wrapper<number>; str: Wrapper<string>; }, { bool: Wrapper<boolean>; str: Wrapper<string>; }>'
!!! related TS6500 tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts:113:5: The expected type comes from property 'map' which is declared here on type 'MappingComponent<{ num: Wrapper<number>; str: Wrapper<string>; }, { bool: Wrapper<boolean>; str: Wrapper<string>; }>'
return {
bool: inputs.nonexistent,
~~~~~~~~~~~
Expand Down Expand Up @@ -189,4 +197,19 @@ tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInf
fetch: (params: Params, foo) => 123,
map: (number) => String(number)
});

// Repro from #45255

declare const branch:
<T, U extends T>(_: { test: T, if: (t: T) => t is U, then: (u: U) => void }) => void

declare const x: "a" | "b"

branch({
test: x,
if: (t): t is "a" => t === "a",
then: u => {
let test1: "a" = u
}
})

43 changes: 43 additions & 0 deletions tests/baselines/reference/intraExpressionInferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ test({
}
});

test({
a: () => 0,
b: (a) => a,
c: (b) => {
const x: number = b;
}
});

// Repro from #41712

class Wrapper<T = any> {
Expand Down Expand Up @@ -174,6 +182,21 @@ example({
fetch: (params: Params, foo) => 123,
map: (number) => String(number)
});

// Repro from #45255

declare const branch:
<T, U extends T>(_: { test: T, if: (t: T) => t is U, then: (u: U) => void }) => void

declare const x: "a" | "b"

branch({
test: x,
if: (t): t is "a" => t === "a",
then: u => {
let test1: "a" = u
}
})


//// [intraExpressionInferences.js]
Expand Down Expand Up @@ -228,6 +251,13 @@ test({
var x = b;
}
});
test({
a: function () { return 0; },
b: function (a) { return a; },
c: function (b) {
var x = b;
}
});
// Repro from #41712
var Wrapper = /** @class */ (function () {
function Wrapper() {
Expand Down Expand Up @@ -279,6 +309,13 @@ example({
fetch: function (params, foo) { return 123; },
map: function (number) { return String(number); }
});
branch({
test: x,
"if": function (t) { return t === "a"; },
then: function (u) {
var test1 = u;
}
});


//// [intraExpressionInferences.d.ts]
Expand Down Expand Up @@ -340,3 +377,9 @@ interface Params {
one: number;
two: string;
}
declare const branch: <T, U extends T>(_: {
test: T;
if: (t: T) => t is U;
then: (u: U) => void;
}) => void;
declare const x: "a" | "b";
Loading