【发布时间】:2019-03-18 18:49:53
【问题描述】:
我正在尝试为包 passport-twitchtv 制作打字稿定义文件,但似乎无法让它找到定义。
示例定义文件:
/// <reference types="passport"/>
import passport = require('passport');
import express = require('express');
interface Profile extends passport.Profile {
id: string;
username: string;
displayName: string;
email: string;
_raw: string;
_json: any;
}
interface IStrategyOptionBase {
clientID: string;
clientSecret: string;
callbackURL: string;
scope: string;
}
interface IStrategyOption extends IStrategyOptionBase {
passReqToCallback?: false;
}
interface IStrategyOptionWithRequest extends IStrategyOptionBase {
passReqToCallback: true;
}
declare class Strategy extends passport.Strategy {
constructor(options: IStrategyOption,
verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void);
constructor(options: IStrategyOptionWithRequest,
verify: (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void);
name: string;
authenticate(req: express.Request, options?: Object): void;
}
导入方式:
import { Strategy as TwitchStrategy } from 'passport-twitchtv';
我收到错误消息:“找不到模块 'passport-twitchtv' 的声明文件”。
如果我将文件放到我的 node_modules/@types/passport-twitchtv 中它可以工作,但我无法让打字稿找到 .d.ts 文件。
我尝试将 typeRoots 添加到 tsconfig.json 中的 compilerOptions,添加 typings.json 文件,将 "typings": "./typings/index" 添加到包文件中。我尝试的任何方法似乎都不起作用。
不确定我是否应该在不在 node_modules/@types 文件夹中时声明模块。
【问题讨论】:
标签: node.js typescript