Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

add undefined import tip to guide#365

Open
bagilevi wants to merge1 commit intowmonk:master
base:master
Choose a base branch
Loading
frombagilevi:add-troubleshooting-import-undefined

Conversation

@bagilevi
Copy link

Add troubleshooting tip for importing the default export in TypeScript.

Easy mistake to make when migrating from JavaScript.

See:#364

paulmelnikow and mcmonster reacted with thumbs up emoji
Add troubleshooting tip for importing the default export in TypeScript.Easy mistake to make when migrating from JavaScript.
@bagilevibagileviforce-pushed theadd-troubleshooting-import-undefined branch from66d5fb1 todc4e448CompareJuly 13, 2018 11:09
@DorianGrey
Copy link
Collaborator

Sorry for the delay ... had a lot of things to do recently.

This description lacks some details and potential alternative suggestions.
A bit of background (refering to the example in the ticket):

import _ from 'lodash';

This only works in case the packagelodash has a default export. But it does not have one (at least in v4) - every function is exported separately (lodash-es provides some default exports, but one for each function in separation).
So in general, you will have to go with

import * as _ from 'lodash';

However, there are two ways to synthesize the default export:

  • Usingbabel
  • Usingtypescript with theesModuleInterop option enabled (allowSyntheticDefaultImports is required in most cases as well)

Both synthesize the default export of a module to* as <whatever> in case the source module is not an ES module and does not yet have a default export declaration.

I have to admit that I'm not sure if a description about this topic should be added here, since it is a more general issue - yet it might be helpful.

@nickserv
Copy link

nickserv commentedSep 1, 2018
edited
Loading

I'm starting to feel that esModuleInterop should be in the default tsconfig template, so we can keep CRA's default generated imports and avoid confusing users new to TS.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@bagilevi@DorianGrey@nickserv

[8]ページ先頭

©2009-2025 Movatter.jp