• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the 'License');
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an 'AS IS' BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16type T00 = Exclude<'a' | 'b' | 'c' | 'd', 'a' | 'c' | 'f'>; // 'b' | 'd'
17type T01 = Extract<'a' | 'b' | 'c' | 'd', 'a' | 'c' | 'f'>; // 'a' | 'c'
18
19type T02 = Exclude<string | number | (() => void), Function>; // string | number
20type T03 = Extract<string | number | (() => void), Function>; // () => void
21
22type T04 = NonNullable<string | number | undefined>; // string | number
23type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
24
25function f1(s: string): any {
26  return {a: 1, b: s};
27}
28
29class C {
30  x = 0;
31  y = 0;
32}
33
34type ResultString = ReturnType<() => string>; // string
35type ResultVoid = ReturnType<(s: string) => void>; // void
36type ResultGeneric = ReturnType<(<T>() => T)>; // {}
37type ResultConstrained = ReturnType<(<T extends U, U extends number[]>() => T)>; // number[]
38type ResultInstance = ReturnType<typeof f1>; // { a: number, b: string }
39type ResultAny = ReturnType<any>; // any
40type ResultNever = ReturnType<never>; // any
41
42type T20 = InstanceType<typeof C>; // C
43type T21 = InstanceType<any>; // any
44type T22 = InstanceType<never>; // any