# FAQ

# 忽略类型检查

单行忽略(添加到特定行的行前来忽略这一行的错误)

// @ts-ignore

跳过对某些文件的检查 (添加到该文件的首行才起作用)

// @ts-nocheck

对某些文件的检查

// @ts-check

# 设置全局的对象变量

//GlobalWindow.d.ts
declare interface Window {
  googleCallback: (res: any) => void;
  fbCallback: (res: any) => void;
  reCaptchaLoadCallback: () => void;
  FB: any;
  performance: any;
  gtag: any;
}

# React组件中的ts类型

input 输入框

const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
  const value = e.target.value;
  setInputValue(value);
};

<input type="text" value={inputValue} onChange={onInputChange} />

children类型

type ChildrenProps = {
  children: React.ReactNode;
  age: string;
};

function Children(props: ChildrenProps) {
  const { age, children } = props;
  return (
    <>
      <div>{age}</div>
      <div>{children}</div>
    </>
  );
}

ReactNode的定义如下

type ReactNode = ReactElement | string | number | ReactFragment | ReactPortal | boolean | null | undefined;
陕ICP备20004732号-3