Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript compiler errors when importing some file(s) if we use "strict": true at tsconfig.json #174

Closed
Muhammad-Altabba opened this issue May 20, 2021 · 5 comments · Fixed by #175
Labels
bug Something isn't working enhancement New feature or request

Comments

@Muhammad-Altabba
Copy link

The problem
TypeScript compiler errors when importing some file(s) if we use "strict": true at tsconfig.json.

Details
I have the following

{
  "compilerOptions": {
     "strict": true,
....

When import { toJose } from 'did-jwt/src/util'; the following error came:

node_modules/did-jwt/src/util.ts:75:18 - error TS2322: Type 'number | undefined' is not assignable to type 'number'.
  Type 'undefined' is not assignable to type 'number'.

75   return { r, s, recoveryParam }
                    ~~~~~~~~~~~~~

  node_modules/did-jwt/src/util.ts:67:70
    67 export function fromJose(signature: string): { r: string; s: string; recoveryParam: number } {
                                                                            ~~~~~~~~~~~~~
    The expected type comes from property 'recoveryParam' which is declared here on type '{ r: string; s: string; recoveryParam: number; }'

Describe the solution you'd like
I suggest to enable strict mode for the TypeScript compiler and fix for related issues. This will make the library more usable for other projects.

Describe alternatives you've considered
I had to use "strict": false at my tsconfig.json which is something not desired.

@Muhammad-Altabba
Copy link
Author

Do you like me to open an MR regarding this?

@mirceanis
Copy link
Member

Do you like me to open an MR regarding this?

Hey, thanks for reporting this.
There is already a PR( #175 ) with a fix for this issue and others, but it will take some more time until it is merged because of other potentially conflicting work that is in progress.

In the meantime, you can try to add skipLibCheck: true to your tsconfig.json

@Muhammad-Altabba
Copy link
Author

Thanks @mirceanis ,
I add skipLibCheck: true to my tsconfig.json. This could make the plugin to compile. However, when using that plugin in another project I face the error:

netid-kms-plugin/node_modules/did-jwt/src/util.ts:1
import * as u8a from 'uint8arrays'
^^^^^^
SyntaxError: Cannot use import statement outside a module

This is because I could not import the function I need directly. I could only import it using:

import { bytesToBase64url, hexToBytes, toJose } from 'did-jwt/src/util';

And that is because the functions inside did-jwt/src/util are not exported in the index file. I think we need to add the following to did-jwt/src/index.tx as follow:

export { 
  base58ToBytes, 
  base64ToBytes, 
  bytesToBase58, 
  bytesToBase64, 
  bytesToBase64url, 
  bytesToHex,
  decodeBase64url,
  encodeBase64url,
  fromJose,
  hexToBytes,
  EcdsaSignature,
  leftpad,
  parseKey,
  stringToBytes,
  toJose,
  toSealed} from './util'

What do you think?

Many thanks,

@mirceanis
Copy link
Member

The required methods are small enough to be implemented directly in your code-base. If we export them from did-jwt then we would have to maintain them in future versions and at the moment they are out of the scope of this library.
After #170 is settled, then there might be a utility package, but until then it is easier to use something like uint8arrays directly to perform these encoding conversions.

mirceanis added a commit that referenced this issue Jun 2, 2021
…175)

* fix(build): produce non-minified output for module

fixes #173

* fix(build): fix strict compiler errors for most of the code

fixes #174

* chore(ci): adjust bot schedule for less noise

* fix(style): enable strict mode and fix strict compiler errors

* chore(style): enable eslint and fix linter errors

* chore: clarify usage of JWK epk and proof types for signing
uport-automation-bot pushed a commit that referenced this issue Jun 2, 2021
## [5.5.1](5.5.0...5.5.1) (2021-06-02)

### Bug Fixes

* **build:** non-minified outputs and better handling of strict mode ([#175](#175)) ([029b429](029b429)), closes [#173](#173) [#174](#174)
* **ci:** add GH push ability to build bot ([e50edf6](e50edf6))
@uport-automation-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 5.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants