-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Allow all private declarations to be emitted in declaration output #23351
Allow all private declarations to be emitted in declaration output #23351
Conversation
7924e42
to
4bfefba
Compare
looks like this is something i need it lol |
f42e713
to
aa71540
Compare
@sheetalkamat Would you like to give this a review? The GH UI won't let me add people T.T |
@@ -107,3 +107,4 @@ declare const FilteredThing_base: { | |||
export declare class FilteredThing extends FilteredThing_base { | |||
match(path: string): boolean; | |||
} | |||
export {}; |
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.
where is this coming from ?
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.
declare const FilteredThing_base: {
new (...args: any[]): { new (...args: any[]): {
match(path: string): boolean; match(path: string): boolean;
thing: number; thing: number;
}; };
} & typeof Unmixed; } & typeof Unmixed;
doesn't exist at runtime (we just emit it so we have a thing for the extends
clause) - this scopes the file so it's actually private.
} | ||
declare class D extends C { | ||
} | ||
export {}; |
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.
unwanted export {}
?
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.
declare class D extends C {
}
isn't exported (but it used in C
). To keep it that way, we need to emit export {}
to fix the scoping of the 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.
But there is export declare class C so export {} is not needed. https://github.com/Microsoft/TypeScript/pull/23351/files/aa71540de296549fa21676bee32349088189fa35#diff-880f6135e59878559ff8c952515ec352R43
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 mostly all of these scenarios the error you are fixing is public -> private so you are just adding private types to file, the scoping of file shouldnt affect by any of these additions.
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.
No, it is. Our .d.ts
scope rules are odd - any export
statement makes it a module, but (separately from that) in a .d.ts
unless there's an export assignment or export declaration, every top-level declaration is seen at exported, even without an explicit export modifier. AFAIK this was a decision made to reduce the noise in writing declaration files a long time ago.
does can fix this code too? and function fn(inputRegExp: RegExp, input: string){}
namespace fn
{
export const S = Symbol('fn');
}
// @ts-ignore
const fn2 = fn;
export = fn2;
|
src/compiler/checker.ts
Outdated
@@ -3679,7 +3684,14 @@ namespace ts { | |||
return typeParameterNodes; | |||
} | |||
|
|||
function symbolToTypeNode(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags): TypeQueryNode | TypeReferenceNode | ImportTypeNode { | |||
function getAccessTypeSplitNode(top: IndexedAccessTypeNode): IndexedAccessTypeNode { |
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.
What does getAccessTypeSplitNode
mean? The name is quite opaque, so a doc comment would be helpful.
@@ -1171,7 +1156,7 @@ namespace ts { | |||
} | |||
|
|||
function ensureAccessor(node: AccessorDeclaration): PropertyDeclaration | undefined { | |||
const accessors = getAllAccessorDeclarations((node.parent as ClassDeclaration).members, node); | |||
const accessors = resolver.getAllAccessorDeclarations(node); |
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.
Why was this needed? If AccessorDeclaration
is now synthetic, you could just call getParseTreeNode
(which you are still doing in the version in the checker) and use the existing getAllAccessorDeclarations
in utilities.ts.
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.
Computed property names have differing names and need to merge - the only way to do so is via their symbol.
@rbuckton anything else? |
Followup to #22798 the allows any top-level declaration to be made visible if it is required to properly emit another emitted declaration.
Fixes #23127
Makes #15058 redundant.
As a side effect, because we now consider these declarations "visible", we now sometimes use their names in the
type
baselines.