• 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  private field2:number = 20;
19  foo(){}
20}
21
22function main():void{
23  let a:A = new A();
24  type keyofA = keyof A;
25
26  let x1:("abcd"|keyofA|number|A)[] = ["abcd",/* @@ label1 */"field2","foo",123,a];
27  let x2:("abcd"|keyofA|number|A)[] = ["abcd",/* @@ label2 */"other field","foo",123,a];
28
29  let x3:["abcd",keyofA,number,A] = ["abcd",/* @@ label3 */"field2",123,a];
30  let x4:["abcd",keyofA,number,A] = ["abcd",/* @@ label4 */"other field",123,a];
31
32  let x5:Array<"abcd"|keyofA|number|A> = /* @@ label5 */new Array<"abcd"|keyofA|number|A>("abcd","field2","foo",123,a);
33  let x6:Array<"abcd"|keyofA|number|A> = /* @@ label6 */new Array<"abcd"|keyofA|number|A>("abcd","other field","foo",123,a);
34}
35
36/* @@? 26:62 Error TypeError: Array element at index 1 with type '"field2"' is not compatible with the target array element type '"abcd"|Double|A|"foo"|"field1"' */
37/* @@? 27:62 Error TypeError: Array element at index 1 with type '"other field"' is not compatible with the target array element type '"abcd"|Double|A|"foo"|"field1"' */
38/* @@? 29:60 Error TypeError: Array initializer's type is not assignable to tuple type at index: 1 */
39/* @@? 30:60 Error TypeError: Array initializer's type is not assignable to tuple type at index: 1 */
40/* @@? 32:57 Error TypeError: Expected 1 arguments, got 5. */
41/* @@? 32:57 Error TypeError: Expected 2 arguments, got 5. */
42/* @@? 32:57 Error TypeError: Expected 0 arguments, got 5. */
43/* @@? 32:57 Error TypeError: No matching construct signature for escompat.Array("abcd", "field2", "foo", int, A) */
44/* @@? 32:98 Error TypeError: Type '"field2"' is not compatible with rest parameter type '"abcd"|Double|A|"foo"|"field1"' at index 2 */
45/* @@? 33:57 Error TypeError: Expected 1 arguments, got 5. */
46/* @@? 33:57 Error TypeError: Expected 2 arguments, got 5. */
47/* @@? 33:57 Error TypeError: Expected 0 arguments, got 5. */
48/* @@? 33:57 Error TypeError: No matching construct signature for escompat.Array("abcd", "other field", "foo", int, A) */
49/* @@? 33:98 Error TypeError: Type '"other field"' is not compatible with rest parameter type '"abcd"|Double|A|"foo"|"field1"' at index 2 */
50