Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85945c3

Browse files
Fix throws clause inference for arrow functions
- Arrow functions without explicit throws clauses can now properly infer throws from their body- Removed validation that incorrectly required arrow functions to have explicit throws clauses- Arrow functions calling other throwing functions still require explicit throws clauses- Maintains proper validation for functions with explicit throws clauses
1 parent0cfe594 commit85945c3

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

‎src/compiler/checker.ts‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39687,19 +39687,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3968739687
checkReturnExpression(node, returnOrPromisedType, node.body, node.body, exprType);
3968839688
}
3968939689
}
39690-
const declaredThrows = node.throwsClause?.types ?? [];
39691-
const actuallyThrown = collectThrownTypes(node.body);
39692-
39693-
39694-
39695-
for (const thrown of actuallyThrown) {
39696-
if (!isThrowsTypeCompatible(thrown, declaredThrows)) {
39697-
error(node, {
39698-
message: `Function throws ${typeToString(thrown)}, but it is not declared in the throws clause.`,
39699-
category: DiagnosticCategory.Error,
39700-
code: 1234,
39701-
key: 'functionThrowsButNotDeclaredInThrowsClause',
39702-
});
39690+
// Only validate throws for functions with explicit throws clauses
39691+
// Arrow functions without explicit throws clauses should be allowed to infer throws
39692+
if (node.throwsClause) {
39693+
const declaredThrows = node.throwsClause.types;
39694+
const actuallyThrown = collectThrownTypes(node.body);
39695+
39696+
// If throws clause is empty, allow all throws (inference mode)
39697+
if (declaredThrows.length > 0) {
39698+
// Check if each actually thrown type is compatible with declared throws
39699+
for (const thrown of actuallyThrown) {
39700+
if (!isThrowsTypeCompatible(thrown, declaredThrows)) {
39701+
error(node, {
39702+
message: `Function throws ${typeToString(thrown)}, but it is not declared in the throws clause.`,
39703+
category: DiagnosticCategory.Error,
39704+
code: 1234,
39705+
key: 'functionThrowsButNotDeclaredInThrowsClause',
39706+
});
39707+
}
39708+
}
3970339709
}
3970439710
}
3970539711
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp