已合并
Declare interface method has body_2 #13007
fanglou创建于 3月31日
Declare interface method has body_2 #13007
已合并
共 3 个文件变更+113-0
| @@ -0,0 +1,28 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 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 | +/*--- | ||
| 17 | + tags: [not-a-test] | ||
| 18 | +---*/ | ||
| 19 | + | ||
| 20 | +export declare interface I1 { | ||
| 21 | + foo1(s: string): string; | ||
| 22 | + default foo(s: string): string; | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +export declare interface I2 { | ||
| 26 | + default foo(s: string): string; | ||
| 27 | + foo2(s: int): int; | ||
| 28 | +} | ||
| @@ -0,0 +1,32 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 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 | +/*--- | ||
| 17 | + tags: [not-a-test] | ||
| 18 | +---*/ | ||
| 19 | + | ||
| 20 | +export interface I1 { | ||
| 21 | + foo1(s: string): string; | ||
| 22 | + foo(s: string): string { | ||
| 23 | + return s; | ||
| 24 | + } | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +export interface I2 { | ||
| 28 | + foo(s: string): string { | ||
| 29 | + return s; | ||
| 30 | + } | ||
| 31 | + foo2(s: int): int; | ||
| 32 | +} | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 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 | +/*--- | ||
| 17 | + files: [declare.ets] | ||
| 18 | +---*/ | ||
| 19 | + | ||
| 20 | +import { I1, I2 } from './declare.d.ets' | ||
| 21 | + | ||
| 22 | +let i11: I1 = { | ||
| 23 | + foo1(s: string) { | ||
| 24 | + return s; | ||
| 25 | + } | ||
| 26 | +}; | ||
| 27 | + | ||
| 28 | +let i12: I1 = { | ||
| 29 | + foo1: (s: string) => { | ||
| 30 | + return s; | ||
| 31 | + } | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +let i21: I2 = { | ||
| 35 | + foo2(s: int){ | ||
| 36 | + return s; | ||
| 37 | + } | ||
| 38 | +}; | ||
| 39 | + | ||
| 40 | +let i22: I2 = { | ||
| 41 | + foo2: (s: int) => { | ||
| 42 | + return s; | ||
| 43 | + } | ||
| 44 | +}; | ||
| 45 | + | ||
| 46 | +arktest.assertEQ(i11.foo('Ifoo'), 'Ifoo'); | ||
| 47 | +arktest.assertEQ(i11.foo1('Ifoo11'), 'Ifoo11'); | ||
| 48 | +arktest.assertEQ(i12.foo('Ifoo'), 'Ifoo'); | ||
| 49 | +arktest.assertEQ(i12.foo1('Ifoo12'), 'Ifoo12'); | ||
| 50 | +arktest.assertEQ(i21.foo('Ifoo21'), 'Ifoo21'); | ||
| 51 | +arktest.assertEQ(i21.foo2(21), 21); | ||
| 52 | +arktest.assertEQ(i22.foo('Ifoo22'), 'Ifoo22'); | ||
| 53 | +arktest.assertEQ(i22.foo2(22), 22); | ||