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

Type-only default+named imports #16

Open
robpalme opened this issue Nov 22, 2021 · 6 comments
Open

Type-only default+named imports #16

robpalme opened this issue Nov 22, 2021 · 6 comments

Comments

@robpalme
Copy link
Collaborator

robpalme commented Nov 22, 2021

Hegel and Flow support type-only imports of the default binding with named bindings like this:

// default import with named import
import type defaultBinding, { otherBinding } from "module"    // Error in TypeScript

The above is not supported by TypeScript: A type-only import can specify a default import or named bindings, but not both.

The workaround for TypeScript is to use an alias.

// default import with named import
import type { default as defaultBinding, otherBinding } from "module"

Should we widen the type-only import syntax to account for handling both immediate default imports and named imports?

@giltayar
Copy link
Collaborator

What am I missing? According to this, TS does support the Hegel/Flow syntax.

@ptomato
Copy link
Collaborator

ptomato commented Nov 23, 2021

I think it's the difference between

import type { APIResponseType } from "./api";

(import an exported type named APIResponseType) and

import type APIResponseType from "./api";

(import a default export type, and call it APIResponseType)

@robpalme robpalme changed the title Type-only default imports Type-only default+named imports Nov 23, 2021
@robpalme
Copy link
Collaborator Author

Apologies I misled you first time around. Type-only default imports are supported in TypeScript. The only case that is not handled is requesting both the default and named bindings.

@giltayar
Copy link
Collaborator

Got it! And, yes, I say widen the support.

@robpalme
Copy link
Collaborator Author

robpalme commented Dec 7, 2021

I went back to the recent history on this. The reason the combined syntax was not added to TypeScript is because of a potential confusion.

import a, { type b } from 'mod'  // ONLY b is a type import - easily understood

vs

import type a, { b } from 'mod'  // BOTH a & b are type imports - is this obvious to all?

For the latter case, users might mistakenly think that { b } is a value import, assuming that type a binds tightly, when in fact the type applies to the entire statement.

I don't think this is essential to resolve right now. So I'd like to leave this as an open issue for now until we hear more from users.

@robpalme
Copy link
Collaborator Author

The champion group discussed this and concluded we will bring this into scope, meaning both default and named imports will be permitted in the same import declaration.

Note that this does not imply that TypeScript will permit the form. That's an independent decision.

kevinschaul added a commit to kevinschaul/maplibre-gl-js that referenced this issue Feb 8, 2023
The syntax is a bit odd. Background here:
tc39/proposal-type-annotations#16
HarelM pushed a commit to maplibre/maplibre-gl-js that referenced this issue Feb 13, 2023
* Change how meta key is detected for coop. gestures

UIEvents like 'wheel' include properties for whether some keys are
currently pressed, including ctrl and meta. [0] This should be less
prone to error, specifically when the user presses or depresses one of
these keys while the browser document is not active.

Adds a debug page for cooperative gestures because this feature cannot
be tested with a fullscreen map, and the only other test page is
a fullscreen map.

[0] https://w3c.github.io/uievents/#dom-mouseevent-ctrlkey

* Add method to enable/disable cooperativeGestures

Fixes #2057

Also disable cooperative gestures in fullscreen, using these new methods
(Fixes #1488)

* Changelog

* Combine imports from map

The syntax is a bit odd. Background here:
tc39/proposal-type-annotations#16

* Remove debug page

* Specify event type

* Add Map._getMetaKey()

* Add cooperative gestures class

* Add return value to _getMetaKey()

* Add _metaKey property, initialize in constructor

* Update expectedBytes to size of bundle on main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants