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 parsing import.meta #22861

Closed
justinfagnani opened this issue Mar 24, 2018 · 4 comments
Closed

Support parsing import.meta #22861

justinfagnani opened this issue Mar 24, 2018 · 4 comments
Assignees
Labels
Domain: ES Modules The issue relates to import/export style module behavior ES Next New featurers for ECMAScript (a.k.a. ESNext) Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@justinfagnani
Copy link

import.meta does not parse. import.meta is stage 3 and implemented in Chrome/V8. See the TC39 proposal here: https://github.com/tc39/proposal-import-meta

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms:
import.meta

Code

const u = import.meta.url;

Expected behavior:

import.meta at least parses when output is esnext.

For downlevel emit, specific meta-properties like import.meta.url, would presumably have to be handled differently. For import.meta.url a project could be given a base URL from which module base URLs are calculated from given their path.

Or a custom transform could be used. Any solution requires that import.meta parse though.

Actual behavior:

Syntax error.

Playground Link:

http://www.typescriptlang.org/play/#src=const%20i%20%3D%20import.meta.url%3B

Related Issues:

@DanielRosenwasser DanielRosenwasser added the ES Next New featurers for ECMAScript (a.k.a. ESNext) label Mar 25, 2018
@DanielRosenwasser
Copy link
Member

What would the type be? any? Changing it after the fact would be breaking.

@DanielRosenwasser DanielRosenwasser added the Domain: ES Modules The issue relates to import/export style module behavior label Mar 25, 2018
@justinfagnani
Copy link
Author

As far as I know, import.meta is host defined, so by default I don't think it could be anything other than object. The node and dom typings should define import.meta.url as string.

@DanielRosenwasser DanielRosenwasser self-assigned this Mar 25, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 26, 2018

As far as I know, import.meta is host defined, so by default I don't think it could be anything other than object. The node and dom typings should define import.meta.url as string.

I would say the type should be:

interface ImportMeta {
    [x: string]: any;
}

This allows say node to define some well-known import.meta fields.

@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 26, 2018
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Mar 26, 2018
@justinfagnani
Copy link
Author

I guess there are two options:

interface ImportMeta {
    [x: string]: any;
}

and

interface ImportMeta {
}

The latter would require that you import some typings that define specific fields, or cast your way out of an error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: ES Modules The issue relates to import/export style module behavior ES Next New featurers for ECMAScript (a.k.a. ESNext) Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants