Skip to content

Instantly share code, notes, and snippets.

View nbhaohao's full-sized avatar
🤡
the next level play!

PudgeWL nbhaohao

🤡
the next level play!
View GitHub Profile
@nbhaohao
nbhaohao / awaitWrap.ts
Created April 4, 2020 14:40
async/await 优雅的错误处理方法
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 September 14, 2019 01:52
webStorm/Idea 在 webpack 配置文件被隐藏的情况下,无法识别 alias 的问题
const resolve = dir => require("path").join(__dirname, dir);
module.exports = {
resolve: {
alias: {
"@": resolve("src")
}
}
};
@nbhaohao
nbhaohao / handleTree.js
Last active August 7, 2019 05:41
handleTreeData
const testArray = [
{
id: 1
},
{
id: 5
},
{
id: 2,
parentId: 1