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/tile1.ts === 20declare function AssertType(value:any, type:string):void; 21interface Lifecycle<Attrs, State extends Lifecycle<Attrs, State>> { 22 oninit?(vnode: Vnode<Attrs, State>): number; 23 [_: number]: any; 24} 25 26interface Vnode<Attrs, State extends Lifecycle<Attrs, State>> { 27 tag: Component<Attrs, State>; 28} 29 30interface Component<Attrs, State extends Lifecycle<Attrs, State>> { 31 view(this: State, vnode: Vnode<Attrs, State>): number; 32} 33 34interface ClassComponent<A> extends Lifecycle<A, ClassComponent<A>> { 35 oninit?(vnode: Vnode<A, this>): number; 36 view(vnode: Vnode<A, this>): number; 37} 38 39interface MyAttrs { id: number } 40class C implements ClassComponent<MyAttrs> { 41 view(v: Vnode<MyAttrs, C>) { 42AssertType(0, "int"); 43return 0; 44} 45 46 // Must declare a compatible-ish index signature or else 47 // we won't correctly implement ClassComponent. 48 [_: number]: unknown; 49} 50 51const test8: ClassComponent<any> = new C(); 52AssertType(test8, "ClassComponent<any>"); 53AssertType(new C(), "C"); 54AssertType(C, "typeof C"); 55 56 57