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.

TS: Using an exported class declaration locally in a type annotation

See original GitHub issue

The following snippet…

export class Foo<T = any> {};
let foo: Foo = new Foo();
let foo: Foo<any> = new Foo();

…compiles to…

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); class Foo {} exports.Foo = Foo;;
let foo = exports.Foo = new Foo();
let foo = new Foo();

Notice how exports.Foo is being re-assigned. 😳

  • sucrase v3.9.4
  • node v11.3.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alangpiercecommented, Jan 11, 2019

Yikes, thanks for the report. Here’s a slightly simpler test case:

export class Foo {}
let foo: Foo = new Foo();

Playground link

0reactions
aleclarsoncommented, Jan 11, 2019

Nope, I say go for it. 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Modules - TypeScript
Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword. StringValidator.ts. ts. export...
Read more >
Issue - GitHub
From what I've read in this issue, I just need to import the RedBN type to my example.ts ? But RedBN was declare...
Read more >
How to use class returned by a function in type annotations?
When you declare a class with the class keyword, the compiler knows two things. That in the current scope there is a value...
Read more >
A quick introduction to “Type Declaration” files and adding ...
In the Module System lesson, we learned how to share type declaration between modules using import/export statements. You can import a type ......
Read more >
TypeScript - Modules - TutorialsTeacher
ts is a module which contains two variables and a class definition. The age variable and the Employee class are prefixed with the...
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