我有一个只接受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/

10-09 17:08
查看更多