-
Notifications
You must be signed in to change notification settings - Fork 12.8k
A ES6 module with with multiple exports including a default export #2440
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
Comments
For your first question, yes it is valid ES6 code. It gives an error in the compiler today, but we plan to change the design to allow that code, per #2242 (comment). For your second question, no. An import { default as function1, function2 } from './module1';
function1();
function2(); You can also combine the default import with import function1, * as module1 from './module1';
function1();
module1.function2(); |
I just posted #2460 which addresses this issue. Regarding Given your example above, you can import and use the module as follows: import * as module1 from './module1'
module1.default(); // This calls function1
module2.function2(); If you want to export a member both by its name and as the default, you can do this: export function function1() {
console.log('hej')
}
export function function2() {
console.log('hej')
}
export default function1; Then you can do this: import * as module1 from './module1'
module1.default(); // This calls function1
module1.function1();
module2.function2(); |
One change breaks something else with linting error so to test first change must fix next change, which breaks more stuff by the time we finally get rid of linting errors, we've changed SOO much ALL the problems revolve around: export * from 'somewhere' import {something} from 'somewhere' -> import something from 'somewhere' import {default as something} from 'somewhere' Read docs from following pages but still don't understand - VERY confusingly written: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import https://esdiscuss.org/topic/import-statements-destructuring babel/babel#3049 http://www.thedreaming.org/2017/04/28/es6-imports-babel/ babel/babel-loader#194 https://stackoverflow.com/questions/4832829/import-javascript-file-from-within-javascript-synchronously babel/babel#4996 https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md import-js/eslint-plugin-import#49 microsoft/TypeScript#2440 https://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default/33506169#33506169
Hi, sorry for digging out an old thread. I've recently thought of moving into TS import Types, { TypeA, TypeB } from '@/common/support/types'; I mean, importing Would you mind giving me a tip on whats the valid syntax at this moment? Thanks! |
@Worie i can't find either. but with one more line i can do: import * as React from 'react';
const { Component } = React; |
I'm not sure if this is valid ES6 code but I'm trying to get this work:
app.ts
module1.ts
I'm using today's master branch and I get the following error when I compile
app.ts
:An another question, if
app.ts
do a namespaced import will I have access to the default function too?app.ts
The text was updated successfully, but these errors were encountered: