• 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  field1:keyof A = "field1";
23}
24
25interface I{
26  field1:keyof A;
27}
28
29function main():void{
30  let x1:B = {field1:"field1"};
31  let x2:Partial<B> = {field1:"field1"};
32  let x3:Partial<B> = {field1:"foo"};
33  let x4:Partial<B> = {};
34  let x5:Required<B> = {field1:"field1"};
35  let x6:Required<B> = {field1:"foo"};
36  let x7:Readonly<B> = {field1:"field1"};
37  let x8:Readonly<B> = {field1:"foo"};
38
39  let x9:B = new B();
40  x9.field1 = "field1";
41  x9.field1 = "foo"
42
43  let i1:I = {field1:"field1"};
44  let i2:Partial<I> = {field1:"field1"};
45  let i3:Partial<I> = {field1:"foo"};
46  let i4:Partial<I> = {};
47  let i5:Required<I> = {field1:"field1"};
48  let i6:Required<I> = {field1:"foo"};
49  let i7:Readonly<I> = {field1:"field1"};
50  let i8:Readonly<I> = {field1:"foo"};
51}
52