• 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/conformance/statements/returnStatements/returnStatements.ts ===
20declare function AssertType(value:any, type:string):void;
21// all the following should be valid
22function fn1(): number {
23AssertType(1, "int");
24return 1;
25}
26
27function fn2(): string {
28AssertType('', "string");
29return '';
30}
31
32function fn3(): void {
33AssertType(undefined, "undefined");
34return undefined;
35}
36
37function fn4(): void {
38return; }
39function fn5(): boolean {
40AssertType(true, "boolean");
41return true;
42}
43
44function fn6(): Date {
45AssertType(new Date(12), "Date");
46return new Date(12);
47
48AssertType(Date, "DateConstructor");
49
50AssertType(12, "int");
51}
52
53function fn7(): any {
54AssertType(null, "null");
55return null;
56}
57
58function fn8(): any {
59return; } // OK, eq. to 'return undefined'
60
61interface I { id: number }
62class C implements I {
63    id: number;
64    dispose() {}
65}
66class D extends C {
67    name: string;
68}
69function fn10(): I {
70AssertType({ id: 12 }, "{ id: number; }");
71AssertType(id, "number");
72AssertType(12, "int");
73return { id: 12 }; }
74
75function fn11(): I {
76AssertType(new C(), "C");
77return new C();
78
79AssertType(C, "typeof C");
80}
81
82function fn12(): C {
83AssertType(new D(), "D");
84return new D();
85
86AssertType(D, "typeof D");
87}
88
89function fn13(): C {
90AssertType(null, "null");
91return null;
92}
93
94
95