• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) Microsoft Corporation. All rights reserved.
3* Copyright (c) 2023 Huawei Device Co., Ltd.
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*     http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*
16* This file has been modified by Huawei to verify type inference by adding verification statements.
17*/
18
19// === tests/cases/compiler/nonInferrableTypePropagation2.ts ===
20declare function AssertType(value:any, type:string):void;
21export interface Predicate<A> {
22    (a: A): boolean
23}
24
25interface Left<E> {
26    readonly _tag: 'Left'
27    readonly left: E
28}
29
30interface Right<A> {
31    readonly _tag: 'Right'
32    readonly right: A
33}
34
35type Either<E, A> = Left<E> | Right<A>;
36
37interface Refinement<A, B extends A> {
38    (a: A): a is B
39}
40
41declare const filter: {
42AssertType(filter, "{ <A, B extends A>(Refinement<A, B>): (readonly A[]) => readonly B[]; <A>(Predicate<A>): <B extends A>(readonly B[]) => readonly B[]; <A>(Predicate<A>): (readonly A[]) => readonly A[]; }");
43
44    <A, B extends A>(refinement: Refinement<A, B>): (as: ReadonlyArray<A>) => ReadonlyArray<B>
45AssertType(refinement, "Refinement<A, B>");
46AssertType(as, "readonly A[]");
47
48    <A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => ReadonlyArray<B>
49AssertType(predicate, "Predicate<A>");
50AssertType(bs, "readonly B[]");
51
52    <A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => ReadonlyArray<A>
53AssertType(predicate, "Predicate<A>");
54AssertType(as, "readonly A[]");
55
56};
57
58declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
59declare function exists<A>(predicate: Predicate<A>): <E>(ma: Either<E, A>) => boolean;
60
61declare const es: Either<string, number>[];
62AssertType(es, "Either<string, number>[]");
63
64const x = pipe(es, filter(exists((n) => n > 0)))
65AssertType(x, "readonly Either<string, number>[]");
66AssertType(pipe(es, filter(exists((n) => n > 0))), "readonly Either<string, number>[]");
67AssertType(pipe, "<A, B>(A, (A) => B) => B");
68AssertType(es, "Either<string, number>[]");
69AssertType(filter(exists((n) => n > 0)), "(readonly Either<string, number>[]) => readonly Either<string, number>[]");
70AssertType(filter, "{ <A, B extends A>(Refinement<A, B>): (readonly A[]) => readonly B[]; <A>(Predicate<A>): <B extends A>(readonly B[]) => readonly B[]; <A>(Predicate<A>): (readonly A[]) => readonly A[]; }");
71AssertType(exists((n) => n > 0), "<E>(Either<E, number>) => boolean");
72AssertType(exists, "<A>(Predicate<A>) => <E>(Either<E, A>) => boolean");
73AssertType((n) => n > 0, "(number) => boolean");
74AssertType(n, "number");
75AssertType(n > 0, "boolean");
76AssertType(n, "number");
77AssertType(0, "int");
78
79
80