Auth0.js: Typings need some love

Created on 24 Mar 2016  路  14Comments  路  Source: auth0/auth0.js

Two issues but I'm hitting them both here in case I'm missing something simple.

  • My ide cannot find the type definitions for auth0-js because it's defined as "auth0"
npm install auth0-js --save
typings install auth0 --save --ambient
import * as Auth0 from 'auth0-js';

The exported typings module is named "auth0" while the npm package is "auth0-js". I get around this problem by tweaking the bottom of index.d.ts to declare module "auth0-js" { ... but it's not ideal.

  • The type definition for Auth0Static.getDelegationToken vs implementation do not match

Definition

interface Auth0Static {
    getDelegationToken(targetClientId: string, id_token: string, options: any, callback: (error?: Auth0Error, delegationResult?: Auth0DelegationToken) => any): void;
}

Implementation

Auth0.prototype.getDelegationToken = function (options, callback) {...

Would love to be told I'm making a stupid mistake

Most helpful comment

To complicate matters, Typings has gone 1.0 and has some breaking changes.

typings install auth0 --save --ambient

is now

typings install dt~auth0 --save --global

and the folder structure inside the typings folder has changed (making the problem with editing auth0/index.d.ts immediately apparent).

Watching this thread.

All 14 comments

To complicate matters, Typings has gone 1.0 and has some breaking changes.

typings install auth0 --save --ambient

is now

typings install dt~auth0 --save --global

and the folder structure inside the typings folder has changed (making the problem with editing auth0/index.d.ts immediately apparent).

Watching this thread.

Anyone has a workaround for this?

My PR (https://github.com/DefinitelyTyped/DefinitelyTyped/pull/10653) was just merged. This should now be fixed!

This just caused me a world of pain. @westy92 one of the issues mentioned in the OP is still not fixed with your PR:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f5a12116d0eb27ec1d4e8a1a0730957efbdba3e9/auth0-js/auth0-js.d.ts#L130

the module is still exported as "auth0" when it should be "auth0-js"

I somehow missed that string. I'll submit a PR shortly.

Thanks. There are actually a number of other issues with the typings file, once I've completed my implementation I'll share.

As I mentioned in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/10721#issuecomment-242801261, there are _two_ packages for auth0, so both auth0 and auth0-js are equally valid.

I still get this error after I install types

npm install auth0-js --save
npm install @types/auth0-js --save

   import { Auth0 } from 'auth0-js';

Module '"auth0-js"' has no exported member 'Auth0'.

@CrisLi there is no Auth0 class. Try:

import * as Auth0 from 'auth0-js';

@westy92 I have tried

import * as Auth0 from 'auth0-js';

The error became

node_modules/@types/auth0-js/index.d.ts' is not a module.

The package.json snippet is:

    "@types/auth0-js": "^8.1.0",
    "angular2-jwt": "^0.1.28",
    "auth0-js": "^8.2.0",

I have the same issue as @CrisLi. I was able to fix it locally by changing the top line from:

declare module auth0 {

to

declare module 'auth0-js' {

Not sure how this affects backwards compatibility or if there are any other issues.

For now, I did the following to make the typings work:

  1. Added "typeRoots": ["./types"] to tsconfig.json
  2. Moved index.d.ts from node_modules/@types/auth0-js to types/auth0-js
  3. Fixed the index.d.ts file
  4. Removed node_modules/@types/auth0-js

The above steps require TS >v.2.0.0 and possibly modeResulotion set to node.

I was looking through this trying to figure out the issue, and it looks like it may have been fixed in https://github.com/DefinitelyTyped/DefinitelyTyped/commit/625be7cb6522b3d004b2fe93ace7357686eeb3a4. Can you grab the latest version (8.3.0) and try again?

I fixed this issue in v7 but it appears to have regressed in earlier versions of v8.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edmorley picture edmorley  路  6Comments

duongmanhhoang picture duongmanhhoang  路  3Comments

kmaida picture kmaida  路  7Comments

jorgeucano picture jorgeucano  路  6Comments

lorensr picture lorensr  路  6Comments