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

Add import type shorthand syntax #2890

Closed
wants to merge 1 commit into from

Conversation

jeffmo
Copy link
Contributor

@jeffmo jeffmo commented Nov 24, 2016

Currently, importing both types and values from the same modules requires two statements with most of the same boilerplate in both statements:

import {someValue} from "blah";
import type {someType} from "blah";
import typeof {someOtherValue} from "blah";

This gets tediously repetitive and adds a lot of boilerplate to JS files.

This PR implements a proposal from @leebyron to add an additional type/typeof shorthand to vanilla-import statements for individual named specifiers so that the above code can be written more concisely as:

import {
  someValue,
  type someType,
  typeof someOtherValue,
} from "blah";

This PR does not remove import type or import typeof statements -- it only adds the shorthand to vanilla import statements.

Note also that I've banned usage of the shorthand with import type and import typeof statements since the need for shorthand in those is far less common and often combinatorially confusing:

import type { type T } from "foo"; // <-- parse error
import typeof { type T } from "foo"; // <-- parse error

@jeffmo jeffmo force-pushed the import_type_shorthand branch 2 times, most recently from 888f10a to e343f99 Compare November 24, 2016 18:22
@facebook-github-bot
Copy link
Contributor

@jeffmo has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@CodyReichert
Copy link

Nothing super constructive, but I'm really looking forward to this. Nice work!

@facebook-github-bot
Copy link
Contributor

@jeffmo has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jeffmo has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@jeffmo has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

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

Successfully merging this pull request may close these issues.

None yet

4 participants