gpt4 book ai didi

file - 在TypeScript中创建文件对象类型

转载 作者:行者123 更新时间:2023-12-03 09:28:50 25 4
gpt4 key购买 nike

我有一个只接受JS File对象的函数。

如何在TypeScript中创建该类型?

编辑:共享我的tsconfig.json

{
"compilerOptions": {
"outDir": "./ts-dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": [
"dom",
"es2017"
]
},
"include": [
"./src/**/*", "./test/**/*"
],
"exclude": [
"node_modules", "dist"
]
}

最佳答案

Typescript具有File的已定义类型,它表示JavaScript中的文件对象。通常,您应该寻找名称为其Javascript计数器类型的类型。您可以在参数的参数注释中使用此类型:

function processFile(file: File) {

}

关于file - 在TypeScript中创建文件对象类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51722363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com