Merge pull request #7500 from Microsoft/noImplicitReturnCtor
don't check that return statement has expression in constructors
This commit is contained in:
commit
94ada07051
5 changed files with 37 additions and 1 deletions
|
@ -13965,7 +13965,7 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(func, returnType)) {
|
||||
else if (func.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(func, returnType)) {
|
||||
// The function has a return type, but the return statement doesn't have an expression.
|
||||
error(node, Diagnostics.Not_all_code_paths_return_a_value);
|
||||
}
|
||||
|
|
14
tests/baselines/reference/noImplicitReturnInConstructors.js
Normal file
14
tests/baselines/reference/noImplicitReturnInConstructors.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
//// [noImplicitReturnInConstructors.ts]
|
||||
class C {
|
||||
constructor() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//// [noImplicitReturnInConstructors.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
return;
|
||||
}
|
||||
return C;
|
||||
}());
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/noImplicitReturnInConstructors.ts ===
|
||||
class C {
|
||||
>C : Symbol(C, Decl(noImplicitReturnInConstructors.ts, 0, 0))
|
||||
|
||||
constructor() {
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/noImplicitReturnInConstructors.ts ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
constructor() {
|
||||
return;
|
||||
}
|
||||
}
|
6
tests/cases/compiler/noImplicitReturnInConstructors.ts
Normal file
6
tests/cases/compiler/noImplicitReturnInConstructors.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @noImplicitReturns: true
|
||||
class C {
|
||||
constructor() {
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue