Live Note

Remain optimistic

Introduction

1
2
3
4
5
6
7
8
9
interface A {
text: string
}

class B {
text: string
}

let a: A = new B() // no error

At least same member

1
2
3
4
5
6
7
8
9
10
11
interface A {
text: string
}

function foo(obj: { text: string }): string {
return obj.text
}

let obj = { text: "some text", num: 3 }
let a: A = obj // success
foo(obj) // success
Read more »

Numeric enums

1
2
3
4
5
6
7
8
9
10
11
12
enum Direction {
UP,
DOWN,
LEFT,
RIGHT,
}

function move(length: number, direction: Direction): void {
console.log(`move: ${direction} ${length}meters.`)
}

move(10, Direction.UP)

String enums

1
2
3
4
5
6
enum Direction {
UP = "UP",
DOWN = "DOWN",
LEFT = "LEFT",
RIGHT = "RIGHT",
}
Read more »

Generics

1
2
3
4
5
6
7
8
function foo<T>(arg: T): T {
return arg
}

function len<T>(arg: Array<T>): Array<T> {
console.log(arg.length)
return arg
}

Generics Types

1
2
3
4
5
6
7
8
9
10
11
function foo<T>(arg: T): T {
return arg
}

interface fooInterface<T> {
(arg: T): T
}

let myFunction: <T>(arg: T) => T = foo
let otherFunction: { <T>(arg: T): T } = foo
let interfaceFunction: fooInterface<number> = foo
Read more »

Function Types

Typing the function

1
2
3
4
5
6
7
function foo(x: number, y: string): string {
return x + y
}

let fo = function (x: number, y: string): string {
return x + y
}

Writing the function type

1
2
3
4
5
6
let foo: (x: number, y: string) => string = function (
x: number,
y: string
): string {
return x + y
}

Inferring types

1
2
3
let foo: (x: number, y: string) => string = function (x, y) {
return x + y
}
Read more »

Classes

1
2
3
4
5
6
7
8
9
10
11
class Greeter {
greeting: string

constructor(message: string) {
this.greeting = message
}

greet(): string {
return "Hello, " + this.greeting
}
}

Private

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Animal {
constructor(private name: string) {}
}

class Horse extends Animal {
constructor() {
super("Horse")
}
}

class Human {
constructor(private name: string) {}
}

let animal = new Animal("Lucy")
let horse = new Horse()
let human = new Human("Jack")
animal = horse // success
animal = human // failed
Read more »

Interface

1
2
3
4
5
6
7
8
9
10
interface labelValue {
label: string
}

function printLabel(obj: labelValue): void {
console.log(obj.label)
}

let obj = { size: 10, label: "some text" }
printLabel(obj)

Optional Properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
interface SquareConfig {
color?: string
width?: number
}

function createSquare(config: SquareConfig): { color: string; area: number } {
let defaultSquare = { color: "White", area: 200 }
if (config.color) defaultSquare.color = config.color
if (config.width) defaultSquare.area = config.width ** 2

return defaultSquare
}

console.log(createSquare({ color: "Black", width: 30 }))

Readonly Properties

1
2
3
4
5
6
7
interface Point {
readonly x: number
readonly y: number
}

let readOnlyArray: ReadonlyArray<number> = [1, 2, 3, 4]
let a: number[] = readOnlyArray as number[] // readonly array assignment to ordinary array

Excess Property Checks

1
2
3
4
5
6
7
interface SquareConfig {
color?: string
width?: number
[propName: string]: any
}

let newSquare = createSquare({ width: 100, opacity: 0.5 } as SquareConfig)
Read more »

基本类型

  • boolean:
    1
    let done: boolean = true
  • number:
    1
    let count: number = 20
  • string:
    1
    let name = "Edward Wang"
  • array:
    1
    2
    let list1: number[] = [1, 2, 3]
    let list2: Array<number> = [1, 2, 3]
  • tuple:
    1
    let x: [string, number] = ["test", 2]
  • enum:
    1
    2
    3
    4
    5
    6
    7
    enum NUMBER {
    ONE,
    TWO,
    THREE,
    }
    let a = NUMBER.TWO
    let title: string = NUMBER[3]
Read more »

川普不对伊朗动武 美股涨 金价回落 油价跳水

伊朗袭击美军驻伊拉克基地后,美国总统川普表示将升级经济制裁取代付诸武力。市场乐观情绪上扬,美股上涨,金价回落,油价则大跳水。

川普 1 月 8 日在白宫发表谈话,伊朗袭击并未伤害到任何美国人,称伊朗有所退让,暗示不会对伊朗动武,伊朗外交部长也称该国不寻求升级事态,这些消息都缓解了投资人对美伊局势的不安。

8 日美国股市上涨,道琼工业指数收涨 161.41 点或 0.56%,报 28745.09 点。标普 500 指数收涨 15.87 点或 0.49%,报 3253.05 点。那斯达克指数收涨 60.66 点或 0.67%,报 9129.24 点。费城半导体指数上涨 0.31 点或 0.02%,报 1867.59 点。

那斯达克指数创收盘新高,道琼工业指数、标普 500 指数、费城半导体指数徘回历史次高位。

Read more »

《纽约时报》美国当地时间 1 月 2 日报道说,美国官员确认,在美军对巴格达的一次空袭中,伊朗伊斯兰革命卫队特种部队“圣城旅”部队指挥官卡西姆·苏莱曼尼将军死亡。

《纽约时报》报道,伊朗官方媒体确认了,伊拉克当地时间 3 日,伊朗将军卡西姆·苏莱曼尼在美军对巴格达国际机场一处目标的空袭中死亡。苏莱曼尼是伊朗革命卫队中的重要官员。美国国防部声明表示,美国发动了空袭。

“苏莱曼尼将军积极筹划了对美国在伊拉克及地区的外交官和服务人员的攻击。苏莱曼尼将军和‘圣城旅’需要为美军和联军数百人死亡、数千人受伤负起责任。”

伊朗誓言为苏莱曼尼将军之死报复美国

伊朗伊斯兰革命卫队(伊朗武装力量组成部分)前总司令、伊朗确定国家利益委员会秘书长穆赫辛·雷扎伊称,伊朗将为在巴格达死于火箭弹袭击的伊斯兰革命卫队圣城旅指挥官卡西姆·苏莱曼尼将军复仇。

雷扎伊在推特上写道:

“殉难的卡西姆·苏莱曼尼去找他的兄弟们了。我们会狠狠报复美国。”

伊斯兰革命卫队圣城旅指挥官卡西姆·苏莱曼尼将军 2 日晚上在巴格达的火箭弹袭击中被炸死,伊拉克什叶派民兵武装“人民动员组织”(Al-Hashd al-Shaabi)的几位高级别成员也一同丧生,12 名伊拉克士兵受伤。

五角大楼称系按照美国总统川普的命令开展对苏莱曼尼的行动。五角大楼称,此次打击旨在预防伊朗方面的袭击,而苏莱曼尼本人涉嫌参与袭击联盟基地和美国驻伊拉克大使馆。

TG(目前)最大的需求–宣传

前几天在 TG,有个人问我如何实现一个 TG 批量拉人入某个 group。找了找资料发现真的可以实现。

测试了似乎单次最多只能邀请 30 人进组,并且一个人邀请太多人会被禁止单项邀请。
TG 还能不进群,直接拉进去,直接获取某个群组的所有 member,太 BUG 了

有类似想法的可以联系我,与我交流。