Accept error baselines
This commit is contained in:
parent
efea81b8a0
commit
4c71a7c084
|
@ -0,0 +1,47 @@
|
|||
tests/cases/conformance/controlFlow/typeGuardsTypeParameters.ts(10,13): error TS2322: Type 'C' is not assignable to type 'T'.
|
||||
tests/cases/conformance/controlFlow/typeGuardsTypeParameters.ts(20,11): error TS2339: Property 'length' does not exist on type 'never'.
|
||||
tests/cases/conformance/controlFlow/typeGuardsTypeParameters.ts(31,26): error TS2345: Argument of type 'T[keyof T]' is not assignable to parameter of type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/controlFlow/typeGuardsTypeParameters.ts (3 errors) ====
|
||||
|
||||
// Type guards involving type parameters produce intersection types
|
||||
|
||||
class C {
|
||||
prop: string;
|
||||
}
|
||||
|
||||
function f1<T>(x: T) {
|
||||
if (x instanceof C) {
|
||||
let v1: T = x;
|
||||
~~
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'T'.
|
||||
let v2: C = x;
|
||||
x.prop;
|
||||
}
|
||||
}
|
||||
|
||||
function f2<T>(x: T) {
|
||||
if (typeof x === "string") {
|
||||
let v1: T = x;
|
||||
let v2: string = x;
|
||||
x.length;
|
||||
~~~~~~
|
||||
!!! error TS2339: Property 'length' does not exist on type 'never'.
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #13872
|
||||
|
||||
function fun<T>(item: { [P in keyof T]: T[P] }) {
|
||||
const strings: string[] = [];
|
||||
for (const key in item) {
|
||||
const value = item[key];
|
||||
if (typeof value === "string") {
|
||||
strings.push(value);
|
||||
~~~~~
|
||||
!!! error TS2345: Argument of type 'T[keyof T]' is not assignable to parameter of type 'string'.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
68
tests/baselines/reference/typeGuardsTypeParameters.js
Normal file
68
tests/baselines/reference/typeGuardsTypeParameters.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
//// [typeGuardsTypeParameters.ts]
|
||||
|
||||
// Type guards involving type parameters produce intersection types
|
||||
|
||||
class C {
|
||||
prop: string;
|
||||
}
|
||||
|
||||
function f1<T>(x: T) {
|
||||
if (x instanceof C) {
|
||||
let v1: T = x;
|
||||
let v2: C = x;
|
||||
x.prop;
|
||||
}
|
||||
}
|
||||
|
||||
function f2<T>(x: T) {
|
||||
if (typeof x === "string") {
|
||||
let v1: T = x;
|
||||
let v2: string = x;
|
||||
x.length;
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #13872
|
||||
|
||||
function fun<T>(item: { [P in keyof T]: T[P] }) {
|
||||
const strings: string[] = [];
|
||||
for (const key in item) {
|
||||
const value = item[key];
|
||||
if (typeof value === "string") {
|
||||
strings.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [typeGuardsTypeParameters.js]
|
||||
// Type guards involving type parameters produce intersection types
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
}());
|
||||
function f1(x) {
|
||||
if (x instanceof C) {
|
||||
var v1 = x;
|
||||
var v2 = x;
|
||||
x.prop;
|
||||
}
|
||||
}
|
||||
function f2(x) {
|
||||
if (typeof x === "string") {
|
||||
var v1 = x;
|
||||
var v2 = x;
|
||||
x.length;
|
||||
}
|
||||
}
|
||||
// Repro from #13872
|
||||
function fun(item) {
|
||||
var strings = [];
|
||||
for (var key in item) {
|
||||
var value = item[key];
|
||||
if (typeof value === "string") {
|
||||
strings.push(value);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue