typescript - 如何在 googleapis 中使用 Typescript 类型(特别是使用 drive_v3 时的文件类型)
问题描述
我有这是我的package.json
:
"dependencies": {
"googleapis": "^50.0.0"
}
我的index.ts
文件中有这个:
import {drive_v3} from "googleapis";
const {Schema$File} = drive_v3.Schema$File
console.log({x:Schema$File})
tsc
告诉我:
error TS2339: Property 'Schema$File' does not exist on type 'typeof drive_v3'.
但是当我查看.d.ts
文件时,我可以看到是否在那里声明
使用 drive_v3 api 时导入“Google Drive File”类型的正确方法是什么?
解决方案
派对迟到了,但你可以这样做
import { drive_v3 } from 'googleapis'
type DriveFile = drive_v3.Schema$File
const file: DriveFile = ....
或者只是使用drive_v3.Schema$File
而不是重新分配它。
推荐阅读
- flutter - 如何根据选择的第一项颤动填充第二个 DropdownMenu
- java - 有没有办法使用hibernate从java监控数据库性能?
- ios - Alamofire 未创建身份验证标头来发送凭据
- angular - Angular Scehmatics 中的条件“X-Prompt”
- javascript - 如何计算与矩形外接的圆的大小?
- php - 我应该如何在 git 下的 Laravel 项目中工作,同时在同一个 laravel 项目的 component/ 文件夹中的 Laravel 组件中工作
- python - 通过映射现有列创建新列
- jax-rs - 在资源接口的实现类中处理自定义注解
- sql - postgressql中的datediff函数
- excel - 如何在字符串 VBA 中分配范围?