-
Notifications
You must be signed in to change notification settings - Fork 12.9k
avoid add missing member in declaration file #29493
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
avoid add missing member in declaration file #29493
Conversation
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.
Use getSourceFileOfNode(node).isDeclarationFile
src/compiler/utilities.ts
Outdated
@@ -1698,6 +1698,10 @@ namespace ts { | |||
return !!node && !!(node.flags & NodeFlags.JSDoc); | |||
} | |||
|
|||
export function isInDeclarationFile(node: Node | undefined): boolean { |
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 isn't a correct check. Ambient nodes can occur inside non-declaration files, e.g. in
declare namespace X {
}
blocks
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.
Probably worth remembering that the original issue is specifically about the stdlib files (which generally shouldn't be editable), and not all .d.ts files. Adding more props to declarations within your own project are fine - but adding props to a stdlib or node_modules sourced declaration is prooooobably wrong. Well, it's wrong unless the addition is done by making an augmentation in the current file 😛
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.
Probably only check file in node_modules?
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.
We should really apply a concrete notion of where a .d.ts file "came from" - lib, upstream composite project, node_modules/types, or a local "hand-authored" .d.ts file, only the last of which is a valid rename target
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.
isSourceFileFromExternalLibrary
is that not good indication?
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.
Sounds like exactly what we want 😃
47f49a8
to
53b7e9d
Compare
53b7e9d
to
bf42f5b
Compare
Fixes #29482