Skip to content
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

Chapter 9 - how to import other TypeScript modules? #175

Open
fuhrmanator opened this issue Sep 26, 2021 · 0 comments
Open

Chapter 9 - how to import other TypeScript modules? #175

fuhrmanator opened this issue Sep 26, 2021 · 0 comments

Comments

@fuhrmanator
Copy link

fuhrmanator commented Sep 26, 2021

In the example in Chapter 9, a third-party JavaScript module is imported (reused) in the TypeScript.

What about when you want to make your own separate modules in TypeScript?

I tried to extend the Chapter 9 code with a src/browser/a.ts class that is simply

export class A { /* ... */ }

VS Code wants to import A using classic TypeScript syntax (just after the blockchain elements are imported):

import { Blockchain, Block } from '../lib/bc_transactions.js';
import { A } from 'a';

But when I run the code, I get a errors for importing a -- first it requires a relative URL (so, I make it ./a but then I get an error saying it's looking for a.js).

Is there a clean solution in Chapter 9 for using TypeScript modules? It hardly feels realistic if all of the project is in main.ts.

In the mean time, rather than using a bundler, I'll follow the advice of specifying .js at the end of the import's specification microsoft/TypeScript#27287 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant