VS Code配置ts类型校验

安装 类型声明文件

 pnpm i -D miniprogram-api-typings @uni-helper/uni-app-types

配置 tsconfig.json

types中加入,添加vueCompilerOptions

    "types": [
      "@dcloudio/types", // uni-app API 类型
      "miniprogram-api-typings", // 原生微信小程序类型
      "@uni-helper/uni-app-types" // uni-app 组件类型
    ]
  },
  // vue 编译器类型,校验标签类型
  "vueCompilerOptions": {
    // 原配置 `experimentalRuntimeMode` 现调整为 `nativeTags`
    "nativeTags": ["block", "component", "template", "slot"], // [!code ++]
    "experimentalRuntimeMode": "runtime-uni-app" // [!code --]
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]

  • 15
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用以下类型校验JS事件对象e的类型: ```typescript interface MouseEvent extends UIEvent { readonly altKey: boolean; readonly button: number; readonly buttons: number; readonly clientX: number; readonly clientY: number; readonly ctrlKey: boolean; readonly metaKey: boolean; readonly movementX: number; readonly movementY: number; readonly offsetX: number; readonly offsetY: number; readonly pageX: number; readonly pageY: number; readonly relatedTarget: EventTarget | null; readonly screenX: number; readonly screenY: number; readonly shiftKey: boolean; readonly x: number; readonly y: number; } interface KeyboardEvent extends UIEvent { readonly altKey: boolean; readonly code: string; readonly ctrlKey: boolean; readonly isComposing: boolean; readonly key: string; readonly location: number; readonly metaKey: boolean; readonly repeat: boolean; readonly shiftKey: boolean; } interface UIEvent extends Event { readonly detail: number; readonly view: Window | null; } interface Event { readonly bubbles: boolean; cancelBubble: boolean; readonly cancelable: boolean; readonly composed: boolean; readonly currentTarget: EventTarget | null; readonly defaultPrevented: boolean; readonly eventPhase: number; readonly isTrusted: boolean; returnValue: boolean; readonly target: EventTarget | null; readonly timeStamp: number; readonly type: string; composedPath(): EventTarget[]; initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void; preventDefault(): void; stopImmediatePropagation(): void; stopPropagation(): void; } interface EventTarget { addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void; dispatchEvent(event: Event): boolean; removeEventListener(type: string, listener?: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void; } ``` 以上这些类型都是内置的TypeScript类型,可以直接使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值