Skip to content

Commit bad002c

Browse files
Merge pull request microsoft#26150 from Kingwl/CheckReturnUnknow
add check for function return unknow type
2 parents d0ed21c + c47a57f commit bad002c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20681,7 +20681,7 @@ namespace ts {
2068120681
}
2068220682

2068320683
// Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions.
20684-
if (returnType && maybeTypeOfKind(returnType, TypeFlags.AnyOrUnknown | TypeFlags.Void)) {
20684+
if (returnType && maybeTypeOfKind(returnType, TypeFlags.Any | TypeFlags.Void)) {
2068520685
return;
2068620686
}
2068720687

tests/baselines/reference/unknownType1.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ tests/cases/conformance/types/unknown/unknownType1.ts(114,9): error TS2322: Type
1818
Type 'unknown' is not assignable to type '{}'.
1919
tests/cases/conformance/types/unknown/unknownType1.ts(120,9): error TS2322: Type 'T' is not assignable to type 'object'.
2020
tests/cases/conformance/types/unknown/unknownType1.ts(129,5): error TS2322: Type '123' is not assignable to type '{ [x: string]: unknown; }'.
21+
tests/cases/conformance/types/unknown/unknownType1.ts(149,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
2122
tests/cases/conformance/types/unknown/unknownType1.ts(155,14): error TS2700: Rest types may only be created from object types.
2223
tests/cases/conformance/types/unknown/unknownType1.ts(161,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
2324

2425

25-
==== tests/cases/conformance/types/unknown/unknownType1.ts (21 errors) ====
26+
==== tests/cases/conformance/types/unknown/unknownType1.ts (22 errors) ====
2627
// In an intersection everything absorbs unknown
2728

2829
type T00 = unknown & null; // null
@@ -211,6 +212,8 @@ tests/cases/conformance/types/unknown/unknownType1.ts(161,5): error TS2564: Prop
211212
// Functions with unknown return type don't need return expressions
212213

213214
function f27(): unknown {
215+
~~~~~~~
216+
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
214217
}
215218

216219
// Rest type cannot be created from unknown

0 commit comments

Comments
 (0)