-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Merged Declarations for Classes and Interfaces #3333
Merged Declarations for Classes and Interfaces #3333
Conversation
This reverts commit 813d227.
Hi @aozgaa, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
@@ -135,6 +135,26 @@ module ts { | |||
return node.name ? declarationNameToString(node.name) : getDeclarationName(node); | |||
} | |||
|
|||
/* internal */ |
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 exported, so you don't need this.
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.
Changed.
@@ -144,7 +163,10 @@ module ts { | |||
let symbol: Symbol; | |||
if (name !== undefined) { | |||
symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); | |||
if (symbol.flags & excludes) { | |||
|
|||
// Check for declarations node cannot be merged with. |
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.
Nit: Can you put single quotes around node
just so this reads easier? Thanks!
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.
Changed.
@@ -1473,7 +1473,8 @@ module ts { | |||
EnumMemberExcludes = Value, | |||
FunctionExcludes = Value & ~(Function | ValueModule), | |||
ClassExcludes = (Value | Type) & ~ValueModule, | |||
InterfaceExcludes = Type & ~Interface, | |||
AmbientClassExcludes = (Value | Type) & ~(ValueModule | Interface), |
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.
If you do the other change I suggested (https://github.com/Microsoft/TypeScript/pull/3333/files#r31552915), then this goes away, and ClassExcludes becomes (Value | Type) & ~(ValueModule | Interface)
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 not just letting classes and interfaces merge, and reporting an error later on in CheckClassDeclaration for instance if the class is not ambient? just like we do with merging order for module/class and module/class being in different files.
*/ | ||
function hasNonAmbientClass(symbol: Symbol): boolean { | ||
return symbol && forEach(symbol.declarations, (element: Declaration) => { | ||
return element.kind === SyntaxKind.ClassDeclaration && !(element.flags & NodeFlags.Ambient); |
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.
should not this be inAmbientContext instead?
👍 |
Thoughs @mhegazy, @ahejlsberg ? |
@@ -202,11 +211,11 @@ namespace ts { | |||
symbol = hasProperty(symbolTable, name) | |||
? symbolTable[name] | |||
: (symbolTable[name] = createSymbol(SymbolFlags.None, name)); | |||
|
|||
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.
Remove the leading space if you get the chance.
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.
fixed.
There are apparently some issues with the build - you probably need to fix up baselines that don't agree with the merge. |
@DanielRosenwasser The error codes needed to be changed as part of merging the upstream fixes and this broke some of the baselines. No other errors occurred. They've been added now :). |
👍 |
1 similar comment
👍 |
Merged Declarations for Classes and Interfaces
This should be added to the |
How does this work with imported module? When I have like this application.ts import * as amqp from 'amqplib';
// I want to merge declaration with `interface amqp.ExchangeOptions`
interface ExchangeOptions {
'x-recent-history-length' : number;
}
interface amqp.ExchangeOptions {
'x-recent-history-length' : number;
} Which one should work? |
Neither one of those would work here. You'd need to do the following: declare module 'amqplib' {
interface ExchangeOptions {
'x-recent-history-length' : number;
}
} |
Thanks! |
@JsonFreeman Is there an equivalent for external modules? |
This doesn't appear to be possible but feels like it should: interface Foo {
readonly name: string
}
class Foo {
constructor(name: string) {
this.name = name; //error
}
} |
@nbransby thanks, I'll open an issue for you. |
This implements the proposal in #3332.