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/objectTypeLiteral/propertySignatures/stringNamedPropertyAccess.ts === 20declare function AssertType(value:any, type:string):void; 21class C { 22 "a b": number; 23 static "c d": number; 24} 25let c: C; 26AssertType(c, "C"); 27 28let r1 = c["a b"]; 29AssertType(r1, "number"); 30AssertType(c["a b"], "number"); 31AssertType(c, "C"); 32AssertType("a b", "string"); 33 34let r1b = C['c d']; 35AssertType(r1b, "number"); 36AssertType(C['c d'], "number"); 37AssertType(C, "typeof C"); 38AssertType('c d', "string"); 39 40interface I { 41 "a b": number; 42} 43let i: I; 44AssertType(i, "I"); 45 46let r2 = i["a b"]; 47AssertType(r2, "number"); 48AssertType(i["a b"], "number"); 49AssertType(i, "I"); 50AssertType("a b", "string"); 51 52let a: { 53AssertType(a, "{ "a b": number; }"); 54 55 "a b": number; 56AssertType("a b", "number"); 57} 58let r3 = a["a b"]; 59AssertType(r3, "number"); 60AssertType(a["a b"], "number"); 61AssertType(a, "{ "a b": number; }"); 62AssertType("a b", "string"); 63 64let b = { 65AssertType(b, "{ "a b": number; }"); 66AssertType({ "a b": 1}, "{ "a b": number; }"); 67 68 "a b": 1 69AssertType("a b", "number"); 70AssertType(1, "int"); 71} 72let r4 = b["a b"]; 73AssertType(r4, "number"); 74AssertType(b["a b"], "number"); 75AssertType(b, "{ "a b": number; }"); 76AssertType("a b", "string"); 77 78 79