Skip to content

Instantly share code, notes, and snippets.

View zhangxiang958's full-sized avatar
💭
Working on my full time job

Shawn Cheung zhangxiang958

💭
Working on my full time job
View GitHub Profile
@eczn
eczn / distributive-law-in-conditional-type.md
Last active May 9, 2022 08:33
莲学派 TypeScript 重新理解 never

条件类型中的分配律

TypeScript Conditional Types 条件类型在设计上是 distributable 的, 也就是可以按分配律,也可以不按分配律做处理,具体来说,只有在有泛型参数出现的情况下才会按 distributive 做处理,理由是底层实现如此:

image

而什么是分配律?其实跟乘法的分配律一样,是代数系统一种概念, 如:

type ABABC =
@jherax
jherax / configure.md
Last active July 3, 2025 12:33
VS Code: Debugging with Jest

VS Code: Debugging Jest

Sometimes, debugging with console.log is not enough to find out what is happening in the code, as console.log prints only plain objects but neither functions nor objects with circular references. Besides, it's possible you may need to know the context and flow of the code.

Read more about debugging with VS Code in VS Code: Debugging.

@cecilemuller
cecilemuller / launch.json
Last active April 4, 2025 13:08
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
@zmmbreeze
zmmbreeze / analytics.js
Last active June 1, 2025 06:51
GA的源码 analytics.js
(function() {
/**
* 记录方法使用情况的类
* @param {Array.<boolean>} umMap 初始的使用情况
*/
var UsageManager = function(umMap) {
this.umMap = umMap || [];
};
/**
* 记录新的使用情况
@saelo
saelo / decorator.go
Created March 8, 2015 19:45
Decorators in Go
package main
import (
"fmt"
"reflect"
)
func Decorate(impl interface{}) interface{} {
fn := reflect.ValueOf(impl)