Typescript 类型声明工具函数一览

news/2024/7/4 15:24:49

Typescript 类型声明工具函数一览

原文地址:Typescript 类型声明工具函数一览

类型声明是 Typescript 中用到最多得东西,他提供了一系列类型声明函数辅助开发,提升效率。

下面简述每个方法的主要作用,个人认为不容易理解的会带示例,仅供参考。

Partial

Partial 的作用就是将 T 类型里的属性全部变为可选项 ? 。

Required

Partial 的作用就是将 T 类型里的属性全部变为必选项 ? 。

Readonly

Readonly 的作用是将 T 类型所有属性变为只读属性,也就意味着这些属性不能被重新赋值。

Record

Record<K, T> 的作用是将 K 中所有的属性的值转化为 T 类型。

示例

type petsGroup = 'dog' | 'cat' | 'fish';
interface IPetInfo {
    name:string,
    age:number,
}

type IPets = Record<petsGroup, IPetInfo>;

const animalsInfo:IPets = {
    dog:{
        name:'dogName',
        age:2
    },
    cat:{
        name:'catName'

http://www.niftyadmin.cn/n/3433362.html

相关文章

recv函数返回值

recv函数返回值说明 recv函数 int recv( SOCKET s, char FAR *buf, int len, int flags); 不论是客户还是服务器应用程序都用recv函数从TCP连接的另一端接收数据。该函数的第一个参数指定接收端套接字描述符&#xff1b; 第二个参数指明一个缓冲区&#xff0c;该缓冲区用来存放…

python-生成密码(37)

from random import choice import stringall_chs string.ascii_letters string.digitsdef gen_pass(n8): #默认是循环8次&#xff0c;也就是生成8位密码result for i in range(n):ch choice(all_chs)result chreturn resultif __name__ __main__:print(gen_pass())print…

React 18已经发布,新特性一览,带你快速了解。

React 18已经发布&#xff0c;新特性一览&#xff0c;带你快速了解。 react 18 已经发布。 1.新增了useId&#xff0c;startTransition&#xff0c;useTransition&#xff0c;useDeferredValue&#xff0c;useSyncExternalStore&#xff0c;useInsertionEffect等新的 hook API…

centos编译安装zlib

2019独角兽企业重金招聘Python工程师标准>>> 先到官网下载(比如下载1.2.11版本)&#xff1a; http://www.zlib.net/ 然后将tar包解压到 /usr/local/zlib。 切换到/usr/local/zlib/zlib-1.2.11 ./configure make && make install 转载于:https://my.oschina.…

[LeetCode]3Sum Closest

题目描述:(链接) Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array …

recv()

说明我的想法之前&#xff0c;我先纠正一下上面我犯的几个错误&#xff0c;也许说明这些错误对楼主也有帮助。且听我慢慢道来&#xff0c;嘿嘿我的犯的最大错误是&#xff0c;没有搞清楚“模式”和“选项”&#xff0c;BLOCK是一种模式&#xff0c;而TIMEOUT只是一个在特定模式…

crontab-ui 管理 crontab

背景 以前在做定时任务的时候&#xff0c;都需要上网查一下怎么配置 crontab&#xff0c;因为这个东西不常用而且使用功能间隔可能会很长&#xff0c;每次需要用的时候可能都忘记上次是怎么用的&#xff0c;所以每次都需要去查怎么配置使用。这里介绍一个工具 crontab-ui 帮助…

python-序列对象方法(38)

>>> from random import randint >>> alist list() >>> list(hello) [h, e, l, l, o] >>> list((10,20,30)) #元组转换成列表 [10, 20, 30]>>> astr str() >>> str(10) #将数字转换成字符串 10 >>> str…