记录typescript常见的类型

1.基础类型

editState?: boolean;  //?表示非必填
showEditButton: boolean;
page?: number;
name: string;
creator: Array<string>;
creator: Array<{
	id: number,
	phone: number
}>;
dept: string[];

export interface PageInfoRsp {
	name: string;
	id: number
};
pageInfo: PageInfoRsp;

export interface Person {
  name: string;
  age?: number;
  [propName: string]: any; // 定义了任意属性取 string 类型的值。
}
let xiaowang: Person = {
  name: 'xiao liu',
  website: 'http://xiaoliu.com',
};
export interface IButtonProps {
	status: number;
	[propName: string]: any;
}

2.| 或间隔

pattern: string | RegExp | Array<string> | Array<number>
value?: string | string[] | number;
type: 'employees' | 'deppartments' | 'tags';
export interface IPicProps {
	type: 'error' | 'success' | 'warn'
}
export interface ITextProps {
	title: string;
	subTitle: string;
}
export interface IResultProps extends IPicProps, ITextProps {
	readonly [propName: string]: any;  // 定义了任意属性取 string 类型的值
}
export interface IShowTipsProps extends React.HTMLProps<HTMLDivElement> {
	readonly content: string;
	readonly position?: 'top' | 'bottom'
}
interface IShowTipsState {
	content: string;
	show: boolean;
}
export default class ToolTips extends React.PureComponent<IShowTipsProps, {}> {

}
export default class ToolTips extends React.PureComponent<IShowTipsProps, IShowTipsState> {

}
export default class ToolTips extends React.Component<IShowTipsProps, IShowTipsState> {

}

3.React.ReactNode

title: React.ReactNode;
title: React.RectNode = (
  <span>标题标题标题</span>
)

4.HTMLElement,HTMLInputElement

const clone: HTMLElement = el.cloneNode();
input: HTMLInputElement

5.函数

onSubmit(data: any): void;
onSubmit: () => void | Promise<boolean | void>;
onCancel?: () => void;
children: (editStatus: boolean) => React.ReactNode;
onSubmit(): Promise<any>;
onChange?(status: 'on' | 'off'): void;
onBack?: Function

6.React.FC

const PageContent: React.FC<IPageContentProps> = props => {
    ......
};

7.React.MouseEventHandler

onClick?: React.MouseEventHandler<Element>;
<a onClick={this.handleClickEvent} target={_blank || '_self'}>a链接点击</a>
<button onClick={this.handleClickEvent}>按钮点击</button>
handleClickEvent: React.MouseEventHandler<
        HTMLButtonElement | HTMLAnchorElement
    > = e => {
    ...
    }

8.React.ChangeEvent

private readonly handleChangeValue = (
    e: React.ChangeEvent<HTMLInputElement>
) => {
    ......
};

9.React.MouseEvent

interface IDeleteIcon {
    allowClear?: boolean;
    onClean: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
}
private readonly handleClean = (
        e: React.MouseEvent<HTMLElement, MouseEvent>
    ) => {
        ......
    };

10.type

export type dataType = 'input' | 'textarea'
export interface ITextProps {
	title: string;
	subTitle: string;
	dataType: dataType
}
type Type = 1 | 2 | 3;
export interface Scope<T extends Type> {
    type: T;
    changeId: string;
    changeName: string;
}
export interface VisibleInfos {
    tags: Array<Scope<3>>;
    employees: Array<Scope<1>>;
    deptments: Array<Scope<2>>;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值