Skip to content

Instantly share code, notes, and snippets.

View chenyong's full-sized avatar
💭
Debugging TypeScript...

ChenYong chenyong

💭
Debugging TypeScript...
View GitHub Profile
@chenyong
chenyong / check.cljs
Created June 3, 2019 03:28
Comparing Clojure spec and TypeScript with multiple structs
(def data {
:mock-all? false
:mocks [
{:path "api/test/json", :type :json :status 200 :data {"code" 200, "message" "This is a test json message in EDN"}}
{:path "api/test/file", :type :file :status 200 :file "user-info.json"}
{:path "api/test/text", :type :text :status 200 :text "user-info.json"}
]
:sites {
"api" {:target :apis}
"web" {:target :proxy, :path "/web", :host "http://localhost:8200"}
@chenyong
chenyong / return.ts
Created May 20, 2019 06:48
Infer return type from function parameter's type, based on https://dev.to/aexol/typescript-tutorial-infer-keyword-2cn This is far from satisfaction.
let a ={
b: {
c:1
}
}
type A = typeof a
@chenyong
chenyong / used-icons
Created February 27, 2019 07:48
Icons really used in antd
check-circle
check-circle-o
close-circle
close-circle-o
default
down
exclamation-circle
exclamation-circle-o
info-circle
@chenyong
chenyong / ty-errors.text
Created February 20, 2019 03:22
Some type errors found in upgrading ant typescript
✖ 「atl」: Checking finished with 31 errors
[at-loader] ../node_modules/@types/react-router/index.d.ts:104:55
TS2344: Type 'keyof T' does not satisfy the constraint 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
[at-loader] ../node_modules/@types/react-router-dom/index.d.ts:15:5
TS2305: Module '"../../../../../../../Users/chen/work/web/node_modules/@types/react-router"' has no exported member 'generatePath'.
[at-loader] ./ts/report/models/component.ts:55:23
if (symbol.flags & (32 /* Class */ | 64 /* Interface */)) {
if (symbol.valueDeclaration && symbol.valueDeclaration.parent == null) {
console.log(node) <---- log
}
if (symbol.valueDeclaration && ts.isBinaryExpression(symbol.valueDeclaration.parent)) {
var jsdocType = getJSDocTypeReference(node, symbol, typeArguments);
if (jsdocType) {
return jsdocType;
}
}
@chenyong
chenyong / immer-helpers.ts
Created December 10, 2018 11:47
Helper functions to use Immer in React projects.
import produce from "immer";
export interface ImmerStateFunc<S> {
(f: ((s: S) => void)): Promise<any>;
}
export interface MergeStateFunc<S> {
(partialState: Partial<S>): Promise<any>;
}
@chenyong
chenyong / safe-prop.ts
Last active December 10, 2018 13:32
A stupid Optional Chaining alternative in TypeScript, demo https://streamable.com/vnyap
// get
export function safeGet<T, K1 extends keyof T>(x: T, k1: K1): T[K1] {
if (x != null) {
return x[k1];
}
return null;
}
export function safeGet2<T, K1 extends keyof T, K2 extends keyof (T[K1])>(x: T, k1: K1, k2: K2) {
@chenyong
chenyong / brew-list
Created November 7, 2018 10:28
Current brew list
=>> brew list
ack gettext libidn2 nginx python
adns ghc libksba node@10 python3
aspcud git libpng npth python@2
bash gmp libtasn1 ocaml readline
bash-completion gnupg libtiff ocamlbuild rlwrap
camlp4 gnutls libtool opam ruby
clasp go libunistring openssl sphinx-doc
clingo graphviz libusb openssl@1.1 sqlite
clojure gringo libyaml p11-kit tcpflow
@chenyong
chenyong / immerState.ts
Last active October 17, 2018 06:17
ImmerState function with types
import React from "react";
import produce from "immer";
// get type of partial of an object with type T
export type IPartialObject<T> = { [K in keyof T]?: T[K] };
export interface ImmerStateFunc<S> {
(f: IPartialObject<S> | ((s: S) => void), callback?: () => void): void;
}
@chenyong
chenyong / meyvn-pom.xml
Created September 13, 2018 04:49
pom.xml generated by meyvn
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>respo</groupId>
<artifactId>inflow-popup</artifactId>
<version>0.2.5</version>
<name>inflow-popup</name>
<scm>
<connection>scm:git:git@github.com:Respo/inflow-popup.git</connection>