• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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
16/*---
17 desc: 7.19 Nullish-Coalescing Expression
18 name: issue14609_02
19 tags:
20 ---*/
21
22class A<T> {
23  public parent: A<T>
24  data: T
25  constructor(data: T) {
26      this.data = data
27  }
28  foo() : A<T> {
29    return this.parent ?? this
30  }
31}
32
33function main(): void {
34  let a = new A<string>("hello")
35  let aa = a.foo()
36  let b = new A<null>(null)
37  let bb = b.foo()
38  assertTrue( aa instanceof A)
39  assertTrue( bb instanceof A)
40}