-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
@typedef: Improve error spans from declaration emit #42501
@typedef: Improve error spans from declaration emit #42501
Conversation
This is a proof-of-concept fix. I think it could be expanded for all of jsdoc, but I only set it up for jsdoc type aliases. It could use a lot of polish too.
Remove trueErrorNode
@@ -4699,7 +4700,7 @@ namespace ts { | |||
|
|||
function createMappedTypeNodeFromType(type: MappedType) { | |||
Debug.assert(!!(type.flags & TypeFlags.Object)); | |||
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined; | |||
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyKeyword | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by deprecation fix
@@ -6183,7 +6184,7 @@ namespace ts { | |||
tracker: { | |||
...oldcontext.tracker, | |||
trackSymbol: (sym, decl, meaning) => { | |||
const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases*/ false); | |||
const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases*/ false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by case fix
/** @typedef {import('./base')} BaseFactory */ | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should add a Exported type alias 'BaseFactory' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base".
formatted error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the general case, yes -- in this case, with the import('./base')
sitting right there, it's not so valuable.
!!! error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'. | ||
/** @enum {import('./base')} BaseFactoryFactoryRegistry */ | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one seems less like the other two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhhhhhhhh yeah, I didn't notice that. It should be ${0}=BaseFactoryFactoryRegistry, ${1}='Base'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look at these two issues.
/** @typedef {import('./base')} BaseFactory */ | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the general case, yes -- in this case, with the import('./base')
sitting right there, it's not so valuable.
!!! error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'. | ||
/** @enum {import('./base')} BaseFactoryFactoryRegistry */ | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhhhhhhhh yeah, I didn't notice that. It should be ${0}=BaseFactoryFactoryRegistry, ${1}='Base'
.
Since enums don't have a name property, you *have* to call `getNameOfDeclaration` to go looking through the AST for one.
Done. Improving the error forced me to fix the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This is a proof-of-concept fix. I think it could be expanded for all of jsdoc, but I only set it up for jsdoc type aliases.
It could use a lot of polish too.
(The silly prefix on
trueErrorNode
should remind me of that.)Fixes rest of #41672 for jsdoc type aliases:
@typedef
,@callback
,@enum
. But not for commonplace tags like@param
,@return
,@type
, etc.