TypeScript: 3.8 RC Regression? "Individual declarations in merged declaration"

TypeScript Version: 3.8.1-rc and nightly (3.8.0-dev.20200207)

Search Terms: Individual declarations in merged declaration

Code Two files:

// ns.ts
export type Type = {greet: string}

export function hello(input: Type) {
  console.log(input.greet)
}
// use.ts
import * as Greeting from './ns'

export type Greeting = Greeting.Type
export {Greeting}

Expected behavior: Expected that this compiles and users can refer to Greeting as both the type {greet: string} and the namespace of functions/data (just hello in this case). In versions 3.7.5 and 3.8.0-beta, this was OK.

Actual behavior: 3.8.1-rc and current nightly produce these errors:

use.ts:1:13 - error TS2395: Individual declarations in merged declaration 'Greeting' must be all exported or all local.

1 import * as Greeting from './ns'
              ~~~~~~~~

use.ts:3:13 - error TS2395: Individual declarations in merged declaration 'Greeting' must be all exported or all local.

3 export type Greeting = Greeting.Type
              ~~~~~~~~

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

Something that makes this type of thing easy to do would be super appreciated, from this user’s perspective 😃

I haven’t been able to find a good workaround for this at the moment

@andrewbranch I can also confirm my codebase is littered with NamespaceAndType.NamespaceAndType like @danprince mentioned…

Spending a lot of time writing Rectangle.Rectangle and Vector.Vector at the moment and it would be great to chop them down, or at least to know it’s a wontfix.

Every single one of these files is imported like import * as Blah from "./Blah";

image

…which means I write Asset.Asset, Color.Color, Company.Company, etc. a lot!

I guess we accidentally fixed that case, which we had previously accidentally left unfixed, sometime after the beta? Possibly with https://github.com/microsoft/TypeScript/pull/36237? Sorry @DanielRosenwasser, I should have recognized #36237 as a breaking change 😕

@andrewbranch thanks! That worked.

Yes, I believe so. It’s something I wish we could’ve communicated sooner, but the code never should have compiled.