【问题标题】:How to define an array of string and number or a tuple in immutable.js如何在 immutable.js 中定义字符串和数字数组或元组
【发布时间】:2021-06-17 15:39:19
【问题描述】:

在打字稿中,我可以像这样定义一个数字和字符串的数组:

type A = [number, string]

我现在决定使用 Immutable.js 如何使用不可变列表来定义这种类型。

类似这样的:

import { List } from 'immutable';

type A = List<number, string>

【问题讨论】:

    标签: typescript immutable.js


    【解决方案1】:

    只需使用联合:

    import { List } from 'immutable';
    
    type A = List<number | string>
    
    const a: A = List(['a', 1] as const)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2011-08-20
      相关资源
      最近更新 更多