Skip to content

Commit 4e7fe97

Browse files
committed
wip
1 parent 8715473 commit 4e7fe97

5 files changed

+90
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
three.ts(28,14): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
2+
3+
4+
==== one.ts (0 errors) ====
5+
declare const y: never[] | string[];
6+
export const yThen = y.map(item => item.length);
7+
==== two.ts (0 errors) ====
8+
declare const y: number[][] | string[];
9+
export const yThen = y.map(item => item.length);
10+
==== three.ts (1 errors) ====
11+
// #42504
12+
interface ResizeObserverCallback {
13+
(entries: ResizeObserverEntry[], observer: ResizeObserver): void;
14+
}
15+
interface ResizeObserverCallback { // duplicate for effect
16+
(entries: ResizeObserverEntry[], observer: ResizeObserver): void;
17+
}
18+
19+
const resizeObserver = new ResizeObserver(([entry]) => {
20+
entry
21+
});
22+
// comment in #35501
23+
interface Callback<T> {
24+
(error: null, result: T): unknown
25+
(error: Error, result: null): unknown
26+
}
27+
28+
interface Task<T> {
29+
(callback: Callback<T>): unknown
30+
}
31+
32+
export function series<T>(tasks: Task<T>[], callback: Callback<T[]>): void {
33+
let index = 0
34+
let results: T[] = []
35+
36+
function next() {
37+
let task = tasks[index]
38+
if (!task) {
39+
~~~~
40+
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
41+
callback(null, results)
42+
} else {
43+
task((error, result) => {
44+
if (error) {
45+
callback(error, null)
46+
} else {
47+
// must use postfix-!, since `error` and `result` don't have a
48+
// causal relationship when the overloads are combined
49+
results.push(result!)
50+
next()
51+
}
52+
})
53+
}
54+
}
55+
next()
56+
}
57+
58+
series([
59+
cb => setTimeout(() => cb(null, 1), 300),
60+
cb => setTimeout(() => cb(null, 2), 200),
61+
cb => setTimeout(() => cb(null, 3), 100),
62+
], (error, results) => {
63+
if (error) {
64+
console.error(error)
65+
} else {
66+
console.log(results)
67+
}
68+
})
69+

tests/baselines/reference/truthinessCallExpressionCoercion.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
2+
truthinessCallExpressionCoercion.ts(8,11): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
23
truthinessCallExpressionCoercion.ts(18,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
34
truthinessCallExpressionCoercion.ts(36,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
45
truthinessCallExpressionCoercion.ts(50,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
@@ -7,7 +8,7 @@ truthinessCallExpressionCoercion.ts(76,9): error TS2774: This condition will alw
78
truthinessCallExpressionCoercion.ts(82,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
89

910

10-
==== truthinessCallExpressionCoercion.ts (7 errors) ====
11+
==== truthinessCallExpressionCoercion.ts (8 errors) ====
1112
function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) {
1213
if (required) { // error
1314
~~~~~~~~
@@ -18,6 +19,8 @@ truthinessCallExpressionCoercion.ts(82,9): error TS2774: This condition will alw
1819
}
1920

2021
if (!!required) { // ok
22+
~~~~~~~~
23+
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
2124
}
2225

2326
if (required()) { // ok

tests/baselines/reference/truthinessCallExpressionCoercion1.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
truthinessCallExpressionCoercion1.ts(3,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
2+
truthinessCallExpressionCoercion1.ts(9,7): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
23
truthinessCallExpressionCoercion1.ts(19,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
34
truthinessCallExpressionCoercion1.ts(33,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
45
truthinessCallExpressionCoercion1.ts(46,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
56
truthinessCallExpressionCoercion1.ts(76,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
67

78

8-
==== truthinessCallExpressionCoercion1.ts (5 errors) ====
9+
==== truthinessCallExpressionCoercion1.ts (6 errors) ====
910
function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) {
1011
// error
1112
required ? console.log('required') : undefined;
@@ -17,6 +18,8 @@ truthinessCallExpressionCoercion1.ts(76,9): error TS2774: This condition will al
1718

1819
// ok
1920
!!required ? console.log('not required') : undefined;
21+
~~~~~~~~
22+
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
2023

2124
// ok
2225
required() ? console.log('required call') : undefined;

tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
truthinessCallExpressionCoercion2.ts(11,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
22
truthinessCallExpressionCoercion2.ts(14,10): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
3+
truthinessCallExpressionCoercion2.ts(29,7): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
34
truthinessCallExpressionCoercion2.ts(41,18): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
45
truthinessCallExpressionCoercion2.ts(44,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
56
truthinessCallExpressionCoercion2.ts(48,9): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
@@ -35,7 +36,7 @@ truthinessCallExpressionCoercion2.ts(180,9): error TS2774: This condition will a
3536
truthinessCallExpressionCoercion2.ts(183,14): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
3637

3738

38-
==== truthinessCallExpressionCoercion2.ts (35 errors) ====
39+
==== truthinessCallExpressionCoercion2.ts (36 errors) ====
3940
declare class A {
4041
static from(): string;
4142
}
@@ -69,6 +70,8 @@ truthinessCallExpressionCoercion2.ts(183,14): error TS2774: This condition will
6970

7071
// ok
7172
!!required1 && console.log('not required');
73+
~~~~~~~~~
74+
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
7275

7376
// ok
7477
required1() && console.log('required call');

tests/baselines/reference/truthinessPromiseCoercion.errors.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
truthinessPromiseCoercion.ts(7,9): error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
2+
truthinessPromiseCoercion.ts(8,11): error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
23
truthinessPromiseCoercion.ts(11,5): error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
4+
truthinessPromiseCoercion.ts(12,7): error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
35
truthinessPromiseCoercion.ts(32,9): error TS2801: This condition will always return true since this 'Promise<unknown>' is always defined.
46
truthinessPromiseCoercion.ts(40,9): error TS2801: This condition will always return true since this 'Promise<boolean>' is always defined.
57
truthinessPromiseCoercion.ts(43,9): error TS2801: This condition will always return true since this 'Promise<boolean>' is always defined.
68

79

8-
==== truthinessPromiseCoercion.ts (5 errors) ====
10+
==== truthinessPromiseCoercion.ts (7 errors) ====
911
declare const p: Promise<number>
1012
declare const p2: null | Promise<number>
1113
declare const obj: { p: Promise<unknown> }
@@ -17,13 +19,19 @@ truthinessPromiseCoercion.ts(43,9): error TS2801: This condition will always ret
1719
!!! error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
1820
!!! related TS2773 truthinessPromiseCoercion.ts:7:9: Did you forget to use 'await'?
1921
if (!!p) {} // no err
22+
~
23+
!!! error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
24+
!!! related TS2773 truthinessPromiseCoercion.ts:8:11: Did you forget to use 'await'?
2025
if (p2) {} // no err
2126

2227
p ? f.arguments : f.arguments;
2328
~
2429
!!! error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
2530
!!! related TS2773 truthinessPromiseCoercion.ts:11:5: Did you forget to use 'await'?
2631
!!p ? f.arguments : f.arguments;
32+
~
33+
!!! error TS2801: This condition will always return true since this 'Promise<number>' is always defined.
34+
!!! related TS2773 truthinessPromiseCoercion.ts:12:7: Did you forget to use 'await'?
2735
p2 ? f.arguments : f.arguments;
2836
}
2937

0 commit comments

Comments
 (0)