Reputation: 888
How do i import FileReader in typescript. I tried this:
var reader:FileReader = new FileReader();
my tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "."
},
"exclude": [
"node_modules",
".vscode-test"
]
}
My error is cannot find name 'FileReader' I am unable to do this too:
import FileReader;
Upvotes: 2
Views: 6000
Reputation: 2949
I ran into this issue as I forgot to add "dom" to the "lib" node in the tsconfig.json
.
Fix:
In your tsconfig.json
ensure under "lib" you have "dom". Here is my current tsconfig.json
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext",
"es5",
"es6"
],
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
}
}
See the below ugly themed VS code the lib.dom.d.ts
is where the FileReader
interface lives which made me realise I was missing "dom"
Upvotes: 4