• 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/genericMethodOverspecialization.ts ===
20declare function AssertType(value:any, type:string):void;
21let names = ["list", "table1", "table2", "table3", "summary"];
22AssertType(names, "string[]");
23AssertType(["list", "table1", "table2", "table3", "summary"], "string[]");
24AssertType("list", "string");
25AssertType("table1", "string");
26AssertType("table2", "string");
27AssertType("table3", "string");
28AssertType("summary", "string");
29
30interface HTMLElement {
31    clientWidth: number;
32    isDisabled: boolean;
33}
34
35declare let document: Document;
36AssertType(document, "Document");
37
38interface Document {
39    getElementById(elementId: string): HTMLElement;
40}
41
42let elements = names.map(function (name) {
43AssertType(elements, "HTMLElement[]");
44AssertType(names.map, "<U>((string, number, string[]) => U, ?any) => U[]");
45AssertType(function (name) {    return document.getElementById(name);}, "(string) => HTMLElement");
46AssertType(name, "string");
47AssertType(names.map(function (name) {    return document.getElementById(name);}), "HTMLElement[]");
48
49AssertType(document.getElementById(name), "HTMLElement");
50AssertType(document.getElementById, "{ (string): HTMLElement; (string): HTMLElement; }");
51AssertType(name, "string");
52    return document.getElementById(name);
53
54});
55
56
57let xxx = elements.filter(function (e) {
58AssertType(xxx, "HTMLElement[]");
59AssertType(elements.filter, "{ <S extends HTMLElement>((HTMLElement, number, HTMLElement[]) => value is S, ?any): S[]; ((HTMLElement, number, HTMLElement[]) => unknown, ?any): HTMLElement[]; }");
60AssertType(function (e) {    return !e.isDisabled;}, "(HTMLElement) => boolean");
61AssertType(e, "HTMLElement");
62AssertType(elements.filter(function (e) {    return !e.isDisabled;}), "HTMLElement[]");
63
64AssertType(!e.isDisabled, "boolean");
65AssertType(e.isDisabled, "boolean");
66    return !e.isDisabled;
67
68});
69
70let widths:number[] = elements.map(function (e) { // should not error
71AssertType(widths, "number[]");
72AssertType(elements.map, "<U>((HTMLElement, number, HTMLElement[]) => U, ?any) => U[]");
73AssertType(function (e) { // should not error    return e.clientWidth;}, "(HTMLElement) => number");
74AssertType(e, "HTMLElement");
75AssertType(elements.map(function (e) { // should not error    return e.clientWidth;}), "number[]");
76
77AssertType(e.clientWidth, "number");
78    return e.clientWidth;
79
80});
81
82
83
84