-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
Type declaration merging doesn't work #715
Comments
Thanks for the detailed report. This is actually expected. See https://github.com/TypeStrong/ts-node#help-my-types-are-missing. Specifically, you're using |
How to make it global? The README's linked TypeScript documentation doesn't mention how. Googling for "typescript global declaration" turns up this example. It's unclear what in all that file's names and comments does the trick. @vladrmnv did you figure it out? |
@john-kurkowski That's a great point, feel free to make a PR updating the documentation around this. I do feel it's confusing from TypeScript's perspective and lacks some good documentation. The difference is around how you define it. Once you add Module: export const bar: string Global: declare module "module" {
export const bar: string
} In general, using a global is for a quick hack and may conflict some time. Using |
@blakeembrey could you provide an example of what you mean by "use paths"? |
@vladrmnv |
@john-kurkowski yep, tried that, bug how would I merge my custom definition with the existing definitions? Such as in my |
@vladrmnv @john-kurkowski did anyone of you figured this out and could post a sample of what needs to be changed? I still don't get it. How can I add a prop to the |
Having the same issue, this fixed it #615 (comment) Basically, add the
|
Thanks to this comment by @blakeembrey, I got my declaration merges working! All you need to do is put "typeRoots": ["./typings", "./node_modules/@types"] |
Here is a working example for those who still struggling (like I was for past few hours):
declare namespace Express { // MUST be namespace, and not declare module "Express" {
export interface Request {
Bla: string;
}
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"typeRoots" : [
"@types", // custom merged types MUST be first in a list
"node_modules/@types",
]
}
} If you are using "paths" in
Afterwards I was able to run |
Extra information. TypeScript guys favor |
@antonovicha this is awesome! you have really saved my day!!! thanks a lot |
can't make it work for process.env my @types/node/process.d.ts
my tsconfig.json
I'm getting "No overload matches this call." error on process.env.TOTO |
@antonovicha |
ts-node src/index.ts All of the above doesn't work with me. #745 (comment) |
this does work! Thanks a lot ! |
I've tried to extend the standard Express Request interface, VSCode is picking up the declaration, but when I run
ts-node index.ts
I get :However running
tsc
works fine. Also this is only a problem with ts-node@7, if I addTS_NODE_FILES=true
it works as expected.Here is a test repo to reporoduce the error:
https://github.com/vladrmnv/ts-node-broken-declaration-merging
The text was updated successfully, but these errors were encountered: