blog
blog copied to clipboard
记录日常遇到的问题,需要记录的笔记以及新学到的知识,会进行汇总和分类,自动更新 README,欢迎评论和补充,互相学习
> 来源:https://github.com/SunshowerC/blog/issues/8 - main : 定义了 npm 包的入口文件,browser 环境和 node 环境均可使用 - module : 定义 npm 包的 ESM 规范的入口文件,browser 环境和 node 环境均可使用 - browser : 定义 npm 包在 browser 环境下的入口文件
> 来源:https://medium.com/@martin_hotell/10-typescript-pro-tips-patterns-with-or-without-react-5799488d6680 Don't ``` SkaterBoy.tsx userAccessHandlers.ts ``` Do ``` skater-boy.tsx user-access-handlers.ts ``` 1. 可读性更好 文中说 my-half-fixed-deduped-dir-resolver vs MyHalfFixedDedupedDirResolver,我觉得差不多 3. git 更友好(git 默认不区分文件名大小写) 我觉得这个才是关键点 5. 一致性(存疑) > consistency (I don’t have...
> 来源:https://react-typescript-cheatsheet.netlify.app/docs/basic/troubleshooting/types 1. 获取组件 props ```tsx import { Button } from "library"; // but doesn't export ButtonProps! oh no! type ButtonProps = React.ComponentProps; // no problem! grab your own! type...
> 来源:https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/default_props/ 不推荐使用 defaultProps 来定义组件的默认值, 而是使用对象默认值 ```tsx type GreetProps = { age?: number }; const Greet = ({ age = 21 }: GreetProps) => // etc ``` 使用 defaultProps 会存在这样的问题:...
## 类型判断 `typeof` 处理一些基础类型的数据 `string | number | bigint | boolean | symbol | undefined | object | function` ```ts type Val = string | number; const getValType = (val:...
## ReactElement ReactElement 是含有 props 和 type 属性的对象: ```ts interface ReactElement { type: T; props: P; key: Key | null; } ``` ## ReactNode ReactNode 则是多种类型的集合: ```ts type ReactText =...
> 来源:https://www.ruanyifeng.com/blog/2015/04/tail-call.html ## 尾调用 概念:某个函数的最后一步是调用另一个函数 触发形式: ```js function f(x){ return g(x); } // 尾调用不一定出现在函数尾部,只要是最后一步操作即可 function f(x) { if (x > 0) { return m(x) } return n(x); } ``` 触发条件:ES6...
来源:https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/20 1. `class` 会进行声明提升,类似 let const,进入暂时性死区 2. `class` 内部采用严格模式 3. `class` 所有方法(包括静态和实例方法)都是不可枚举的 4. `class` 的所有方法(包括静态方法和实例方法)都没有原型对象 `prototype`,所以也没有 `[[construct]]`,不能使用 new 来调用 5. 必须使用 new 调用 `class` 6. `class` 内部无法重写类名 7. ES5 和...