kevlened / isomorphic-webcrypto

:game_die: webcrypto library for Node, React Native and IE11+
https://www.w3.org/TR/WebCryptoAPI/
MIT License
116 stars 42 forks source link

Typescript error on crypto export... #3

Closed sinewave440hz closed 5 years ago

sinewave440hz commented 6 years ago

node_modules/isomorphic-webcrypto/index.d.ts(2,1): error TS2309: An export assignment cannot be used in a module with other exported elements.

Removing the default export stops typescript complaining. (I'm on typescript 2.7.2)

kevlened commented 6 years ago

Both entries exist so you can import two ways and still get types: 1) import crypto from 'isomorphic-webcrypto'; 2) const crypto = require('isomorphic-webcrypto');

I imagine you stop getting types on the ES6 import example if you remove the default export. I think you'd have to import like this:

import * as crypto from 'isomorphic-webcrypto';

kevlened commented 6 years ago

Seems related to a breaking change introduced in TypeScript 2.7

I'm hesitant to remove the default statement unless both scenarios above work, so we'll probably have to find another solution.

sinewave440hz commented 6 years ago

Ah ok. With my tsconfig I have to have one or the other - this is another thing that I suppose a working example might avoid, if an example tsconfig is supplied... In either case, ensureSecure() is not available in the types (with my ts/tsconfig, at least). Also, getRandomValues() requires an argument (I am told by ts ;) ). What version of typescript did you develop against btw?

kevlened commented 6 years ago

re: ensureSecure - I'll need to add it re: getRandomValues - Yeah, I should def fix that in the docs re: TypeScript version - I didn't develop using TypeScript. I used the intellisense in VSCode to determine whether types were available. I believe my version was backed by 2.6

kevlened commented 6 years ago

I'll include an example using TypeScript to clear this up.

kevlened commented 5 years ago

I set up a React Native TypeScript example with typescript@3.4.5 and I've added the ensureSecure method.

Hope this helps. Closing for now.