问题
I am writing an app in electron using angular 4. I need a database and want to use websql but I cannot find a way to import websql typings.
I added @types/websql. In my IDE, there is no compil error when i do :
const db: Database = window.openDatabase('foo', '1.0', 'foo', 2 * 1024 * 1024);
but ng serve
gives me :
Property 'openDatabase' does not exist on type 'Window'
I do not have any import specific to @types/websql
. As it is not a module, I don't know how to import it.
Does anyone have any idea on how I can import this ?
回答1:
Ok, I found the solution.
ng-cli generate a tsconfig.app.json with a property types
set to [].
If I understand tsc doc correctly, it prevents the compiler to use the typeRoots
property.
By simply removing this property, my code compile.
回答2:
As in https://www.typescriptlang.org/docs/handbook/tsconfig-json.html:
all visible “@types” packages are included in your compilation ...
If typeRoots is specified, only packages under typeRoots will be included.
If types is specified, only packages under types will be included.
If i put the type in ts.config.app like this configuration:
"types": [
"websql"
]
it will only include the node_modules/@types/websql ignoring others that may have been installed.
来源:https://stackoverflow.com/questions/44385151/angular-2-websql-typings