Typescript WTF Moment 12:谨防对象文字联合
type ABC = {
A: number, B: number } | {
C: number }
const abc: ABC = {
A:
type ABC = {
A: number, B: number } | {
C: number }
const abc: ABC = {
A:
观察下面的例子: type A = boolean; type B = string; type C<T extends B> = {
type ABC = { A: number, B: number } | { C: number
const a = false || [] // ^? const b = [] // ^? function c() {
type o = boolean extends Record<infer X, unknown> ? X : false // valueOf // ^?
相同类型的对象联合不会崩溃 type a = 1 | 1 // 1, collapsed // ^? type b = {
相同类型的对象联合不会崩溃 type a = 1 | 1 // 1, collapsed // ^? type b = {
const a = 'a' const obj = { [a]:1 } // {a:1} const b =
这个系列是关于我在 Typescript 中遇到的困惑,不直观,难以推理或需要额外注意的事情。 警告的原因可能是由于错误或缺陷或只是按预期工作 我会不时地为这个系列添加新的
typescript重要吗 If you hang around in the JavaScript community, along with `left-pad` you
联合类型(Union Types)表示取值可以为多种类型中的一种。 let myFavoriteNumber: string | number; myFavo
还没有评论,来说两句吧...