Skip to content

Commit

Permalink
[labs/analyzer] Don't extract JSDoc types in TS. Port type tests to J…
Browse files Browse the repository at this point in the history
…S. (#3658)

* TS already takes into account JSDoc comments when determining types, if applicable. (...)

When TypeScript is checking `.ts` files, JSDoc comments that indicate types have
no effect despite being parsed and reachable through the AST. When checking
`.js` files, JSDoc comments are automatically considered by `tsc` and don't need
to be separately taken into account.

* Remove incorrect JSDoc type tests. (...)

These tests were checking if types defined by JSDoc comments in `.ts` files were
being output by the analyzer. However, TS does not consider JSDoc comments to
have any effect in `.ts` files, even though they're parsed and reachable in the
AST.

* Copy TS type tests and port to JS.

* Remove a comment that no longer applies.

* Add a changeset.
  • Loading branch information
bicknellr committed Feb 9, 2023
1 parent b731bb5 commit b7b01c0
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 329 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-ravens-drop.md
@@ -0,0 +1,5 @@
---
'@lit-labs/analyzer': minor
---

JSDoc types in TS files now have no effect on the analyzer's output, matching TS itself.
7 changes: 1 addition & 6 deletions packages/labs/analyzer/src/lib/types.ts
Expand Up @@ -60,13 +60,8 @@ export const getTypeForNode = (
node: ts.Node,
analyzer: AnalyzerInterface
): Type => {
// Since getTypeAtLocation will return `any` for an untyped node, to support
// jsdoc @type for JS (TBD), we look at the jsdoc type first.
const jsdocType = ts.getJSDocType(node);
return getTypeForType(
jsdocType
? analyzer.program.getTypeChecker().getTypeFromTypeNode(jsdocType)
: analyzer.program.getTypeChecker().getTypeAtLocation(node),
analyzer.program.getTypeChecker().getTypeAtLocation(node),
node,
analyzer
);
Expand Down

0 comments on commit b7b01c0

Please sign in to comment.