-
Notifications
You must be signed in to change notification settings - Fork 12.8k
checker.ts :: checkModuleDeclaration(): Redundant type guard erroneously narrows node type to 'never' #45572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think your sources are out of date; this was fixed as soon as it became a problem. It now reads const isAmbientExternalModule: boolean = isAmbientModule(node); The compiler compiles itself in CI, so we automatically catch things like this as we go. |
EDIT: Okay, it seems like just adding a type annotation solves this issue. But how? @andrewbranch that doesn't really change anything about the issue, does it? The issue is not in the type definition of isAmbientExternalModule, it is in the intersection of The line // utilities.ts:773
export function isExternalModuleAugmentation(node: Node): node is AmbientModuleDeclaration {
return isAmbientModule(node) && isModuleAugmentationExternal(node);
} I think the issue should be reopened. The bug is still there. |
Bug Report
I have a ready, very easy fix for this bug, so if you indeed recognize this as a bug, please assign it to me, and I'll submit a PR.
🔎 Search Terms
checkModuleDeclaration node type never
checker.ts
isExternalModuleAugmentation
Property 'parent' does not exist on type 'never' (ts2339)
🕗 Version & Regression Information
This is a logical bug in
checker.ts
that should arise in pretty much any TypeScript version that supports type guards/predicaments. However, sinceisAmbientModule()
's result is assigned to a variable, and control flow of aliased conditional expressions is introduced only in v4.4.0, this issue will only appear in v4.4.0+ (or any other version with pull request #44730)Judging by related commits that I've found by using
git blame -L37720,37722 src/compiler/checker.ts
andgit log -L37720,37722:src/compiler/checker.ts
, the bug was introduced somewhere around v2.8-rc:isExternalModuleAugmentation()
check (which will become redundant in the next commit)isExternalModuleAugmentation()
, which created a redundancy with parentisAmbientModule
check.⏯ Playground Link
Close recreation of the issue
💻 Code
checker.ts : line 37664
🙁 Actual behavior
Covered in the code examples/playground.
🙂 Expected behavior
Covered in the code examples/playground.
The text was updated successfully, but these errors were encountered: