• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/doubleUnderscoreMappedTypes.ts ===
20declare function AssertType(value:any, type:string):void;
21interface Properties {
22    property1: string;
23    __property2: string;
24}
25
26// As expected, I can make an object satisfying this interface
27const ok: Properties = {
28AssertType(ok, "Properties");
29AssertType({    property1: "",    __property2: ""}, "{ property1: string; __property2: string; }");
30
31    property1: "",
32AssertType(property1, "string");
33AssertType("", "string");
34
35    __property2: ""
36AssertType(__property2, "string");
37AssertType("", "string");
38
39};
40
41// As expected, "__property2" is indeed a key of the type
42type Keys = keyof Properties;
43const k: Keys = "__property2"; // ok
44AssertType(k, "keyof Properties");
45AssertType("__property2", "string");
46
47// This should be valid
48type Property2Type = Properties["__property2"];
49
50// And should work with partial
51const partial: Partial<Properties> = {
52AssertType(partial, "Partial<Properties>");
53AssertType({    property1: "",    __property2: ""}, "{ property1: string; __property2: string; }");
54
55    property1: "",
56AssertType(property1, "string");
57AssertType("", "string");
58
59    __property2: ""
60AssertType(__property2, "string");
61AssertType("", "string");
62
63};
64
65
66