Skip to content

Instantly share code, notes, and snippets.

Avatar
🤡
the next level play!

PudgeWL nbhaohao

🤡
the next level play!
View GitHub Profile
@nbhaohao
nbhaohao / awaitWrap.ts
Created Apr 4, 2020
async/await 优雅的错误处理方法
View awaitWrap.ts
function awaitWrap<T, U = any>(promise: Promise<T>): Promise<[U | null, T | null]> {
return promise
.then<[null, T]>((data: T) => [null, data])
.catch<[U, null]>(err => [err, null])
}
@nbhaohao
nbhaohao / alias.config.js
Created Sep 14, 2019
webStorm/Idea 在 webpack 配置文件被隐藏的情况下,无法识别 alias 的问题
View alias.config.js
const resolve = dir => require("path").join(__dirname, dir);
module.exports = {
resolve: {
alias: {
"@": resolve("src")
}
}
};
@nbhaohao
nbhaohao / handleTree.js
Last active Aug 7, 2019
handleTreeData
View handleTree.js
const testArray = [
{
id: 1
},
{
id: 5
},
{
id: 2,
parentId: 1