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

Support module specifiers with extensions in editors #920

Closed
kitsonk opened this issue Oct 5, 2018 · 7 comments
Closed

Support module specifiers with extensions in editors #920

kitsonk opened this issue Oct 5, 2018 · 7 comments

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Oct 5, 2018

Mostly this is for tracking purposes.

Currently the TypeScript language services module specifier resolution does not allow extensions as part of the module specifier. The TypeScript team's main argument is that all the main module loaders (AMD, CommonJS, SystemJS and native browser module loaders) support extensionless module resolution and has been the common standard. Add to that the TypeScript is generally a transpiled language means that a module specifier of foo/bar.ts would need to be rewritten to foo/bar.js or maybe foo/bar.mjs or foo/bar.ejs or anything really after transpilation and rewriting module specifiers is a really loaded and complex topic.

@guybedford indicated that Node.js is considering supporting full extension module resolution. I suspect if that is the case, TypeScript would need to reflect that, but that would complicate what needs to be done at design time and what would be reality at run time. It will simply be complicated.

The other challenge that Deno has, is that even if there was a default module resolution with extensions in TypeScript, it is very unlikely that it would support fetching the types of remote modules for consumption in the editor. So while local modules would have type information, remote one would simply be unresolvable.

The only long term solution I see is that there is a language services plugin for Deno, that would provide a different wrap to the language services API for standard TypeScript, that would do the following things:

  • Provide module resolution in line with runtime deno
  • Fetch remote module resources and cache them to make their types available to the editor
  • Provide the current Deno default type library, so that developers don't have to include it manually
@ry
Copy link
Member

ry commented Oct 5, 2018

Other solution: become popular and force the eco system to support us.
Including the extension is correct as this is how its done in the browser.
So it's their bug, not ours -- they'll come around. I'm not very concerned about this.

@rsp
Copy link
Contributor

rsp commented Oct 11, 2018

@ry Re: forcing the eco system to support us - I already started myself ;) few weeks ago I posted a comment about it in a related issue in the TypeScript repo, just so that people know that the current behaviour and syntax highlighting is completely backwards for some runtimes like Deno - Code highlights good code as error and bad code as ok:

I'm sure that eventually the editors will support Deno like they support Node today but I'd like it to happen sooner rather than later, so the more people are vocal about it the better.

@guybedford
Copy link
Contributor

guybedford commented Oct 12, 2018 via email

@rsp
Copy link
Contributor

rsp commented Oct 12, 2018

@guybedford that's good news. I never really understood why transpilers couldn't change the extensions in the first place since they know what they are transpiling anyway (and since import takes a constant string literal so no risk of strings built at runtime, like with require). I am never sure what Node will require with require('./foo') if I have both a directory foo with index.js and foo.js in the same place - add to that multiple extensions to the mix and I'm totally confused.

I see in https://github.com/systemjs/systemjs/blob/2.0.0/docs/system-register.md examples like:

import {b} from './b.js';
export function a() {
  b();
}

so if it's valid in Deno and SystemJS then I guess VS Code and others will follow, hopefully sooner rather than later.

Update: It turns out that VS Code considers js extensions to be fine, only ts extensions to be errors, which is even more confusing than I thought before - see this comment microsoft/TypeScript#11235 (comment)

@kitsonk
Copy link
Contributor Author

kitsonk commented Oct 12, 2018

which is even more confusing than I thought before

Well, it is sort of simple from the TypeScript perspective, .ts code isn't ever designed to be run in a runtime, and then when you try to determine what it will be at runtime it get mind-bogglingly complex. So out of the box, I still agree that TypeScript should prevent people from assuming that .ts will be .ts at runtime. What we need is a literal module resolution mode that is a compiler option.

Because we have the extensionless at the moment, and Node.js is considering changing their module resolution, my opinion is we wait a bit longer and if push comes to shove, I suspect we could submit a PR that meets our needs and champion for it with the core TypeScript team.

@bartlomieju
Copy link
Member

@kitsonk is this issue somehow resolved with your deno_ls_plugin?

@kitsonk
Copy link
Contributor Author

kitsonk commented Feb 12, 2019

Yes and the VScode plugin.

@kitsonk kitsonk closed this as completed Feb 12, 2019
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

5 participants