• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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/**---
16 description: >
17    TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member.
18 module: ES2022
19 isCurrent: true
20 ---*/
21
22
23import { Assert } from '../../../suite/assert.js';
24
25enum Color {
26  Red,
27  Orange,
28  Yellow,
29  Green,
30  Blue,
31  Violet
32}
33
34enum Values {
35  First = 'aaaaa',
36  Second = 'bbbbbbbbb',
37  Third = 'ccccccccc'
38}
39
40type PrimaryValues = Color.Red | Values.First;
41
42function isPrimaryValues(c: Values | Color): c is PrimaryValues {
43  return c === Color.Red || c === Values.First;
44}
45
46const firstValue = isPrimaryValues(Values.First);
47Assert.isTrue(firstValue);
48
49const secondValue = isPrimaryValues(Color.Red);
50Assert.isTrue(secondValue);
51
52const thirdValue = isPrimaryValues(Color.Yellow);
53Assert.isFalse(thirdValue);