typescript tdd

搭建前端Vue框架的步骤,包括TypeScript、ESLint、Prettier和Vite的配置

搭建前端Vue框架需要以下步骤: 1. 安装Node.js和npm 2. 创建一个新的Vue项目 ``` vue create my-project ``` 3. 安装TypeScript ``` npm install --save-dev typescript ``` 4. 配置TypeScri ......
前端 TypeScript 框架 Prettier 步骤

TypeScript 5.1

getter 和 setter 可以完全不同类型了 以前我们提过,getter 的类型至少要是其中一个 setter 的类型。这个限制被突破了。现在可以完全使用不同类型了。 v5.1 后,没有再报错了 ......
TypeScript 5.1

TypeScript – 冷知识

当 generic return 遇上 parameter 报错了。原因是 querySelector 默认返回类型是抽象的 Element。 而 method 参数要求的是具体的 InputElement 解决方法是传入具体的 InputElement 类型 const input = docum ......
TypeScript 知识

typeScript学习-Record和Map对比

typeScript学习 Record 和 Map 对比 Record 是属于一个轻量级的 type 类型,Map 相对 Record 是重量级。 Map 不能像 Record 一样直接转换为普通的对象,来应对只有查询的实际问题,只是为了频繁的查询去 new 一个 Map 是一种不必要的浪费。 如果 ......
typeScript Record Map

TypeScript(TS)JavaScript(JS)中的所有循环方法

for循环: for (let i = 0; i < array.length; i++) { // 循环体 } for…of循环: for (const element of array) { // 循环体 } forEach方法: array.forEach((element) => { // ......
TypeScript JavaScript 方法

[React Typescript] Updating the Global Namespace for an Additional Attribute

I want to add a common attribute to dom element globally: <> <div testId="123" /> <audio testId="123" /> <video testId="123" /> <a testId="123" /> <ab ......

typeScript学习-函数重载

typeScript学习 函数重载 定义:一组具有相同名字,不同参数列表的和返回值无关并且具有一个实现签名和一个或多个重载签名的函数。 type Messgae = { id: number, type: MessgaeType, sendmessage: string } enum Messgae ......
typeScript 函数

typescript 数组根据指定字段去重

this.listDataIn = data.Result.data; const uniqueItems: Item[] = Array.from( new Set(this.listDataIn.map(item => item.MyLandID)) ).map(id => { return o ......
数组 字段 typescript

[React Typescript] ElementType, ComponentType

The ElementTypetype helper is a bit unusal because it accepts some props and derives what types of components would be able to recieve those props. He ......
ComponentType ElementType Typescript React

[React Typescript] JSX.IntrinsicElements

interface IntrinsicElements { // HTML a: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>; abbr: React.Detail ......
IntrinsicElements Typescript React JSX

typeScript学习-泛型

typeScript学习 泛型 为什么要用泛型?泛型定义。 泛型在类中的应用?封装一个面向对象的 ArrayList 类。 泛型默认值。 泛型约束。 泛型在Vue3 源码中的应用。 exends keyof + keyof 的联合应用。 泛型反向赋值。 具有以下特点的数据类型叫泛型: 特点一:定义时 ......
typeScript

typeScript学习-自定义守卫

typeScript学习 自定义守卫 function 函数名(形参:参数类型【参数类型大多数为any】): 形参 is A 类型{ return true or false } class Customer { pay(payMethod: BankPay | MobilePay) { if (i ......
typeScript

typeScript学习-类型守卫

typeScript学习 类型守卫 为什么要用类型守卫: 类型守卫定义:在 语句的块级作用域【if 语句内或条目运算符表达式内】 缩小变量的一种类型推断的行为。 类型守卫产生时机:TS 条件语句中遇到下列条件关键字时,会在语句的块级作用域内缩小变量的类型。这种类型推断的行为称作类型守卫(Type G ......
typeScript 类型

typeScript学习-类型断言、类型转换

typeScript学习 类型断言、类型转换 1、类型断言: 语法格式:A 数据类型的变量 as B 数据类型。 let b: B let c: C = b as C 理解:是绕过TS 编译检查,类型断言就是对编译器说:我是这个类型了,无需检查。 2、类型断言使用场景 export class Ve ......
类型 typeScript

[React Typescript] React.ReactNode > React.ReactElement = JSX.Element = React.JSX.Element

This is ReactNode: type ReactNode = | ReactElement | string | number | ReactFragment | ReactPortal | boolean | null | undefined This is React.ReactEle ......
React Element ReactElement Typescript JSX

采用typescript编写,实现ofd前端预览、验章。

前言 浏览器内核已支持pdf文件的渲染,这极大的方便了pdf文件的阅读和推广。ofd文件作为国产板式标准,急需一套在浏览器中渲染方案。 本人研究ofd多年,分别采用qt、c# 开发了ofd阅读器。本人非前端开发人员,对js、typescript并不熟悉,所以对开发web版阅读器迟迟没有下手。但是,本 ......
前端 typescript ofd

[React Typescript] React namespace

export = React; export as namespace React; declare namespace React { // // React Elements // type ElementType<P = any> = { [K in keyof JSX.IntrinsicEl ......
React Typescript namespace

[React Typescript] Inferring Type Arguments in Curried Hooks

import { DependencyList, useMemo, useState } from "react"; import { Equal, Expect } from "../helpers/type-utils"; const useCustomState = <TValue>(init ......
Typescript Inferring Arguments Curried React

[React Typescript] Function overload in React hook

import { useState } from "react"; import { Equal, Expect } from "../helpers/type-utils"; type UseStateReturnValue<T> = { value: T; set: React.Dispatch ......
React Typescript Function overload hook

Deno 中使用 @typescript/vfs 生成 DTS 文件

## 背景 前段时间开源的 [STC](https://github.com/long-woo/stc) 工具,这是一个将 OpenApi 规范的 Swagger/Apifox 文档转换成代码的工具。可以在上一篇([《OpenApi(Swagger)快速转换成 TypeScript 代码 - STC ......
typescript 文件 Deno DTS vfs

TypeScript学习

TypeScript 快速入门 ![](https://img2023.cnblogs.com/blog/2172992/202308/2172992-20230812101526008-1653263566.png) - JavaScript 是一种属于网络的高级脚本语言,已经被广泛用于 Web ......
TypeScript

[React Typescript] Discriminated Tuples in Custom Hooks

import { useEffect, useState } from "react"; export type Result<T> = | ["loading", undefined?] | ["error", Error] | ["success", T]; export const useDa ......
Discriminated Typescript Custom Tuples React

typeScript学习-类、静态数据、静态属性应用

typeScript学习 类、静态数据、静态属性应用 类: 定义:类就是拥有相同属性和方法的一系列对象的集合。 展开理解:类是一个模具,是从这该类包含的所有具体对象中抽象出来的一个概念,类定义了它包含的全体对象的静态特征和动态特征。 举例: people 类 静态特征【属性】name、age、add ......
静态 typeScript 属性 数据

typeScript学习-TS类型-其他特殊类型-可变元组

typeScript学习 可变元组: let people: [string, number, string, string, string] = ["wangwu", 23, "地址", '13312341234', '备注'] // 当前三个数据固定格式,后面数据不确认格式时 用可变元组 // ......
类型 typeScript TS

typeScript学习-TS类型-对象类型-Array

typeScript学习 对象类型-Array 数组和数组元素只读 const account = [10, 40, 50, 60, 90] as const // account[0] = 100 // 错误 export { } ......
类型 typeScript 对象 Array TS

typeScript学习-TS类型-其他特殊类型-元组(tuple)

typeScript学习 元组(tuple): 满足以下3点的数组就是元组 (1)在定义时每个元素的类型都是确定 (2)元素值的数据类型必须是当前元素定义的类型 (3)元素值的个数必须和定义时个数相同 let salary: [string, number, number, number, numb ......
类型 typeScript tuple TS

[React Typescript] Well typed a React Context provider

import React from "react"; import { Equal, Expect } from "../helpers/type-utils"; const createRequiredContext = <T extends any>() => { const context = ......
React Typescript provider Context typed

[React Typescript] Fixing type inference in a Custom React Hook

// Problem import { useState } from "react"; import { Equal, Expect } from "../helpers/type-utils"; export const useId = (defaultId: string) => { cons ......
React Typescript inference Fixing Custom

typeScript学习-interface和type 区别

typeScript学习 interface(接口) 和 type 区别 type 和接口类似,都用来定义类型,但 type 和 interface 区别如下: 区别1:定义类型范围不同 interface 只能定义对象类型或接口当名字的函数类型。 type 可以定义任何类型,包括基础类型、联合类型 ......
typeScript interface type

[Typescript] Don't compare generic function, instead compare function arguments and return type

Typescript has its problem that when you try to compare generic function to a function signature, you will run into issue. Because for one function, i ......