Skip to content

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

@fuhrmanator

Description

@fuhrmanator

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions