-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix incorrect type declarations for constants inside namespaces merged with enums #61946
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
Open
Copilot
wants to merge
12
commits into
main
Choose a base branch
from
copilot/fix-61944
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+225
−0
Open
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
67ff5e3
Initial plan
Copilot e47e4b8
Investigate enum namespace declaration issue in declarations transformer
Copilot 5971e08
Fix enum namespace constants declaration generation
Copilot 64358a2
Fix test to properly check declaration output and remove invalid .d.t…
Copilot bef82cb
Address code review feedback - revert declarations.ts changes and cle…
Copilot a20ae11
Merge branch 'main' into copilot/fix-61944
RyanCavanaugh fbeac57
Merge branch 'main' into copilot/fix-61944
RyanCavanaugh 8a4d556
Run format tool to fix line endings
Copilot 56ded7a
Merge branch 'main' into copilot/fix-61944
RyanCavanaugh 7fb8cdc
Fix lint error in checker.ts parameter comment
Copilot 245f320
Merge branch 'main' into copilot/fix-61944
RyanCavanaugh 6b7aabb
Fix enum constant declaration generation in namespaces
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
tests/baselines/reference/enumNamespaceConstantsDeclaration.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//// [tests/cases/compiler/enumNamespaceConstantsDeclaration.ts] //// | ||
|
||
//// [enumNamespaceConstantsDeclaration.ts] | ||
// Test for constant declarations inside namespace merged with enum | ||
enum Foo { | ||
bar | ||
} | ||
namespace Foo { | ||
export const baz = Foo.bar; | ||
} | ||
|
||
// Multiple enum members | ||
enum MyEnum { | ||
First = 1, | ||
Second = 2 | ||
} | ||
namespace MyEnum { | ||
export const value1 = MyEnum.First; | ||
export const value2 = MyEnum.Second; | ||
} | ||
|
||
// String enum | ||
enum StringEnum { | ||
Option1 = "option1", | ||
Option2 = "option2" | ||
} | ||
namespace StringEnum { | ||
export const selected = StringEnum.Option1; | ||
} | ||
|
||
//// [enumNamespaceConstantsDeclaration.js] | ||
// Test for constant declarations inside namespace merged with enum | ||
var Foo; | ||
(function (Foo) { | ||
Foo[Foo["bar"] = 0] = "bar"; | ||
})(Foo || (Foo = {})); | ||
(function (Foo) { | ||
Foo.baz = Foo.bar; | ||
})(Foo || (Foo = {})); | ||
// Multiple enum members | ||
var MyEnum; | ||
(function (MyEnum) { | ||
MyEnum[MyEnum["First"] = 1] = "First"; | ||
MyEnum[MyEnum["Second"] = 2] = "Second"; | ||
})(MyEnum || (MyEnum = {})); | ||
(function (MyEnum) { | ||
MyEnum.value1 = MyEnum.First; | ||
MyEnum.value2 = MyEnum.Second; | ||
})(MyEnum || (MyEnum = {})); | ||
// String enum | ||
var StringEnum; | ||
(function (StringEnum) { | ||
StringEnum["Option1"] = "option1"; | ||
StringEnum["Option2"] = "option2"; | ||
})(StringEnum || (StringEnum = {})); | ||
(function (StringEnum) { | ||
StringEnum.selected = StringEnum.Option1; | ||
})(StringEnum || (StringEnum = {})); | ||
|
||
|
||
//// [enumNamespaceConstantsDeclaration.d.ts] | ||
declare enum Foo { | ||
bar = 0 | ||
} | ||
declare namespace Foo { | ||
const baz = Foo.bar; | ||
} | ||
declare enum MyEnum { | ||
First = 1, | ||
Second = 2 | ||
} | ||
declare namespace MyEnum { | ||
const value1 = MyEnum.First; | ||
const value2 = MyEnum.Second; | ||
} | ||
declare enum StringEnum { | ||
Option1 = "option1", | ||
Option2 = "option2" | ||
} | ||
declare namespace StringEnum { | ||
const selected: any; | ||
} | ||
|
||
|
||
!!!! File enumNamespaceConstantsDeclaration.d.ts differs from original emit in noCheck emit | ||
//// [enumNamespaceConstantsDeclaration.d.ts] | ||
=================================================================== | ||
--- Expected The full check baseline | ||
+++ Actual with noCheck set | ||
@@ -16,6 +16,6 @@ | ||
Option1 = "option1", | ||
Option2 = "option2" | ||
} | ||
declare namespace StringEnum { | ||
- const selected: any; | ||
+ const selected = StringEnum.Option1; | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/baselines/reference/enumNamespaceConstantsDeclaration.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//// [tests/cases/compiler/enumNamespaceConstantsDeclaration.ts] //// | ||
|
||
=== enumNamespaceConstantsDeclaration.ts === | ||
// Test for constant declarations inside namespace merged with enum | ||
enum Foo { | ||
>Foo : Symbol(Foo, Decl(enumNamespaceConstantsDeclaration.ts, 0, 0), Decl(enumNamespaceConstantsDeclaration.ts, 3, 1)) | ||
|
||
bar | ||
>bar : Symbol(Foo.bar, Decl(enumNamespaceConstantsDeclaration.ts, 1, 10)) | ||
} | ||
namespace Foo { | ||
>Foo : Symbol(Foo, Decl(enumNamespaceConstantsDeclaration.ts, 0, 0), Decl(enumNamespaceConstantsDeclaration.ts, 3, 1)) | ||
|
||
export const baz = Foo.bar; | ||
>baz : Symbol(baz, Decl(enumNamespaceConstantsDeclaration.ts, 5, 16)) | ||
>Foo.bar : Symbol(bar, Decl(enumNamespaceConstantsDeclaration.ts, 1, 10)) | ||
>Foo : Symbol(Foo, Decl(enumNamespaceConstantsDeclaration.ts, 0, 0), Decl(enumNamespaceConstantsDeclaration.ts, 3, 1)) | ||
>bar : Symbol(bar, Decl(enumNamespaceConstantsDeclaration.ts, 1, 10)) | ||
} | ||
|
||
// Multiple enum members | ||
enum MyEnum { | ||
>MyEnum : Symbol(MyEnum, Decl(enumNamespaceConstantsDeclaration.ts, 6, 1), Decl(enumNamespaceConstantsDeclaration.ts, 12, 1)) | ||
|
||
First = 1, | ||
>First : Symbol(MyEnum.First, Decl(enumNamespaceConstantsDeclaration.ts, 9, 13)) | ||
|
||
Second = 2 | ||
>Second : Symbol(MyEnum.Second, Decl(enumNamespaceConstantsDeclaration.ts, 10, 14)) | ||
} | ||
namespace MyEnum { | ||
>MyEnum : Symbol(MyEnum, Decl(enumNamespaceConstantsDeclaration.ts, 6, 1), Decl(enumNamespaceConstantsDeclaration.ts, 12, 1)) | ||
|
||
export const value1 = MyEnum.First; | ||
>value1 : Symbol(value1, Decl(enumNamespaceConstantsDeclaration.ts, 14, 16)) | ||
>MyEnum.First : Symbol(First, Decl(enumNamespaceConstantsDeclaration.ts, 9, 13)) | ||
>MyEnum : Symbol(MyEnum, Decl(enumNamespaceConstantsDeclaration.ts, 6, 1), Decl(enumNamespaceConstantsDeclaration.ts, 12, 1)) | ||
>First : Symbol(First, Decl(enumNamespaceConstantsDeclaration.ts, 9, 13)) | ||
|
||
export const value2 = MyEnum.Second; | ||
>value2 : Symbol(value2, Decl(enumNamespaceConstantsDeclaration.ts, 15, 16)) | ||
>MyEnum.Second : Symbol(Second, Decl(enumNamespaceConstantsDeclaration.ts, 10, 14)) | ||
>MyEnum : Symbol(MyEnum, Decl(enumNamespaceConstantsDeclaration.ts, 6, 1), Decl(enumNamespaceConstantsDeclaration.ts, 12, 1)) | ||
>Second : Symbol(Second, Decl(enumNamespaceConstantsDeclaration.ts, 10, 14)) | ||
} | ||
|
||
// String enum | ||
enum StringEnum { | ||
>StringEnum : Symbol(StringEnum, Decl(enumNamespaceConstantsDeclaration.ts, 16, 1), Decl(enumNamespaceConstantsDeclaration.ts, 22, 1)) | ||
|
||
Option1 = "option1", | ||
>Option1 : Symbol(StringEnum.Option1, Decl(enumNamespaceConstantsDeclaration.ts, 19, 17)) | ||
|
||
Option2 = "option2" | ||
>Option2 : Symbol(StringEnum.Option2, Decl(enumNamespaceConstantsDeclaration.ts, 20, 24)) | ||
} | ||
namespace StringEnum { | ||
>StringEnum : Symbol(StringEnum, Decl(enumNamespaceConstantsDeclaration.ts, 16, 1), Decl(enumNamespaceConstantsDeclaration.ts, 22, 1)) | ||
|
||
export const selected = StringEnum.Option1; | ||
>selected : Symbol(selected, Decl(enumNamespaceConstantsDeclaration.ts, 24, 16)) | ||
>StringEnum.Option1 : Symbol(Option1, Decl(enumNamespaceConstantsDeclaration.ts, 19, 17)) | ||
>StringEnum : Symbol(StringEnum, Decl(enumNamespaceConstantsDeclaration.ts, 16, 1), Decl(enumNamespaceConstantsDeclaration.ts, 22, 1)) | ||
>Option1 : Symbol(Option1, Decl(enumNamespaceConstantsDeclaration.ts, 19, 17)) | ||
} |
99 changes: 99 additions & 0 deletions
99
tests/baselines/reference/enumNamespaceConstantsDeclaration.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//// [tests/cases/compiler/enumNamespaceConstantsDeclaration.ts] //// | ||
|
||
=== enumNamespaceConstantsDeclaration.ts === | ||
// Test for constant declarations inside namespace merged with enum | ||
enum Foo { | ||
>Foo : Foo | ||
> : ^^^ | ||
|
||
bar | ||
>bar : Foo.bar | ||
> : ^^^^^^^ | ||
} | ||
namespace Foo { | ||
>Foo : typeof Foo | ||
> : ^^^^^^^^^^ | ||
|
||
export const baz = Foo.bar; | ||
>baz : Foo.bar | ||
> : ^^^^^^^ | ||
>Foo.bar : Foo | ||
> : ^^^ | ||
>Foo : typeof Foo | ||
> : ^^^^^^^^^^ | ||
>bar : Foo | ||
> : ^^^ | ||
} | ||
|
||
// Multiple enum members | ||
enum MyEnum { | ||
>MyEnum : MyEnum | ||
> : ^^^^^^ | ||
|
||
First = 1, | ||
>First : MyEnum.First | ||
> : ^^^^^^^^^^^^ | ||
>1 : 1 | ||
> : ^ | ||
|
||
Second = 2 | ||
>Second : MyEnum.Second | ||
> : ^^^^^^^^^^^^^ | ||
>2 : 2 | ||
> : ^ | ||
} | ||
namespace MyEnum { | ||
>MyEnum : typeof MyEnum | ||
> : ^^^^^^^^^^^^^ | ||
|
||
export const value1 = MyEnum.First; | ||
>value1 : MyEnum.First | ||
> : ^^^^^^^^^^^^ | ||
>MyEnum.First : MyEnum.First | ||
> : ^^^^^^^^^^^^ | ||
>MyEnum : typeof MyEnum | ||
> : ^^^^^^^^^^^^^ | ||
>First : MyEnum.First | ||
> : ^^^^^^^^^^^^ | ||
|
||
export const value2 = MyEnum.Second; | ||
>value2 : MyEnum.Second | ||
> : ^^^^^^^^^^^^^ | ||
>MyEnum.Second : MyEnum.Second | ||
> : ^^^^^^^^^^^^^ | ||
>MyEnum : typeof MyEnum | ||
> : ^^^^^^^^^^^^^ | ||
>Second : MyEnum.Second | ||
> : ^^^^^^^^^^^^^ | ||
} | ||
|
||
// String enum | ||
enum StringEnum { | ||
>StringEnum : StringEnum | ||
> : ^^^^^^^^^^ | ||
|
||
Option1 = "option1", | ||
>Option1 : StringEnum.Option1 | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
>"option1" : "option1" | ||
> : ^^^^^^^^^ | ||
|
||
Option2 = "option2" | ||
>Option2 : StringEnum.Option2 | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
>"option2" : "option2" | ||
> : ^^^^^^^^^ | ||
} | ||
namespace StringEnum { | ||
>StringEnum : typeof StringEnum | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
||
export const selected = StringEnum.Option1; | ||
>selected : any | ||
>StringEnum.Option1 : StringEnum.Option1 | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
>StringEnum : typeof StringEnum | ||
> : ^^^^^^^^^^^^^^^^^ | ||
>Option1 : StringEnum.Option1 | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/cases/compiler/enumNamespaceConstantsDeclaration.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
declare enum Foo { | ||
bar = 0 | ||
} | ||
declare namespace Foo { | ||
const baz = bar; | ||
} | ||
declare enum MyEnum { | ||
First = 1, | ||
Second = 2 | ||
} | ||
declare namespace MyEnum { | ||
const value1 = First; | ||
const value2 = Second; | ||
} | ||
declare enum StringEnum { | ||
Option1 = "option1", | ||
Option2 = "option2" | ||
} | ||
declare namespace StringEnum { | ||
const selected: any; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.