A node module without typing
I am using module passport-google-oauth20 and Typescript version 2.2.1 with noImplicitAny
set to true. I tried to set typing with
yarn add @types/passport-google-oauth20
but i get the error
error Couldn't find package "@types/passport-google-oauth20" on the "npm" registry.
When I import the module using import {Strategy} from 'passport-google-oauth20';
, I get the error error TS7016: Could not find a declaration file for module 'passport-google-oauth20'. ... implicitly has an 'any' type.
I want to get rid of this error.
Alternatively, @types/passport-google-oauth20
I found typing here and installed it via typings . Then I referenced it with
/// <reference path="../../../typings/index.d.ts" />
But I am getting error error TS2451: Cannot redeclare block-scoped variable 'Strategy'.
.
Then I tried to write my own file like passport-google-oauth20.d.ts
:
/// <reference types="passport"/>
import passport = require('passport');
declare class Strategy implements passport.Strategy {
public name: string;
public constructor(options: IStrategyOption,
verify: (accessToken: string,
refreshToken: string,
profile: Profile,
done: (error: any, user?: any, info?: any) => void) => void);
}
and enable it with /// <reference path="./passport-google-oauth20.d.ts" />
. Now I get again
error TS7016: Could not find a declaration file for module 'passport-google-oauth20'... implicitly has an 'any' type.
When i need it
const google = require('passport-google-oauth20');
...
public create(): google.Strategy {
I get it error TS2503: Cannot find namespace 'google'.
. When I change the code to
const Strategy = require('passport-google-oauth20');
...
public create(): Strategy {
I receive error TS2304: Cannot find name 'Strategy'.
.
So, all I want to do is use passport-google-oauth20
with noImplicitAny
. Can anyone tell me how? Usually I have no problem when there is no text input, I just switch to require
, so I want to know what is special about this.
Update: I'm not sure if this issue is related to my problem: import / deprecation need p>
source to share
No one has answered this question yet
Check out similar questions: