How to import an interface from @types in index.d.ts?
Express exposes Express.Request
, Express.Response
but I also need Express.NextFunction
interface which is not available in the Express namespace.
How to use the NextFunction
interface in index.d.ts?
Context:
index.d.ts
declares a namespace ServerPlugin.ServerPlugin contains an interface called Params
Anywhere in the app, I can use
ServerPlugin.Params
as expected
But, as soon as I import NextFunction from @types/express, in index.d.ts
I get errors in all files using ServerPlugin.Params
.
Cannot find namespace 'ServerPlugin'
index.d.ts
If not importing NextFunction
and commenting out next
=> no error
declare namespace ServerPlugin {
interface Params {
req: Express.Response;
res: Express.Request;
next: NextFunction;
options: object;
// ... and much more
}
}
import { NextFunction } from 'express';
user.ts
This file says it cannot find namespace ServerPlugin.
If I import { ServerPlugin } from '../../index'
, no error, but I did not have to import before using NextFunction.
import { userViewerChunk } from './graphql/UserType';
const user: Function = ({ next, extendSchema }: ServerPlugin.Params): void => {
extendSchema(userViewerChunk);
next();
};
export default user;
typescript typescript-typings
add a comment |
Express exposes Express.Request
, Express.Response
but I also need Express.NextFunction
interface which is not available in the Express namespace.
How to use the NextFunction
interface in index.d.ts?
Context:
index.d.ts
declares a namespace ServerPlugin.ServerPlugin contains an interface called Params
Anywhere in the app, I can use
ServerPlugin.Params
as expected
But, as soon as I import NextFunction from @types/express, in index.d.ts
I get errors in all files using ServerPlugin.Params
.
Cannot find namespace 'ServerPlugin'
index.d.ts
If not importing NextFunction
and commenting out next
=> no error
declare namespace ServerPlugin {
interface Params {
req: Express.Response;
res: Express.Request;
next: NextFunction;
options: object;
// ... and much more
}
}
import { NextFunction } from 'express';
user.ts
This file says it cannot find namespace ServerPlugin.
If I import { ServerPlugin } from '../../index'
, no error, but I did not have to import before using NextFunction.
import { userViewerChunk } from './graphql/UserType';
const user: Function = ({ next, extendSchema }: ServerPlugin.Params): void => {
extendSchema(userViewerChunk);
next();
};
export default user;
typescript typescript-typings
1
I'm not following your problem here. Yourindex.d.ts
example seems to compile fine, and I have no problem mixing an import ofServerPlugin
fromindex.d.ts
and importingNextFunction
fromexpress
. Can you at least show the compiler error you're getting?
– Alex
Nov 21 '18 at 15:57
1
I just solved the issue by renaming index.d.ts to global.d.ts. Do you think the issue occured because I had a index.ts at the same level as index.d.ts? index.ts was just exporting all undelying modules.
– Asten Mies
Nov 21 '18 at 16:43
1
Yes, typescript has a fuzzy logic for matching imports. If you runtsc --traceResolution
it will give you extremely verbose output about what filenames it tries and in what order. See typescriptlang.org/docs/handbook/… for the official documentation. If you give it a name likeimport x from "abc"
it searches a bunch of extension patterns (defined in the link above) until it finds the first match. Specifically,.ts
is searched before.d.ts
, so that would cause your problem.
– Alex
Nov 21 '18 at 16:52
@Alex Thanks, much appreciated. Please feel free to extend your comment as an answer so I can select it as the answer and upvote.
– Asten Mies
Nov 21 '18 at 17:06
add a comment |
Express exposes Express.Request
, Express.Response
but I also need Express.NextFunction
interface which is not available in the Express namespace.
How to use the NextFunction
interface in index.d.ts?
Context:
index.d.ts
declares a namespace ServerPlugin.ServerPlugin contains an interface called Params
Anywhere in the app, I can use
ServerPlugin.Params
as expected
But, as soon as I import NextFunction from @types/express, in index.d.ts
I get errors in all files using ServerPlugin.Params
.
Cannot find namespace 'ServerPlugin'
index.d.ts
If not importing NextFunction
and commenting out next
=> no error
declare namespace ServerPlugin {
interface Params {
req: Express.Response;
res: Express.Request;
next: NextFunction;
options: object;
// ... and much more
}
}
import { NextFunction } from 'express';
user.ts
This file says it cannot find namespace ServerPlugin.
If I import { ServerPlugin } from '../../index'
, no error, but I did not have to import before using NextFunction.
import { userViewerChunk } from './graphql/UserType';
const user: Function = ({ next, extendSchema }: ServerPlugin.Params): void => {
extendSchema(userViewerChunk);
next();
};
export default user;
typescript typescript-typings
Express exposes Express.Request
, Express.Response
but I also need Express.NextFunction
interface which is not available in the Express namespace.
How to use the NextFunction
interface in index.d.ts?
Context:
index.d.ts
declares a namespace ServerPlugin.ServerPlugin contains an interface called Params
Anywhere in the app, I can use
ServerPlugin.Params
as expected
But, as soon as I import NextFunction from @types/express, in index.d.ts
I get errors in all files using ServerPlugin.Params
.
Cannot find namespace 'ServerPlugin'
index.d.ts
If not importing NextFunction
and commenting out next
=> no error
declare namespace ServerPlugin {
interface Params {
req: Express.Response;
res: Express.Request;
next: NextFunction;
options: object;
// ... and much more
}
}
import { NextFunction } from 'express';
user.ts
This file says it cannot find namespace ServerPlugin.
If I import { ServerPlugin } from '../../index'
, no error, but I did not have to import before using NextFunction.
import { userViewerChunk } from './graphql/UserType';
const user: Function = ({ next, extendSchema }: ServerPlugin.Params): void => {
extendSchema(userViewerChunk);
next();
};
export default user;
typescript typescript-typings
typescript typescript-typings
edited Nov 21 '18 at 12:58
Asten Mies
asked Nov 21 '18 at 12:38
Asten MiesAsten Mies
543211
543211
1
I'm not following your problem here. Yourindex.d.ts
example seems to compile fine, and I have no problem mixing an import ofServerPlugin
fromindex.d.ts
and importingNextFunction
fromexpress
. Can you at least show the compiler error you're getting?
– Alex
Nov 21 '18 at 15:57
1
I just solved the issue by renaming index.d.ts to global.d.ts. Do you think the issue occured because I had a index.ts at the same level as index.d.ts? index.ts was just exporting all undelying modules.
– Asten Mies
Nov 21 '18 at 16:43
1
Yes, typescript has a fuzzy logic for matching imports. If you runtsc --traceResolution
it will give you extremely verbose output about what filenames it tries and in what order. See typescriptlang.org/docs/handbook/… for the official documentation. If you give it a name likeimport x from "abc"
it searches a bunch of extension patterns (defined in the link above) until it finds the first match. Specifically,.ts
is searched before.d.ts
, so that would cause your problem.
– Alex
Nov 21 '18 at 16:52
@Alex Thanks, much appreciated. Please feel free to extend your comment as an answer so I can select it as the answer and upvote.
– Asten Mies
Nov 21 '18 at 17:06
add a comment |
1
I'm not following your problem here. Yourindex.d.ts
example seems to compile fine, and I have no problem mixing an import ofServerPlugin
fromindex.d.ts
and importingNextFunction
fromexpress
. Can you at least show the compiler error you're getting?
– Alex
Nov 21 '18 at 15:57
1
I just solved the issue by renaming index.d.ts to global.d.ts. Do you think the issue occured because I had a index.ts at the same level as index.d.ts? index.ts was just exporting all undelying modules.
– Asten Mies
Nov 21 '18 at 16:43
1
Yes, typescript has a fuzzy logic for matching imports. If you runtsc --traceResolution
it will give you extremely verbose output about what filenames it tries and in what order. See typescriptlang.org/docs/handbook/… for the official documentation. If you give it a name likeimport x from "abc"
it searches a bunch of extension patterns (defined in the link above) until it finds the first match. Specifically,.ts
is searched before.d.ts
, so that would cause your problem.
– Alex
Nov 21 '18 at 16:52
@Alex Thanks, much appreciated. Please feel free to extend your comment as an answer so I can select it as the answer and upvote.
– Asten Mies
Nov 21 '18 at 17:06
1
1
I'm not following your problem here. Your
index.d.ts
example seems to compile fine, and I have no problem mixing an import of ServerPlugin
from index.d.ts
and importing NextFunction
from express
. Can you at least show the compiler error you're getting?– Alex
Nov 21 '18 at 15:57
I'm not following your problem here. Your
index.d.ts
example seems to compile fine, and I have no problem mixing an import of ServerPlugin
from index.d.ts
and importing NextFunction
from express
. Can you at least show the compiler error you're getting?– Alex
Nov 21 '18 at 15:57
1
1
I just solved the issue by renaming index.d.ts to global.d.ts. Do you think the issue occured because I had a index.ts at the same level as index.d.ts? index.ts was just exporting all undelying modules.
– Asten Mies
Nov 21 '18 at 16:43
I just solved the issue by renaming index.d.ts to global.d.ts. Do you think the issue occured because I had a index.ts at the same level as index.d.ts? index.ts was just exporting all undelying modules.
– Asten Mies
Nov 21 '18 at 16:43
1
1
Yes, typescript has a fuzzy logic for matching imports. If you run
tsc --traceResolution
it will give you extremely verbose output about what filenames it tries and in what order. See typescriptlang.org/docs/handbook/… for the official documentation. If you give it a name like import x from "abc"
it searches a bunch of extension patterns (defined in the link above) until it finds the first match. Specifically, .ts
is searched before .d.ts
, so that would cause your problem.– Alex
Nov 21 '18 at 16:52
Yes, typescript has a fuzzy logic for matching imports. If you run
tsc --traceResolution
it will give you extremely verbose output about what filenames it tries and in what order. See typescriptlang.org/docs/handbook/… for the official documentation. If you give it a name like import x from "abc"
it searches a bunch of extension patterns (defined in the link above) until it finds the first match. Specifically, .ts
is searched before .d.ts
, so that would cause your problem.– Alex
Nov 21 '18 at 16:52
@Alex Thanks, much appreciated. Please feel free to extend your comment as an answer so I can select it as the answer and upvote.
– Asten Mies
Nov 21 '18 at 17:06
@Alex Thanks, much appreciated. Please feel free to extend your comment as an answer so I can select it as the answer and upvote.
– Asten Mies
Nov 21 '18 at 17:06
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412209%2fhow-to-import-an-interface-from-types-in-index-d-ts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412209%2fhow-to-import-an-interface-from-types-in-index-d-ts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I'm not following your problem here. Your
index.d.ts
example seems to compile fine, and I have no problem mixing an import ofServerPlugin
fromindex.d.ts
and importingNextFunction
fromexpress
. Can you at least show the compiler error you're getting?– Alex
Nov 21 '18 at 15:57
1
I just solved the issue by renaming index.d.ts to global.d.ts. Do you think the issue occured because I had a index.ts at the same level as index.d.ts? index.ts was just exporting all undelying modules.
– Asten Mies
Nov 21 '18 at 16:43
1
Yes, typescript has a fuzzy logic for matching imports. If you run
tsc --traceResolution
it will give you extremely verbose output about what filenames it tries and in what order. See typescriptlang.org/docs/handbook/… for the official documentation. If you give it a name likeimport x from "abc"
it searches a bunch of extension patterns (defined in the link above) until it finds the first match. Specifically,.ts
is searched before.d.ts
, so that would cause your problem.– Alex
Nov 21 '18 at 16:52
@Alex Thanks, much appreciated. Please feel free to extend your comment as an answer so I can select it as the answer and upvote.
– Asten Mies
Nov 21 '18 at 17:06