fix(no-undefined-types): support strict validation for TS namespaces #1616
+268
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the
no-undefined-typesrule to support strict validation of TypeScript namespaces. Previously, the rule might have been too permissive or failed to recognize types defined within namespaces in the same file.This became an issue recently with an update that led to
definedTypesmatching a declared namespace on a.d.tsfile starting to report their inner properties/types/interfaces asundefined.An example would be configuring the
no-undefined-typeswith:while having a
.d.tsfile with something such as the following:And then wanting to use
Foobar.FoobarInterface,Foobar.FoobarInterface['foo'], orFoobar.Foobiz.bizas types on JSDoc. The TS LSP would recognize them, but this rule started reporting errors.Changes
TSModuleDeclaration) are now added to theclosedTypesset. This means the rule will strictly validate members accessed on these namespaces (e.g.,MyNamespace.NonExistentTypewill now be reported as undefined).TSTypeAliasDeclaration.TSInterfaceDeclaration(including their properties).ExportNamedDeclarationvariants (likeexport classandexport {}) are properly handled (ignored) without reducing code coverage.