我使用模块passport-google-oauth20和Typescript版本2.2.1,noImplicitAny
设置为true。我尝试用
yarn add @types/passport-google-oauth20
但我收到错误
error Couldn't find package "@types/passport-google-oauth20" on the "npm" registry.
当我使用import {Strategy} from 'passport-google-oauth20';
导入模块时,我收到错误error TS7016: Could not find a declaration file for module 'passport-google-oauth20'. ... implicitly has an 'any' type.
我想摆脱此错误。
作为@types/passport-google-oauth20
的替代,我找到了输入here并通过typings命令安装了它。然后我用
/// <reference path="../../../typings/index.d.ts" />
但我收到错误error TS2451: Cannot redeclare block-scoped variable 'Strategy'.
。
然后我尝试编写自己的类型文件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);
}
并将其包含在/// <reference path="./passport-google-oauth20.d.ts" />
中。现在我又来了
error TS7016: Could not find a declaration file for module 'passport-google-oauth20'... implicitly has an 'any' type.
当我需要时
const google = require('passport-google-oauth20');
...
public create(): google.Strategy {
我得到error TS2503: Cannot find namespace 'google'.
。当我将代码更改为
const Strategy = require('passport-google-oauth20');
...
public create(): Strategy {
我得到error TS2304: Cannot find name 'Strategy'.
。
所以我要做的就是将passport-google-oauth20
与noImplicitAny
一起使用。有人能告诉我怎么样?通常情况下,当没有给出打字时我没有问题,我只是切换到require
所以我想了解这种情况下的特殊内容。
更新:我不确定此问题是否解决了我的问题:import/require deprecation