Skip to content

Commit 1642dd8

Browse files
author
victorsun
committed
upd
1 parent dac9600 commit 1642dd8

File tree

297 files changed

+6280
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+6280
-75
lines changed

.vscode/launch.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "ts-node",
9+
"type": "node",
10+
"request": "launch",
11+
"args": [
12+
"${relativeFile}"
13+
],
14+
"runtimeArgs": [
15+
"-r",
16+
"ts-node/register"
17+
],
18+
"cwd": "${workspaceRoot}",
19+
"protocol": "inspector",
20+
"internalConsoleOptions": "openOnSessionStart"
21+
}
22+
]
23+
}

18-TypeScript/01-start.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
interface Person {
2+
firstName: string;
3+
lastName: string;
4+
}
5+
6+
function greeter(person: Person) {
7+
return "Hello, " + person.firstName + " " + person.lastName;
8+
}
9+
10+
let user = { firstName: "Jane", lastName: "User" };
11+
12+
console.log(greeter(user));

18-TypeScript/02-dataType.ts

-75
This file was deleted.
File renamed without changes.
File renamed without changes.

18-TypeScript/old/02-dataType.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Boolean Number String
3+
* Array Enum
4+
* Any Void
5+
*/
6+
// 【 Boolean 】
7+
let isDone: boolean = false
8+
// 【 Number 】
9+
let decLiteral: number = 20
10+
let hexLiteral: number = 0x14
11+
let binaryLiteral: number = 0b10100 // ECMAScript 2015 中引入的二进制字面量
12+
let octalLiteral: number = 0o24 // ECMAScript 2015 中引入的八进制字面量
13+
// 【 String 】
14+
var nameStr: string = 'csxiaoyao'
15+
let sentence: string = `Hello, my name is ${ nameStr }. I'm ${ decLiteral + 1 } years old.`
16+
// 【 Array 】 两种方式
17+
var list1: number[] = [1,2,3];
18+
var list2: Array<string> = ["csxiaoyao","sunshine"];
19+
20+
// 【 Tuple 】 元祖,允许表示一个已知元素数量和类型的数组,各元素的类型不必相同
21+
let x: [string, number]
22+
x = ['hello', 10] // OK
23+
24+
// 【 Enum 】 使用枚举类型可以为一组数值赋予友好的名字,可以由枚举的值得到它的名字
25+
enum Color { Red, Green=5, Blue=2, Purple };
26+
var colorName0: string = Color[0]; // Red
27+
var colorName1: string = Color[1]; // undefined
28+
var colorName2: string = Color[2]; // Blue
29+
var colorName3: string = Color[3]; // Purple
30+
var colorName5: string = Color[5]; // Green
31+
32+
var c1: Color = Color.Green; // 5
33+
var c2: Color = Color.Red // 0
34+
var c3: Color = Color.Purple // 3
35+
36+
// 【 Any 】
37+
var notSure: any = 10;
38+
notSure = "Hello";
39+
notSure = false;
40+
var list: any[] = [10, "hello", false];
41+
42+
// 【 Void 】 和 any 类型相反,表示没有任何类型
43+
// 声明一个void类型的变量没有什么大用,只能赋值 undefined / null
44+
function say(): void {
45+
// body...
46+
}
47+
let unusable: void = undefined;
48+
49+
// 【 null 】 / 【 undefined 】 默认情况下 null 和 undefined 是所有类型的子类型
50+
let u: undefined = undefined
51+
let n: null = null
52+
// decLiteral = n; // 配置 --strictNullChecks,否则,可以把 null 和 undefined 赋值给其他类型的变量
53+
54+
// 【 never 】表示永不存在的值的类型
55+
function error(message: string): never {
56+
throw new Error(message)
57+
}
58+
// 推断的返回值类型为never
59+
function fail() {
60+
return error("Something failed");
61+
}
62+
// 返回never的函数必须存在无法达到的终点
63+
function infiniteLoop(): never {
64+
while (true) {
65+
}
66+
}
67+
68+
// 【 object 】 表示非原始类型,即除 number,string,boolean,symbol,null或undefined 之外的类型
69+
declare function create(o: object | null): void
70+
create({ prop: 0 }) // OK
71+
create(null) // OK
72+
// create(42); // Error
73+
// create("string"); // Error
74+
// create(false); // Error
75+
// create(undefined); // Error
76+
77+
// 【 类型断言 】 两种方式
78+
let someValue: any = 'this is a string'
79+
// 方式1:尖括号
80+
let strLength1: number = (<string>someValue).length
81+
// 方式1:as
82+
let strLength2: number = (someValue as string).length
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

18-TypeScript/proj/dist/bundle.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

18-TypeScript/proj/dist/bundle.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

18-TypeScript/proj/dist/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Hello World!</title>
6+
</head>
7+
<body>
8+
<p id="greeting">Loading ...</p>
9+
<script src="bundle.js"></script>
10+
</body>
11+
</html>

18-TypeScript/proj/gulpfile.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var gulp = require('gulp');
2+
var browserify = require('browserify');
3+
var source = require('vinyl-source-stream');
4+
var tsify = require('tsify');
5+
var sourcemaps = require('gulp-sourcemaps');
6+
var buffer = require('vinyl-buffer');
7+
var paths = {
8+
pages: ['src/*.html']
9+
};
10+
11+
gulp.task('copyHtml', function () {
12+
return gulp.src(paths.pages)
13+
.pipe(gulp.dest('dist'));
14+
});
15+
16+
gulp.task('default', gulp.series('copyHtml', function () {
17+
return browserify({
18+
basedir: '.',
19+
debug: true,
20+
entries: ['src/main.ts'],
21+
cache: {},
22+
packageCache: {}
23+
})
24+
.plugin(tsify)
25+
.transform('babelify', {
26+
presets: ['es2015'],
27+
extensions: ['.ts']
28+
})
29+
.bundle()
30+
.pipe(source('bundle.js'))
31+
.pipe(buffer())
32+
.pipe(sourcemaps.init({loadMaps: true}))
33+
.pipe(sourcemaps.write('./'))
34+
.pipe(gulp.dest('dist'));
35+
}));

0 commit comments

Comments
 (0)