4

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 ?

ctruchi
  • 153
  • 7

2 Answers2

3

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.

ctruchi
  • 153
  • 7
1

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.

joaoacj
  • 11
  • 3
  • You should consider providing an explanation with your answer. For more information, please read : [How do I write a good answer ?](https://stackoverflow.com/help/how-to-answer) – Mickael Nov 20 '17 at 15:07