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 example fails #30

Open
Tyguy7 opened this issue Oct 5, 2019 · 7 comments
Open

Typescript example fails #30

Tyguy7 opened this issue Oct 5, 2019 · 7 comments

Comments

@Tyguy7
Copy link

Tyguy7 commented Oct 5, 2019

The provided typescript usage produces a typescript error:

import * as basicAuth from 'express-basic-auth'
app.use(basicAuth(options), (req: basicAuth.IBasicAuthedRequest, res, next) => {
    res.end(`Welcome ${req.auth.user} (your password is ${req.auth.password})`)
    next()
})

Produces this error:

This expression is not callable.
Type 'typeof expressBasicAuth' has no call signatures.ts(2349)
service.ts(6, 1): Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

@toverux
Copy link
Contributor

toverux commented Oct 5, 2019

Huh, that should work. That always worked like this, not only for this library.
Can you tell us what's your TypeScript version, configuration (tsconfig.json), and try with a default import (import basicAuth from 'express-basic-auth')?

@nhopp
Copy link

nhopp commented Dec 1, 2019

Check to see if you have "esModuelInterop":true enabled in your tsconfig.json file. I ran into the same error and disabling this setting resolved the error.

@DarkLite1
Copy link

DarkLite1 commented Jul 27, 2020

Same issue but for standard Exrpess:

app.use(
  passport.authenticate('oauth-bearer', { session: false }),
  (next) => {
    next()
  }
)

Throws the TS error:
image

Tried the suggestion "esModuelInterop":false but no luck.

Current workaround:

app.use(
  passport.authenticate('oauth-bearer', { session: false }),
  (next: CallableFunction) => {
    next()
  }
)

Another option is to start the unused variables with an underscore:

app.use(
  passport.authenticate('oauth-bearer', { session: false }),
  (_req, _res, next) => {
    next()
  }
)

TypeScript version 3.9.7

@ikarasz
Copy link

ikarasz commented Mar 24, 2021

The provided typescript usage produces a typescript error:

import * as basicAuth from 'express-basic-auth'
app.use(basicAuth(options), (req: basicAuth.IBasicAuthedRequest, res, next) => {
    res.end(`Welcome ${req.auth.user} (your password is ${req.auth.password})`)
    next()
})

Produces this error:

This expression is not callable. Type 'typeof expressBasicAuth' has no call signatures.ts(2349) service.ts(6, 1): Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.

For me basicAuth.default has solved the issue:

import * as basicAuth from 'express-basic-auth';

...

app.use(basicAuth.default({
  users: {
    uname: 'secret',
  },
  challenge: true,
}));

@NixBiks
Copy link

NixBiks commented Oct 7, 2021

Fails for me as well. Can't get basicAuth.IBasicAuthedRequest to work with requests

@LionC
Copy link
Owner

LionC commented Oct 19, 2021

I did not maintain the package for a while (simply did not have time), but I recently returned to open source work. I will revive my TS rewrite branch next week and make sure to release a new version written in Typescript until the end of the month, as a lot of people still depend on this package.

Thank you for the patience and activity everyone :-)

@sephentos
Copy link

sephentos commented Sep 2, 2022

I did not maintain the package for a while (simply did not have time), but I recently returned to open source work. I will revive my TS rewrite branch next week and make sure to release a new version written in Typescript until the end of the month, as a lot of people still depend on this package.

Thank you for the patience and activity everyone :-)

Any update here, @LionC ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants