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 »

在 TypeScript 的类型系统中,逆变(Contravariance)、协变(Covariance)、双变(Bivariance) 和 不变(Invariance) 是描述类型兼容性和子类型关系的重要概念。这些术语来源于类型理论,主要用于处理函数类型、泛型和接口的赋值规则。理解这些概念不仅能帮助我们编写更安全的代码,还能让我们更好地设计类型系统。本文将逐一讲解这四种变型,辅以代码示例,让你轻松掌握它们的含义与应用。

Read more »

1
2
3
4
5
6
7
8
9
10
const enum Foo {
AA = "aa",
BB = "bb",
}

type B = keyof typeof Foo // 'AA' | 'BB'

// Template Literal Types
type C = `${keyof { [x in Foo]: string }}`
// 'aa' | 'bb'

基本类型

  • 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 »

缘由

公司的 PC 没有音卡。导致耳机不能播放。

使用 pavucontrol 输出为模拟信号

刚开始总报找不到这个 package。
换了官方源也没用。
后来才发现需要打开开源 package 安装。。。software & updates > ubuntu software > open-source software