-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liangxiao
committed
Jul 31, 2019
1 parent
a15cbee
commit 0cca8b1
Showing
10 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 单独导出 | ||
export let a = 1 | ||
|
||
// 批量导出 | ||
let b = 2 | ||
let c = 3 | ||
export { b, c } | ||
|
||
// 导出接口 | ||
export interface P { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
// 导出函数 | ||
export function f() {} | ||
|
||
// 导出时起别名 | ||
function g() {} | ||
export { g as G } | ||
|
||
// 默认导出,无需函数名 | ||
export default function () { | ||
console.log("I'm default") | ||
} | ||
|
||
// 引入外部模块,重新导出 | ||
export { str as hello } from './b' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// 导出常量 | ||
export const str = 'Hello' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { a, b, c } from './a'; // 批量导入 | ||
import { P } from './a'; // 导入接口 | ||
import { f as F } from './a'; // 导入时起别名 | ||
import * as All from './a'; // 导入模块中的所有成员,绑定在 All 上 | ||
import myFunction from './a'; // 不加{},导入默认 | ||
|
||
console.log(a, b, c) | ||
|
||
let p: P = { | ||
x: 1, | ||
y: 1 | ||
} | ||
|
||
console.log(All) | ||
|
||
myFunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export = function () { | ||
console.log("I'm default") | ||
} | ||
// export let a = 1 |
7 changes: 7 additions & 0 deletions
7
sourcecode/ts-base/src/part2.project/01.module/node/a.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let a = { | ||
x: 1, | ||
y: 2 | ||
} | ||
|
||
// 整体导出 | ||
module.exports = a |
5 changes: 5 additions & 0 deletions
5
sourcecode/ts-base/src/part2.project/01.module/node/b.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// exports === module.exports | ||
// 导出多个变量 | ||
// module.exports = {} | ||
exports.c = 3 | ||
exports.d = 4 |
11 changes: 11 additions & 0 deletions
11
sourcecode/ts-base/src/part2.project/01.module/node/c.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let c1 = require('./a.node') | ||
let c2 = require('./b.node') | ||
let c3 = require('../es6/a') | ||
import c4 = require('../es6/d') | ||
|
||
console.log(c1) | ||
console.log(c2) | ||
// c3() | ||
// console.log(c3) | ||
// c3.default() | ||
c4() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Shape { | ||
const pi = Math.PI | ||
export function cricle(r: number) { | ||
return pi * r ** 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference path="a.ts" /> | ||
namespace Shape { | ||
export function square(x: number) { | ||
return x * x | ||
} | ||
} | ||
|
||
console.log(Shape.cricle(2)) | ||
console.log(Shape.square(2)) | ||
|
||
import cricle = Shape.cricle | ||
console.log(cricle(2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
interface A { | ||
x: number; | ||
// y: string; | ||
foo(bar: number): number; // 5 | ||
foo(bar: 'a'): string; // 2 | ||
} | ||
|
||
interface A { | ||
y: number; | ||
foo(bar: string): string; // 3 | ||
foo(bar: string[]): string[]; // 4 | ||
foo(bar: 'b'): string; // 1 | ||
} | ||
|
||
let a: A = { | ||
x: 1, | ||
y: 2, | ||
foo(bar: any) { | ||
return bar | ||
} | ||
} | ||
|
||
class C {} | ||
namespace C { | ||
export let state = 1 | ||
} | ||
console.log(C.state) | ||
|
||
function Lib() {} | ||
namespace Lib { | ||
export let version = '1.0' | ||
} | ||
console.log(Lib.version) | ||
|
||
enum Color { | ||
Red, | ||
Yellow, | ||
Blue | ||
} | ||
namespace Color { | ||
export function mix() {} | ||
} | ||
console.log(Color) |