-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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@2_ ambient module cannot be resolved in the right way #11136
Comments
After reading issue #11133 , I find out that when I move the However, this module extends another module. According to the module-plugin.d.ts in handbook, when I want to extend and add some new functions or properties into another module, I have to import the module which will to be extended outside the |
When I try to move the extension into // Type definitions for Koa-Passport v2.2.2
declare module "koa-passport" {
import * as express from 'express';
export function foo();
import * as koa from "koa";
module "koa" {
export interface Request {
authInfo?: any;
}
export interface Middleware {
(ctx: koa.Context, next: () => Promise<any>): any;
}
}
} |
first in your tsconfig.json add Second. is this file intended to live on definitlyTyped and @types? The way you defined the module should work: // Declare your module
declare module "koa-passport" {
import * as express from 'express';
export function foo();
// Augment `Koa` module
module "koa" {
....
}
} I would recommend however, you define // types/koa-passport/index.d.ts
// Local exports
export declare function foo();
// Augment the other module Koa
declare module "Koa" {
......
} then add path mapping entry in your tsconfig for this file: {
"compilerOptions": {
"koa-passport" : ["types/koa-passport"]
}
} |
@mhegazy do you mean {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"koa-passport" : ["types/koa-passport"]
}
}
} or has this changed? |
thanks @aluanhaddad for the correction. yes. i meant to include |
up to you. you could also do a wild card matching like so: {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*" : [ "*" , "types/*"]
}
}
} which says: For every module |
thank you very much. |
TypeScript Version: 2.0.3
OS: win10
Nodejs: 6.6.0
Code
In
./src/index.ts
In
./src/types/koa-passport/index.d.ts
In
tsconfig.json
Expected behavior:
package
koa-passport
can be imported and have intellisense in the right way.Actual behavior:
No intellisense and cannot find the module
koa-passport
According to the tracing log of module resolution, typescript will resolve the module
koa-passport
in a path likes.../node_modules/**/koa-passport
. Therefore the module cannot be find.However, the handbook mentions that
So is this a bug ? Or I just made some mistakes and didn't write the ambient module declaration correctly ?
The text was updated successfully, but these errors were encountered: