Skip to content

Commit 04b9b30

Browse files
committed
Change isTypePresencePossible, accept baseline
1 parent 069f73d commit 04b9b30

8 files changed

+595
-47
lines changed

src/compiler/checker.ts

+6-18
Original file line numberDiff line numberDiff line change
@@ -12722,30 +12722,18 @@ namespace ts {
1272212722
return type;
1272312723
}
1272412724

12725-
function isTypePresencePossible(type: Type, propName: string, shouldHaveProperty: boolean) {
12725+
function isTypePresencePossible(type: Type, propName: __String, assumeTrue: boolean) {
1272612726
const prop = getPropertyOfType(type, propName);
12727-
if (!prop) {
12728-
// if there is NO property:
12729-
// - but we assume type SHOULD have it then presence of object of following type IS NOT possible
12730-
// - and we assume type SHOULD NOT have it then presence of object of following type IS possible
12731-
return !shouldHaveProperty;
12732-
} else if (prop.flags & SymbolFlags.Optional) {
12733-
// if there is an optional property:
12734-
// - and we assume type SHOULD have it then presence of object of following type IS possible
12735-
// - but assume type SHOULD NOT have it then presence of object of following type IS still possible
12736-
return true;
12737-
} else /* if (prop.flags & SymbolFlags.Required) */ {
12738-
// if there is a required property:
12739-
// - and we assume type SHOULD have it then presence of object of following type IS possible
12740-
// - but we assume type SHOULD NOT have it then presence of object of following type IS NOT possible
12741-
return shouldHaveProperty;
12727+
if (prop) {
12728+
return (prop.flags & SymbolFlags.Optional) ? true : assumeTrue;
1274212729
}
12730+
return !assumeTrue;
1274312731
}
1274412732

1274512733
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
1274612734
if ((type.flags & (TypeFlags.Union | TypeFlags.Object)) || (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType)) {
12747-
const propName = literal.text;
12748-
return filterType(type, t => isTypePresencePossible(t, propName, /* shouldHaveProperty */ assumeTrue));
12735+
const propName = escapeLeadingUnderscores(literal.text);
12736+
return filterType(type, t => isTypePresencePossible(t, propName, /* assumeTrue */ assumeTrue));
1274912737
}
1275012738
return type;
1275112739
}

tests/baselines/reference/fixSignatureCaching.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tests/cases/conformance/fixSignatureCaching.ts(284,10): error TS2339: Property '
33
tests/cases/conformance/fixSignatureCaching.ts(293,10): error TS2339: Property 'FALLBACK_PHONE' does not exist on type '{}'.
44
tests/cases/conformance/fixSignatureCaching.ts(294,10): error TS2339: Property 'FALLBACK_TABLET' does not exist on type '{}'.
55
tests/cases/conformance/fixSignatureCaching.ts(295,10): error TS2339: Property 'FALLBACK_MOBILE' does not exist on type '{}'.
6+
tests/cases/conformance/fixSignatureCaching.ts(301,17): error TS2339: Property 'isArray' does not exist on type 'never'.
67
tests/cases/conformance/fixSignatureCaching.ts(330,74): error TS2339: Property 'mobileDetectRules' does not exist on type '{}'.
78
tests/cases/conformance/fixSignatureCaching.ts(369,10): error TS2339: Property 'findMatch' does not exist on type '{}'.
89
tests/cases/conformance/fixSignatureCaching.ts(387,10): error TS2339: Property 'findMatches' does not exist on type '{}'.
@@ -71,7 +72,7 @@ tests/cases/conformance/fixSignatureCaching.ts(982,23): error TS2304: Cannot fin
7172
tests/cases/conformance/fixSignatureCaching.ts(983,37): error TS2304: Cannot find name 'window'.
7273

7374

74-
==== tests/cases/conformance/fixSignatureCaching.ts (71 errors) ====
75+
==== tests/cases/conformance/fixSignatureCaching.ts (72 errors) ====
7576
// Repro from #10697
7677

7778
(function (define, undefined) {
@@ -383,6 +384,8 @@ tests/cases/conformance/fixSignatureCaching.ts(983,37): error TS2304: Cannot fin
383384
isArray = 'isArray' in Array
384385
? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; }
385386
: Array.isArray;
387+
~~~~~~~
388+
!!! error TS2339: Property 'isArray' does not exist on type 'never'.
386389

387390
function equalIC(a, b) {
388391
return a != null && b != null && a.toLowerCase() === b.toLowerCase();

tests/baselines/reference/fixSignatureCaching.symbols

-2
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ define(function () {
358358
>value : Symbol(value, Decl(fixSignatureCaching.ts, 299, 20))
359359

360360
: Array.isArray;
361-
>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
362361
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
363-
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
364362

365363
function equalIC(a, b) {
366364
>equalIC : Symbol(equalIC, Decl(fixSignatureCaching.ts, 300, 24))

tests/baselines/reference/fixSignatureCaching.types

+5-5
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,9 @@ define(function () {
893893
>'[object Array]' : "[object Array]"
894894

895895
isArray = 'isArray' in Array
896-
>isArray = 'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : (value: any) => boolean
896+
>isArray = 'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : any
897897
>isArray : any
898-
>'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : (value: any) => boolean
898+
>'isArray' in Array ? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : Array.isArray : any
899899
>'isArray' in Array : boolean
900900
>'isArray' : "isArray"
901901
>Array : ArrayConstructor
@@ -916,9 +916,9 @@ define(function () {
916916
>'[object Array]' : "[object Array]"
917917

918918
: Array.isArray;
919-
>Array.isArray : (arg: any) => arg is any[]
920-
>Array : ArrayConstructor
921-
>isArray : (arg: any) => arg is any[]
919+
>Array.isArray : any
920+
>Array : never
921+
>isArray : any
922922

923923
function equalIC(a, b) {
924924
>equalIC : (a: any, b: any) => boolean

tests/baselines/reference/inKeywordTypeguard.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ class UnreachableCodeDetection {
9898
}
9999

100100
//// [inKeywordTypeguard.js]
101-
var A = (function () {
101+
var A = /** @class */ (function () {
102102
function A() {
103103
}
104104
return A;
105105
}());
106-
var B = (function () {
106+
var B = /** @class */ (function () {
107107
function B() {
108108
}
109109
return B;
@@ -124,12 +124,12 @@ function positiveClassesTest(x) {
124124
x.a = "1";
125125
}
126126
}
127-
var AWithOptionalProp = (function () {
127+
var AWithOptionalProp = /** @class */ (function () {
128128
function AWithOptionalProp() {
129129
}
130130
return AWithOptionalProp;
131131
}());
132-
var BWithOptionalProp = (function () {
132+
var BWithOptionalProp = /** @class */ (function () {
133133
function BWithOptionalProp() {
134134
}
135135
return BWithOptionalProp;
@@ -142,13 +142,13 @@ function positiveTestClassesWithOptionalProperties(x) {
142142
x.b = "1";
143143
}
144144
}
145-
var AWithMethod = (function () {
145+
var AWithMethod = /** @class */ (function () {
146146
function AWithMethod() {
147147
}
148148
AWithMethod.prototype.a = function () { return ""; };
149149
return AWithMethod;
150150
}());
151-
var BWithMethod = (function () {
151+
var BWithMethod = /** @class */ (function () {
152152
function BWithMethod() {
153153
}
154154
BWithMethod.prototype.b = function () { return ""; };
@@ -172,12 +172,12 @@ function negativeTestClassesWithMemberMissingInBothClasses(x) {
172172
x.b();
173173
}
174174
}
175-
var C = (function () {
175+
var C = /** @class */ (function () {
176176
function C() {
177177
}
178178
return C;
179179
}());
180-
var D = (function () {
180+
var D = /** @class */ (function () {
181181
function D() {
182182
}
183183
return D;
@@ -190,7 +190,7 @@ function negativeMultipleClassesTest(x) {
190190
x.a = "1";
191191
}
192192
}
193-
var ClassWithUnionProp = (function () {
193+
var ClassWithUnionProp = /** @class */ (function () {
194194
function ClassWithUnionProp() {
195195
}
196196
return ClassWithUnionProp;
@@ -203,7 +203,7 @@ function negativePropTest(x) {
203203
var z = x.prop.a;
204204
}
205205
}
206-
var NegativeClassTest = (function () {
206+
var NegativeClassTest = /** @class */ (function () {
207207
function NegativeClassTest() {
208208
}
209209
NegativeClassTest.prototype.inThis = function () {
@@ -216,7 +216,7 @@ var NegativeClassTest = (function () {
216216
};
217217
return NegativeClassTest;
218218
}());
219-
var UnreachableCodeDetection = (function () {
219+
var UnreachableCodeDetection = /** @class */ (function () {
220220
function UnreachableCodeDetection() {
221221
}
222222
UnreachableCodeDetection.prototype.inThis = function () {

0 commit comments

Comments
 (0)