-
Notifications
You must be signed in to change notification settings - Fork 12
Modules
hazzard993 edited this page Jul 11, 2019
·
3 revisions
TypeScript uses relative paths to import modules. You can use the --baseUrl
option to get around this but it transform to the same behaviour.
Import Statements
Statement | Description |
---|---|
import * as m from "./m"; |
Imports all members of "m" and puts them in a variable named "m" |
import "./m"; |
Imports all functions from "m" into the current scope. |
import { x } from "./m"; |
Imports member "x" from "m". |
import { x as y } from "./m"; |
Imports member "x" from "m" and calls it "y". |
import x from "./m"; |
Imports the default value from "m" as "x" |
Relative Import
lib.ts
+ main.ts
+ module.ts
import * as mod from "./module";
lib/
+ lib.ts
+ main.ts
module.ts
import * as mod from "./lib/lib";
Export Statements
Export statements must be used to provide members from a file to another module. This is usually done by putting export
in front of a declaration.
export class Player {}
import { Player } from "./module";