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
base: master
from

Conversation

Projects
None yet
3 participants
@jeffmo
Copy link
Member

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 jeffmo:import_type_shorthand branch 2 times, most recently from 888f10a to e343f99 Nov 24, 2016

@jeffmo jeffmo force-pushed the jeffmo:import_type_shorthand branch from e343f99 to d20ef7f Dec 2, 2016

@facebook-github-bot

This comment has been minimized.

Copy link

facebook-github-bot commented Dec 2, 2016

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

@CodyReichert

This comment has been minimized.

Copy link

CodyReichert commented Dec 2, 2016

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

@jeffmo jeffmo force-pushed the jeffmo:import_type_shorthand branch from d20ef7f to b56e856 Dec 24, 2016

@facebook-github-bot

This comment has been minimized.

Copy link

facebook-github-bot commented Dec 24, 2016

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

@jeffmo jeffmo force-pushed the jeffmo:import_type_shorthand branch from b56e856 to 2550c0d Dec 24, 2016

@facebook-github-bot

This comment has been minimized.

Copy link

facebook-github-bot commented Dec 24, 2016

@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

This comment has been minimized.

Copy link

facebook-github-bot commented Dec 24, 2016

@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