Tools
yarn
无论是否 —force,yarn 在进行依赖安装(install)时都不会进行原有依赖的删除,于是就会出现一些神奇的问题。
node_modules 中会存在一些不需要的包。
可能是 babel 具有某种批量读取的效果?抑或是引用出错,会导致错误的加载顺序,或包的运行问题。
TypeScript
流程控制中守卫及返回值类型收缩
暂未能支持流程控制中收缩泛型参数,继而收缩返回值类型
https://github.com/microsoft/TypeScript/issues/33912
https://stackoverflow.com/questions/59611715/guarded-type-still-not-assignable
S[T] 是 intersection 而不是 union
- When an indexed access
T[K]
occurs on the source side of a type relationship, it resolves to a union type of the properties selected byT[K]
, but when it occurs on the target side of a type relationship, it now resolves to an intersection type of the properties selected byT[K]
. Previously, the target side would resolve to a union type as well, which is unsound. - Given a type variable
T
with a constraintC
, when an indexed accessT[K]
occurs on the target side of a type relationship, index signatures inC
are now ignored. This is because a type argument forT
isn’t actually required to have an index signature, it is just required to have properties with matching types. - A type
{ [key: string]: number }
is no longer related to a mapped type{ [P in K]: number }
, whereK
is a type variable. This is consistent with a string index signature in the source not matching actual properties in the target. - Constraints of indexed access types are now more thoroughly explored. For example, given type variables
T
andK extends 'a' | 'b'
, the types{ a: T, b: T }[K]
andT
are now considered related where previously they weren’t.
https://github.com/microsoft/TypeScript/pull/30769
https://github.com/microsoft/TypeScript/issues/44095#issuecomment-841764725
作为 source 时,S[T] 可以作为 union,而作为 target,S[T] 则是 intersection