1/* 2* Copyright (c) Microsoft Corporation. All rights reserved. 3* Copyright (c) 2023 Huawei Device Co., Ltd. 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15* 16* This file has been modified by Huawei to verify type inference by adding verification statements. 17*/ 18 19// === tests/cases/compiler/transformsElideNullUndefinedType.ts === 20declare function AssertType(value:any, type:string):void; 21let v0: null; 22AssertType(v0, "null"); 23AssertType(null, "null"); 24 25let v1: undefined; 26AssertType(v1, "undefined"); 27 28function f0(): null { 29AssertType(null, "null"); 30return null; 31} 32 33function f1(): undefined { 34AssertType(undefined, "undefined"); 35return undefined; 36} 37 38let f2 = function (): null { 39AssertType(f2, "() => null"); 40return null; 41 42AssertType(function (): null { return null; }, "() => null"); 43 44AssertType(null, "null"); 45 46AssertType(null, "null"); 47} 48 49let f3 = function (): undefined { 50AssertType(f3, "() => undefined"); 51return undefined; 52 53AssertType(function (): undefined { return undefined; }, "() => undefined"); 54 55AssertType(undefined, "undefined"); 56} 57 58let f4 = (): null => null; 59AssertType(f4, "() => null"); 60AssertType((): null => null, "() => null"); 61AssertType(null, "null"); 62AssertType(null, "null"); 63 64let f5 = (): undefined => undefined; 65AssertType(f5, "() => undefined"); 66AssertType((): undefined => undefined, "() => undefined"); 67AssertType(undefined, "undefined"); 68 69function f6(p0: null) { } 70function f7(p1: undefined) { } 71 72let f8 = function (p2: null) { 73AssertType(f8, "(null) => void"); 74 75AssertType(function (p2: null) { }, "(null) => void"); 76 77AssertType(p2, "null"); 78 79AssertType(null, "null"); 80} 81 82let f9 = function (p3: undefined) { 83AssertType(f9, "(undefined) => void"); 84 85AssertType(function (p3: undefined) { }, "(undefined) => void"); 86 87AssertType(p3, "undefined"); 88} 89 90let f10 = (p4: null) => { 91AssertType(f10, "(null) => void"); 92 93AssertType((p4: null) => { }, "(null) => void"); 94 95AssertType(p4, "null"); 96 97AssertType(null, "null"); 98} 99 100let f11 = (p5: undefined) => { 101AssertType(f11, "(undefined) => void"); 102 103AssertType((p5: undefined) => { }, "(undefined) => void"); 104 105AssertType(p5, "undefined"); 106} 107 108class C1 { 109 m0(): null { 110AssertType(null, "null"); 111return null; 112} 113 114 m1(): undefined { 115AssertType(undefined, "undefined"); 116return undefined; 117} 118 119 m3(p6: null) { } 120 m4(p7: undefined) { } 121 122 get a0(): null { 123AssertType(null, "null"); 124return null; 125} 126 127 get a1(): undefined { 128AssertType(undefined, "undefined"); 129return undefined; 130} 131 132 set a2(p8: null) { } 133 set a3(p9: undefined) { } 134} 135 136class C2 { constructor(p10: null) { } } 137class C3 { constructor(p11: undefined) { } } 138 139class C4 { 140 f1; 141 constructor(p12: null) { } 142} 143 144class C5 { 145 f2; 146 constructor(p13: undefined) { } 147} 148 149let C6 = class { constructor(p12: null) { } 150AssertType(C6, "typeof C6"); 151 152AssertType(class { constructor(p12: null) { } }, "typeof C6"); 153 154AssertType(p12, "null"); 155 156AssertType(null, "null"); 157} 158 159let C7 = class { constructor(p13: undefined) { } 160AssertType(C7, "typeof C7"); 161 162AssertType(class { constructor(p13: undefined) { } }, "typeof C7"); 163 164AssertType(p13, "undefined"); 165} 166 167declare function fn<T>(); 168fn<null>(); 169AssertType(fn<null>(), "any"); 170AssertType(fn, "<T>() => any"); 171AssertType(null, "null"); 172 173fn<undefined>(); 174AssertType(fn<undefined>(), "any"); 175AssertType(fn, "<T>() => any"); 176 177declare class D<T> {} 178new D<null>(); 179AssertType(new D<null>(), "D<null>"); 180AssertType(D, "typeof D"); 181AssertType(null, "null"); 182 183new D<undefined>(); 184AssertType(new D<undefined>(), "D<undefined>"); 185AssertType(D, "typeof D"); 186 187 188