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/conformance/types/typeRelationships/assignmentCompatibility/nullAssignableToEveryType.ts === 20declare function AssertType(value:any, type:string):void; 21class C { 22 foo: string; 23} 24let ac: C; 25AssertType(ac, "C"); 26 27interface I { 28 foo: string; 29} 30let ai: I; 31AssertType(ai, "I"); 32 33enum E { A } 34let ae: E; 35AssertType(ae, "E"); 36 37let b: number = null; 38AssertType(b, "number"); 39AssertType(null, "null"); 40 41let c: string = null; 42AssertType(c, "string"); 43AssertType(null, "null"); 44 45let d: boolean = null; 46AssertType(d, "boolean"); 47AssertType(null, "null"); 48 49let e: Date = null; 50AssertType(e, "Date"); 51AssertType(null, "null"); 52 53let f: any = null; 54AssertType(f, "any"); 55AssertType(null, "null"); 56 57let g: void = null; 58AssertType(g, "void"); 59AssertType(null, "null"); 60 61let h: Object = null; 62AssertType(h, "Object"); 63AssertType(null, "null"); 64 65let i: {} = null; 66AssertType(i, "{}"); 67AssertType(null, "null"); 68 69let j: () => {} = null; 70AssertType(j, "() => {}"); 71AssertType(null, "null"); 72 73let k: Function = null; 74AssertType(k, "Function"); 75AssertType(null, "null"); 76 77let l: (x: number) => string = null; 78AssertType(l, "(number) => string"); 79AssertType(x, "number"); 80AssertType(null, "null"); 81 82ac = null; 83AssertType(ac = null, "null"); 84AssertType(ac, "C"); 85AssertType(null, "null"); 86 87ai = null; 88AssertType(ai = null, "null"); 89AssertType(ai, "I"); 90AssertType(null, "null"); 91 92ae = null; 93AssertType(ae = null, "null"); 94AssertType(ae, "E"); 95AssertType(null, "null"); 96 97let m: number[] = null; 98AssertType(m, "number[]"); 99AssertType(null, "null"); 100 101let n: { foo: string } = null; 102AssertType(n, "{ foo: string; }"); 103AssertType(foo, "string"); 104AssertType(null, "null"); 105 106let o: <T>(x: T) => T = null; 107AssertType(o, "<T>(T) => T"); 108AssertType(x, "T"); 109AssertType(null, "null"); 110 111let p: Number = null; 112AssertType(p, "Number"); 113AssertType(null, "null"); 114 115let q: String = null; 116AssertType(q, "String"); 117AssertType(null, "null"); 118 119function foo<T, U, V extends Date>(x: T, y: U, z: V) { 120 x = null; 121AssertType(x = null, "null"); 122AssertType(x, "T"); 123AssertType(null, "null"); 124 125 y = null; 126AssertType(y = null, "null"); 127AssertType(y, "U"); 128AssertType(null, "null"); 129 130 z = null; 131AssertType(z = null, "null"); 132AssertType(z, "V"); 133AssertType(null, "null"); 134} 135 136//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) { 137// x = null; 138// y = null; 139// z = null; 140//} 141 142