• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16class A{
17  field1:number = 10;
18  foo(){}
19}
20
21class B{
22  readonly field1:("abcd"|(keyof A)|number|A)[] = ["abcd","field1","foo",123,new A()];
23}
24
25function main():void{
26  let a:A = new A();
27  type keyofA = keyof A;
28
29  let x:("abcd"|keyofA|number|A)[] = ["abcd","field1","foo",123,a];
30  let x2:("abcd"|(keyof A)|number|A)[] = ["abcd","field1","foo",123,a];
31  let x3:("abcd"|(keyof Number)|number|A)[] = ["abcd","valueOf","toPrecision",123,a];
32
33  let x4:["abcd",keyofA,number,A] = ["abcd","field1",123,a];
34  let x5:["abcd",(keyof A),number,A] = ["abcd","field1",123,a];
35  let x6:["abcd",(keyof Number),number,A] = ["abcd","valueOf",123,a];
36
37  let x7:("abcd"|keyofA|number|A)[][] = [["abcd","field1","foo",123,a],["abcd","field1","foo",123,a]];
38  let x8:("abcd"|(keyof A)|number|A)[][] = [["abcd","field1","foo",123,a],["abcd","field1","foo",123,a]];
39  let x9:("abcd"|(keyof Number)|number|A)[][] = [["abcd","valueOf","toPrecision",123,a],["abcd","valueOf","toPrecision",123,a]];
40
41  let x10:Array<"abcd"|keyofA|number|A> = new Array<"abcd"|keyofA|number|A>("abcd","field1","foo",123,a);
42  let x11:Array<"abcd"|(keyof A)|number|A> = new Array<"abcd"|(keyof A)|number|A>("abcd","field1","foo",123,a);
43  let x12:Array<"abcd"|(keyof Number)|number|A> = new Array<"abcd"|(keyof Number)|number|A>("abcd","valueOf","toPrecision",123,a);
44}
45