question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support merging classes and modules across files

See original GitHub issue

I currently have a setup something like this: A.ts

module mod {
  export class A {
  }
}

B.ts

/// <reference path="A.ts" />
module mod.A {
  export class B extends A {
  }
}

But I’m getting the error in B.ts: A module declaration cannot be in a different file from a class or function with which it is merged. It works fine, however, if the declarations are in the same file: Playground

In my compiler options, I’m concatenating all the files together in the output, so shouldn’t it not matter that they’re in different source files? Even if the output wasn’t concatenated, I don’t understand how the declarations being in separate files changes anything. Basically, the structure I’m going for is that A is going to have a lot of subclasses, and I wanted to have them all be in a module also called A. It just makes sense organizationally to me.

Why is this not allowed? Is there a way around it?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
dev-mrajcommented, Nov 8, 2016

+1

i’d like to have this, to just es6 output with typescript so then i can use clousercompiler to optimize that for es5

0reactions
terrible-codercommented, May 5, 2020

I kinda need this feature too. Any recent updates? Also, what would the import statements look like for importing these “distributed” class/namespace declarations?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combine classes from multiple files into single namespace in ...
Combine classes from multiple files into single namespace in typescript ; from './AbstractCommand'; import · Commands ; from './GoogleCommand'; ...
Read more >
Documentation - Declaration Merging - TypeScript
Currently, classes can not merge with other classes or with variables. For information on mimicking class merging, see the Mixins in TypeScript section....
Read more >
Module Augmentation in TypeScript - DigitalOcean
The answer is, TypeScript doesn't allow merging between classes so we can't create two or more classes with the same name. If you...
Read more >
Combining modules - IBM
Generalized Object File Format (GOFF) object modules, for example those ... GOFF supports long external names up to 32767 bytes, multiple text classes, ......
Read more >
Merging Modules - open-std.org
2 The module interface may be split across multiple files, if desired. ... 2 The merged proposal supports global module fragments, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found