Fix incorrect import/export clashes. - #38730
Conversation
A new error in Typescript 3.7 forbids name clashes like this:
```ts
import { X } from 'y'
export interface X { }
```
Previously they were incorrectly allowed. Typescript 3.7 will have a
beta version in the next day or two. In the meantime you can try
typescript@next -- the nightly build -- to see these errors.
|
Since these are pretty straightforward changes, and the failures cluttering up our DT tests during the 3.7 release, I'm going to merge them today barring any really bad issues. @andrewbranch, who merged the original PR. |
| import { Azure as Az } from 'azure-sb'; | ||
| import Dictionary = Az.ServiceBus.Dictionary; | ||
|
|
||
| export namespace Azure.ServiceBus.Results { |
There was a problem hiding this comment.
Huh. This was merging with Azure from 'azure-sb', right? It kind of feels like that should still be allowed? The issue that the microsoft/TypeScript#31231 was supposed to fix was when an imported type completely shadowed an exported type. If they merge, and exports from both are accessible, is that a problem?
There was a problem hiding this comment.
I don't think it was merging it. I'll test with an older version of Typescript.
There was a problem hiding this comment.
Wouldn’t it have to in order to resolve Dictionary?
There was a problem hiding this comment.
So, after testing, they do not merge:
// @Filename: second.ts
export namespace Azure.ServiceBus {
export interface Dictionary<T> {
[k: string]: T
}
}
export namespace Azure.ServiceBus.Results {
export interface AcsTokenResponse extends Dictionary<string | Dictionary<string>> {
WrapAccessToken: Dictionary<string>;
WrapAccessTokenExpiresIn: Dictionary<string>;
}
export interface AcsTokenResult {
parse(acsTokenQueryString: string): AcsTokenResponse;
}
}
// @Filename: first.ts
import { Azure } from './second';
import Dictionary = Azure.ServiceBus.Dictionary;
export namespace Azure.ServiceBus.Results {
export interface Id {
d: Dictionary<number>
}
}
// @Filename: welove.ts
import { Azure as A } from './first'
import { Azure as B } from './second'
let x: A.ServiceBus.Results./*1*/
let y: B.ServiceBus.Results./*2*/At /1/, you see only Id and at /2/ you see only AcsTokenResponse and Result. And you can't import both with the name Azure.
There was a problem hiding this comment.
Sorry, was replying to the previous comment.
The old behaviour was that references to Azure referred to the imported symbol. The module exports a namespace named Azure too, but that's (1) different (2) not referred to inside the module.
There was a problem hiding this comment.
🤦♂
I completely missed that the old file had import Dictionary = Azure.ServiceBus.Dictionary;. I only saw it in your added changes, so I thought that previously, Dictionary was being resolved against the current namespace scope, which would have implied that it was merged somehow. That was the source of my confusion.
This seems fine. Thanks for investigating and unconfusing me.
|
@sandersn Thank you for submitting this PR! 🔔 @joelhegg @Azure @huan086 @mathieudutour @AndrewVetovitz @donnut @mdekrey @mrdziuban @sbking @afharo @teves-castro @1M0reBug @hojberg @samsonkeung @angeloocana @raynerd @moshensky @ethanresnick @leighman @deftomat @deptno @blimusiek @biern @rayhaneh @rgm @drewwyatt @jottenlips @minitesh @Krantisinh @pirix-gh @brekk @Nemo108 @jituanlin @iRoachie @timwangdev @robertying @forabi @kaoDev @johnnyreilly @CarsonF @aikoven @LKay @bancek @alsiola @tehbi4 @huwmartin @m-b-davis @Reggino @maddijoyce @smifun @mshaaban088 @esetnik @bwlt @mrsekut @keenondrums @tomasz-zablocki @voxmatt @alloy @ckknight @renanmav - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
| import { Azure as Az } from 'azure-sb'; | ||
| import Dictionary = Az.ServiceBus.Dictionary; | ||
|
|
||
| export namespace Azure.ServiceBus.Results { |
There was a problem hiding this comment.
🤦♂
I completely missed that the old file had import Dictionary = Azure.ServiceBus.Dictionary;. I only saw it in your added changes, so I thought that previously, Dictionary was being resolved against the current namespace scope, which would have implied that it was merged somehow. That was the source of my confusion.
This seems fine. Thanks for investigating and unconfusing me.
|
BenchmarkPR is going to time out since so many packages changed; feel free to merge any time |
|
Your confusion makes sense; I think the authors of the package thought the namespaces were going to merge too. |
|
I just published |
|
I just published |
|
I just published |
|
I just published |
|
I just published |
|
I just published |
|
I just published |
|
I just published |
|
I just published |
@RyanCavanaugh is it possible to trigger a v7 publish? |
A new error in Typescript 3.7 forbids name clashes like this:
Previously they were incorrectly allowed. Typescript 3.7 will have a
beta version in the next day or two. In the meantime you can try
typescript@next -- the nightly build -- to see these errors.
There were generally two fixes
I also updated one dependency: ts-toolbelt, which recently shipped a fix for this error.
There are 3 dependencies that are still broken: react-dnd, protractor and three. I'll look at those next and send a PR to those projects if necessary.