basarat / typescript-book

:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹
https://basarat.gitbook.io/typescript/
Other
20.58k stars 2.52k forks source link

Document ES6 modules #3

Open basarat opened 9 years ago

basarat commented 9 years ago

Import

import * as $ from "jquery" import {extend} from "jquery" import {extend as ex} from "jquery" // Useful if the name conflicts with a local variable import something from "es6module"; // For default import. Not recommended https://basarat.gitbooks.io/typescript/content/docs/tips/defaultIsBad.html

Export

export something export default something // Not recommended https://basarat.gitbooks.io/typescript/content/docs/tips/defaultIsBad.html export = something; // Not recommended for new code. Prefer default export or export individual items export {extend as ex} // Useful when you want to extend an alias

Reexport

export * from 'mod'; // Great for top level file where you just export everthing from some sub module. export {v} from 'mod'; // Great for top level file e.g. main.js where you just export stuff from different files in your project. export {v as x} from 'mod'; // When you want to export stuff from someone else's module but with a different name.

jgw96 commented 8 years ago

id like to take this issue if it has not been worked on yet?

basarat commented 8 years ago

@jgw96 thanks for the attention. I've just updated this issue with comments about my opinions :rose:

The main concern is that I need to think about where this should actually go. I actually feel that getting started should receive a bit more love and I should teach tsc -w first with a single file then follow it up with talking about modules and split for first NodeJs and then Webpack.

Its a more massive rewrite that I'll do when I have some spare time so leave it for now :rose: