Skip to content

Commit e8e47dd

Browse files
authored
Add missing test case for assertion functions with PropertySignature declarations (#59714)
1 parent a5eec24 commit e8e47dd

File tree

5 files changed

+680
-1
lines changed

5 files changed

+680
-1
lines changed

tests/baselines/reference/assertionTypePredicates1.errors.txt

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ assertionTypePredicates1.ts(165,15): error TS1228: A type predicate is only allo
1313
assertionTypePredicates1.ts(170,5): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
1414
assertionTypePredicates1.ts(172,5): error TS2776: Assertions require the call target to be an identifier or qualified name.
1515
assertionTypePredicates1.ts(174,5): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
16+
assertionTypePredicates1.ts(200,5): error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
1617

1718

18-
==== assertionTypePredicates1.ts (15 errors) ====
19+
==== assertionTypePredicates1.ts (16 errors) ====
1920
declare function isString(value: unknown): value is string;
2021
declare function isArrayOfStrings(value: unknown): value is string[];
2122

@@ -243,4 +244,69 @@ assertionTypePredicates1.ts(174,5): error TS2775: Assertions require every name
243244
thing.good;
244245
}
245246
}
247+
248+
class TestPropertyDeclaration1 {
249+
assert = (value: unknown): asserts value => {};
250+
other(x: unknown) {
251+
this.assert(x); // error
252+
~~~~~~~~~~~
253+
!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
254+
!!! related TS2782 assertionTypePredicates1.ts:198:3: 'assert' needs an explicit type annotation.
255+
x;
256+
}
257+
}
258+
259+
class TestPropertyDeclaration2 {
260+
assert: (v: unknown) => asserts v = (value) => {};
261+
other(x: unknown) {
262+
this.assert(x); // ok
263+
x;
264+
}
265+
}
266+
267+
declare class ParentInheritedPropertyDeclaration {
268+
assert: (value: unknown) => asserts value;
269+
}
270+
class ChildInheritedPropertyDeclaration extends ParentInheritedPropertyDeclaration {
271+
other(x: unknown) {
272+
this.assert(x); // ok
273+
x;
274+
}
275+
}
276+
277+
interface TestPropertySignature {
278+
assert: (value: unknown) => asserts value;
279+
}
280+
function testPropertySignature(
281+
x: TestPropertySignature,
282+
y: unknown,
283+
) {
284+
x.assert(y); // ok
285+
x;
286+
}
287+
function testFunctionThisParameter1(
288+
this: TestPropertySignature,
289+
x: unknown,
290+
) {
291+
this.assert(x); // ok
292+
x;
293+
}
294+
295+
interface TestMethodSignature {
296+
assert(value: unknown): asserts value;
297+
}
298+
function testMethodSignature(
299+
x: TestMethodSignature,
300+
y: unknown,
301+
) {
302+
x.assert(y); // ok
303+
x;
304+
}
305+
function testFunctionThisParameter2(
306+
this: TestMethodSignature,
307+
x: unknown,
308+
) {
309+
this.assert(x); // ok
310+
x;
311+
}
246312

tests/baselines/reference/assertionTypePredicates1.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,68 @@ function example1(things: Thing[]) {
196196
thing.good;
197197
}
198198
}
199+
200+
class TestPropertyDeclaration1 {
201+
assert = (value: unknown): asserts value => {};
202+
other(x: unknown) {
203+
this.assert(x); // error
204+
x;
205+
}
206+
}
207+
208+
class TestPropertyDeclaration2 {
209+
assert: (v: unknown) => asserts v = (value) => {};
210+
other(x: unknown) {
211+
this.assert(x); // ok
212+
x;
213+
}
214+
}
215+
216+
declare class ParentInheritedPropertyDeclaration {
217+
assert: (value: unknown) => asserts value;
218+
}
219+
class ChildInheritedPropertyDeclaration extends ParentInheritedPropertyDeclaration {
220+
other(x: unknown) {
221+
this.assert(x); // ok
222+
x;
223+
}
224+
}
225+
226+
interface TestPropertySignature {
227+
assert: (value: unknown) => asserts value;
228+
}
229+
function testPropertySignature(
230+
x: TestPropertySignature,
231+
y: unknown,
232+
) {
233+
x.assert(y); // ok
234+
x;
235+
}
236+
function testFunctionThisParameter1(
237+
this: TestPropertySignature,
238+
x: unknown,
239+
) {
240+
this.assert(x); // ok
241+
x;
242+
}
243+
244+
interface TestMethodSignature {
245+
assert(value: unknown): asserts value;
246+
}
247+
function testMethodSignature(
248+
x: TestMethodSignature,
249+
y: unknown,
250+
) {
251+
x.assert(y); // ok
252+
x;
253+
}
254+
function testFunctionThisParameter2(
255+
this: TestMethodSignature,
256+
x: unknown,
257+
) {
258+
this.assert(x); // ok
259+
x;
260+
}
199261

200262

201263
//// [assertionTypePredicates1.js]
@@ -386,6 +448,53 @@ function example1(things) {
386448
thing.good;
387449
}
388450
}
451+
var TestPropertyDeclaration1 = /** @class */ (function () {
452+
function TestPropertyDeclaration1() {
453+
this.assert = function (value) { };
454+
}
455+
TestPropertyDeclaration1.prototype.other = function (x) {
456+
this.assert(x); // error
457+
x;
458+
};
459+
return TestPropertyDeclaration1;
460+
}());
461+
var TestPropertyDeclaration2 = /** @class */ (function () {
462+
function TestPropertyDeclaration2() {
463+
this.assert = function (value) { };
464+
}
465+
TestPropertyDeclaration2.prototype.other = function (x) {
466+
this.assert(x); // ok
467+
x;
468+
};
469+
return TestPropertyDeclaration2;
470+
}());
471+
var ChildInheritedPropertyDeclaration = /** @class */ (function (_super) {
472+
__extends(ChildInheritedPropertyDeclaration, _super);
473+
function ChildInheritedPropertyDeclaration() {
474+
return _super !== null && _super.apply(this, arguments) || this;
475+
}
476+
ChildInheritedPropertyDeclaration.prototype.other = function (x) {
477+
this.assert(x); // ok
478+
x;
479+
};
480+
return ChildInheritedPropertyDeclaration;
481+
}(ParentInheritedPropertyDeclaration));
482+
function testPropertySignature(x, y) {
483+
x.assert(y); // ok
484+
x;
485+
}
486+
function testFunctionThisParameter1(x) {
487+
this.assert(x); // ok
488+
x;
489+
}
490+
function testMethodSignature(x, y) {
491+
x.assert(y); // ok
492+
x;
493+
}
494+
function testFunctionThisParameter2(x) {
495+
this.assert(x); // ok
496+
x;
497+
}
389498

390499

391500
//// [assertionTypePredicates1.d.ts]
@@ -438,3 +547,27 @@ interface GoodThing {
438547
good: true;
439548
}
440549
declare function example1(things: Thing[]): void;
550+
declare class TestPropertyDeclaration1 {
551+
assert: (value: unknown) => asserts value;
552+
other(x: unknown): void;
553+
}
554+
declare class TestPropertyDeclaration2 {
555+
assert: (v: unknown) => asserts v;
556+
other(x: unknown): void;
557+
}
558+
declare class ParentInheritedPropertyDeclaration {
559+
assert: (value: unknown) => asserts value;
560+
}
561+
declare class ChildInheritedPropertyDeclaration extends ParentInheritedPropertyDeclaration {
562+
other(x: unknown): void;
563+
}
564+
interface TestPropertySignature {
565+
assert: (value: unknown) => asserts value;
566+
}
567+
declare function testPropertySignature(x: TestPropertySignature, y: unknown): void;
568+
declare function testFunctionThisParameter1(this: TestPropertySignature, x: unknown): void;
569+
interface TestMethodSignature {
570+
assert(value: unknown): asserts value;
571+
}
572+
declare function testMethodSignature(x: TestMethodSignature, y: unknown): void;
573+
declare function testFunctionThisParameter2(this: TestMethodSignature, x: unknown): void;

0 commit comments

Comments
 (0)