当前位置: 首页 > news >正文

网站建设玖首选金手指企业官方网站推广

网站建设玖首选金手指,企业官方网站推广,seo基础培训机构,做网站表格Partial Partial用于将给定类型的所有属性设置为可选。换句话说#xff0c;Partial 可以创建一个新的类型#xff0c;该类型具有与原始类型相同的属性#xff0c;但是这些属性都是可选的。使用 Partial 可以很方便地定义一个对象#xff0c;其中的属性可以选择性地进行赋值…Partial Partial用于将给定类型的所有属性设置为可选。换句话说Partial 可以创建一个新的类型该类型具有与原始类型相同的属性但是这些属性都是可选的。使用 Partial 可以很方便地定义一个对象其中的属性可以选择性地进行赋值。 interface User {name: string;age: number;email: string; }function updateUser(user: PartialUser): void {// 更新用户信息// ... }const user: User {name: John,age: 30,email: johnexample.com };updateUser({ name: John Doe }); // 仅更新名称 updateUser({ age: 31, email: john.doeexample.com }); // 仅更新年龄和邮箱Required Required 用于将给定类型的所有属性设置为必需的。换句话说Required 可以创建一个新的类型该类型具有与原始类型相同的属性但是这些属性都是必需的不能省略。 interface User {name?: string;age?: number;email?: string; }function createUser(user: RequiredUser): void {// 创建用户// ... }createUser({ name: John, age: 30, email: johnexample.com }); // 完整的用户信息 createUser({ name: John }); // 缺少必需的属性会报错Readonly Readonly用于将给定类型的所有属性设置为只读。换句话说Readonly 可以创建一个新的类型该类型具有与原始类型相同的属性但是这些属性都是只读的不能被修改。使用 Readonly 可以很方便地定义一个只读的对象其中的属性不能被修改。这对于确保对象的不可变性和类型安全非常有用。 interface User {readonly name: string;readonly age: number;readonly email: string; }function getUser(): ReadonlyUser {return { name: John, age: 30, email: johnexample.com }; }const user: ReadonlyUser getUser();console.log(user.name); // John user.name John Doe; // 无法修改只读属性会报错Pick Pick 用于从给定类型中选择指定的属性并创建一个新的类型。换句话说Pick 可以从一个对象类型中挑选出指定的属性创建一个新的类型该类型只包含指定的属性。使用 Pick 可以很方便地从一个复杂的类型中选择需要的部分减少了不必要的冗余信息提高了代码的可读性和灵活性。 interface User {name: string;age: number;email: string;address: string; }type UserBasicInfo PickUser, name | age;const user: UserBasicInfo {name: John,age: 30, };Record Record 用于创建一个具有指定属性类型的对象类型。Record 接受两个类型参数第一个参数指定属性的名称第二个参数指定属性的类型。 使用 Record 可以很方便地定义一个具有指定属性类型的对象类型这对于创建字典、映射等数据结构非常有用。 type Fruit apple | banana | orange; type Price number;const fruitPrices: RecordFruit, Price {apple: 1.5,banana: 0.5,orange: 0.8, };console.log(fruitPrices.apple); // 1.5 console.log(fruitPrices.banana); // 0.5 console.log(fruitPrices.orange); // 0.8Exclude Exclude 用于从一个联合类型中排除指定的类型。 Exclude 接受两个类型参数第一个参数是要排除的类型第二个参数是要从中排除类型的联合类型。 下面是一个例子演示了如何使用 Exclude 类型工具 type Animal dog | cat | bird; type ExcludeBird ExcludeAnimal, bird; const myPets: ExcludeBird[] [dog, cat];Extract Extract 用于从一个联合类型中提取指定的类型。 Extract 接受两个类型参数第一个参数是要提取的类型第二个参数是要从中提取类型的联合类型。 type Animal dog | cat | bird; type ExtractBird ExtractAnimal, bird; const myBird: ExtractBird bird;Omit Omit 用于从一个对象类型中排除指定的属性。 Omit 接受两个类型参数第一个参数是要从中排除属性的对象类型第二个参数是要排除的属性的名称。 type Person {name: string;age: number;gender: string; };type OmitAge OmitPerson, age;const personWithoutAge: OmitAge {name: John,gender: male };NonNullable NonNullable 用于从一个类型中排除 null 和 undefined。 NonNullable 接受一个类型参数该参数表示要排除 null 和 undefined 的类型。 type NullableString string | null | undefined; type NonNullableString NonNullableNullableString; const str: NonNullableString Hello;Parameters Parameters 是一个泛型工具类型它用于获取函数类型 T 的参数类型。它接受一个函数类型作为参数并返回一个元组类型其中包含了函数的每个参数类型。 function greet(name: string, age: number): void {console.log(Hello, ${name}! You are ${age} years old.); }可以使用Parameters来获取greet函数的参数类型 type GreetParams Parameterstypeof greet; // GreetParams 的类型为 [string, number]ConstructorParameters ConstructorParameters 用于获取构造函数的参数类型。 ConstructorParameters 接受一个构造函数类型作为参数并返回一个元组类型该元组类型包含了构造函数的参数类型。 class Person {constructor(name: string, age: number) {// constructor implementation} } type PersonConstructorParams ConstructorParameterstypeof Person; const params: PersonConstructorParams [John, 25];ReturnType ReturnType是一个泛型工具类型它用于获取函数类型T的返回值类型。它接受一个函数类型作为参数并返回该函数的返回值类型。 function add(a: number, b: number): number {return a b; }可以使用ReturnType来获取add函数的返回值类型 type AddResult ReturnTypetypeof add; // AddResult 的类型为 numberInstanceType InstanceType 用于获取构造函数的实例类型。 InstanceType 接受一个构造函数类型作为参数并返回该构造函数类型的实例类型。 class Person {name: string;age: number;constructor(name: string, age: number) {this.name name;this.age age;}sayHello() {console.log(Hello, my name is ${this.name} and Im ${this.age} years old.);} }type PersonInstance InstanceTypetypeof Person;const person: PersonInstance new Person(John, 25); person.sayHello();Uppercase Uppercase 用于将字符串类型的字母转换为大写。 Uppercase 接受一个字符串类型作为参数并返回该字符串类型的大写版本。 type UppercaseString Uppercasehello; // UppercaseString 的类型为 HELLOconst str: UppercaseString HELLO;Lowercase Lowercase 用于将字符串类型的字母转换为小写。 Lowercase 接受一个字符串类型作为参数并返回该字符串类型的小写版本。 type LowercaseString LowercaseHELLO; // LowercaseString 的类型为 helloconst str: LowercaseString hello;Capitalize Capitalize 用于将字符串的第一个字符转换为大写。 type MyString hello; type CapitalizedString CapitalizeMyString; // CapitalizedString 的类型为 HelloUncapitalize Uncapitalize用于将字符串的第一个字符转换为小写。 type MyString Hello; type UncapitalizedString UncapitalizeMyString; // UncapitalizedString 的类型为 hellohttps://www.zhihu.com/question/453332049/answer/3145262802
http://www.yutouwan.com/news/125165/

相关文章:

  • 做电影网站哪个系统好wordpress更换通栏图片
  • 河北住建城乡建设网站鲲鹏建设集团有限公司网站
  • 外贸网站建设公司服务住房城乡建设部网站文件查询
  • 开发一个app需要哪些技术如何优化公司网站
  • 云南网站开发公司网站建设怎么添加视频
  • 石家庄那有建网站网站效果主要包括
  • 如何做Google外贸网站江门seo网站排名
  • githup网站建设网络营销方法案例
  • 绥化市建设局网站wordpress 404 调用
  • 网站建设实训 考核要求网站收录没排名
  • 济宁网站建设500元网站标题的写法
  • 临沂市建设安全管理网站打开有些网站显示建设中
  • 性价比高的广州网站建设除了网页外 网站还需要
  • 网站优点头像制作免费生成器
  • 有没有专门做帽子的网站东莞出租车公司
  • 青岛网站建设排名个人网站备案可以做项目网站
  • 在线设计海报网站邢台网站推广多少钱
  • 凡科建站平台西宁网站怎么做seo
  • 找人做网站属于了解些什么呢构建新引擎激发新动力
  • 企业网站推广有哪些ui设计一个月挣多少钱
  • WordPress站群 管理网站建设的前景
  • 狮山建网站网站多域名
  • php做网站模板网站怎么做现场直播视频
  • 有专门做网站的公司吗网站 验证码错误
  • 检察 门户网站建设深圳做h5网站制作
  • 在线做网站有哪些平台高级网站开发技术使用什么语言
  • 上海传媒公司电话龙岗网站优化培训
  • 做微博类的网站难吗广州 营销型网站建设
  • 网站后台信息管理怎么做vscode制作个人网站
  • 网站做等级保护如何安装wordpress博客