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

Typescript: importing with /// <reference path="" /> doesn't work #252

Open
johnfn opened this issue Sep 18, 2018 · 4 comments
Open

Typescript: importing with /// <reference path="" /> doesn't work #252

johnfn opened this issue Sep 18, 2018 · 4 comments

Comments

@johnfn
Copy link

johnfn commented Sep 18, 2018

Issue description or question

When I use Quokka.js on a TypeScript file, if it has /// references, quokka won't know to pull in those files, meaning it can't resolve any objects in external files.

Sample code

a.ts

/// <reference path="b.ts" />

b;

b.ts

let b = 5;

Quokka.js Console Output

​​b is not defined​​

Code editor version

Visual Studio Code v1.27.1

OS name and version

macOS high sierra

@ArtemGovorov
Copy link
Member

/// reference is not importing anything in runtime. It serves as a declaration of dependency between files. The a.ts file gets compiled to the following JavaScript:

/// <reference path="b.ts" />
b;

so the error is expected.

In order to import a module you may use import or require, for example

/// <reference path="b.ts" />
import './b'
b;

@johnfn
Copy link
Author

johnfn commented Sep 19, 2018

No, that's not true. Depending on how you have your tsconfig configured, it's possible that TypeScript will concatenate all your source files into a single file (if you use outFile). While it's probably unreasonable to expect quokka to compile every file (even though that is what TS does), it would be nice if reference paths hinted quokka to concatenate the two files together.

Unfortunately imports are not always possible - some projects use outFile and imports will confuse that.

@ArtemGovorov
Copy link
Member

Depending on how you have your tsconfig configured, it's possible that TypeScript will concatenate all your source files into a single file (if you use outFile)

It's only the case if you run TypeScript for the whole project, however I specifically mentioned the scenario when The a.ts file gets compiled .... When a single file is compiled (and that's what Quokka is doing), the /// reference is not affecting the the JavaScript output for the file. Any files imported by the file that Quokka is running on are processed with ts-node (that also compiles file by file and doesn't respect /// references).

Unfortunately imports are not always possible - some projects use outFile and imports will confuse that.

Fair enough, re-opening as a feature request.

@ArtemGovorov ArtemGovorov reopened this Sep 19, 2018
@johnfn
Copy link
Author

johnfn commented Sep 19, 2018

It's only the case if you run TypeScript for the whole project, however I specifically mentioned the scenario when The a.ts file gets compiled ....

If you want to be pedantic, there is no such thing as "single file compilation" in a project with outFile set. It's all or nothing 😉

But yea, seeing this sort of thing would be nice. I actually already bought quokka half with the expectation that this would work (the "try pro" wasn't working for some reason), if that motivates you at all, hehe.

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

No branches or pull requests

2 participants