Reputation: 1645
I have a function that should only accept JS File objects.
How do I create that type in TypeScript?
edit: sharing my 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"
]
}
Upvotes: 21
Views: 63993
Reputation: 250106
TypeScript has a defined interface for File
which represents the file object in JavaScript. Generally you should look for types named as their Javascript countertypes. You can use this type in a parameter annotation for the parameter:
function processFile(file: File) {
}
Source: microsoft/TypeScript
Upvotes: 32