-
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
Import types in d.ts files contain relative paths to node_modules #24599
Comments
Small repro: // @declaration: true
// @filename: node_modules/foo/index.d.ts
export interface SomeProps {
x: number;
}
export function foo(): SomeProps;
// @filename: entry.ts
import { foo } from "foo";
export const x = foo(); emits export declare const x: import("./node_modules/foo/index").SomeProps; you'd much rather it use the node module resolution style There is a wrench, though: // @declaration: true
// @filename: node_modules/foo/other/index.d.ts
export interface OtherIndexProps {}
// @filename: node_modules/foo/other.d.ts
export interface OtherProps {}
// @filename: node_modules/foo/index.d.ts
import { OtherProps } from "./other";
import { OtherIndexProps } from "./other/index";
export function foo(): [OtherProps, OtherIndexProps];
// @filename: entry.ts
import { foo } from "foo";
export const x = foo(); in this case, writing Minimally, stripping off the leading relative dir parts and |
I can reproduce this issue in 2.9.1, it's a major blocker for us in upgrading to TS2.9. |
TypeScript 2.9.2 made some changes to this but it's still broken. 2.9.1 generated type import paths like In my case just |
Workaround for microsoft/TypeScript#24599 Manually fixed the type imports in the emitted declaration files
@epeli can you give |
@mhegazy we still haven't published a nightly this week. |
Sure. Can you ping me when it's out so I can test it? |
I too am seeing this problem; my imports in the declarations are going all the way to my filesystem root. I think this might have something to do with the There's a nested dependency in my code, where I have this import:
If
Not what I expect! I would expect it to be Then, if I set
Yeah, shouldn't be an absolute path now, since I have no |
@osdiab do you see the same thing with |
Yes, on typescript@^3.0.0-dev20180616
…On Sat, Jun 16, 2018 at 17:10 Wesley Wigham ***@***.***> wrote:
@osdiab <https://github.com/osdiab> do you see the same thing with
***@***.***?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24599 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzabqAQjafbWX2yRrJVqY8K1DKJ60WNks5t9XQxgaJpZM4UXXxN>
.
|
What're all the rest of your tsconfig options (outDir, rootDir, etc), and are there any symlinks in your project? |
No symlinks, here’s the tsconfig:
```
{
"compilerOptions": {
"target": "es2015",
"module": "esnext",
"moduleResolution": "node",
"lib": ["es2018"],
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"declaration": true
},
"exclude": ["node_modules", "dist"]
}
```
…On Sat, Jun 16, 2018 at 14:39 Wesley Wigham ***@***.***> wrote:
What're all the rest of your tsconfig options (outDir, rootDir, etc), and
are there any symlinks in your project?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24599 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzabrbuKQgAuRiTpjWV3O9xSHNHf59sks5t9XslgaJpZM4UXXxN>
.
|
If you need something to reproduce this with you can use my redux-stack lib. There is no
and checkout the type imports in |
I am also seeing this issue.
We have a custom build process that copies the build files to a slightly different directory structure than the source code, so this relative path is incorrect. |
Got biten by this. I have a function whose return type is implicit and lives in another file my project. When compiling with Typescript 2.9.1:
Typescript 2.9.2:
This is a very bad regression! 2.9.1 worked well enough, because it stayed inside my declarations folder. |
Hello, I am bit confused as this issue seems to be tracking two different problems.
So does #25110 solve both or just the 2nd issue? |
@tyler-johnson please give |
@mhegazy I can confirm excessive |
I still see export declare const fetchFilterCategories: ({ entityType, entityId }: any) => import("node_modules/axios").AxiosPromise<any>; to reproduce: import Axios from 'axios'
export const fetchFilterCategories = ({ entityType, entityId }: any) => {
return Axios.get(`sd`);
}; Also have such references /// <reference path="../node_modules/@types/lodash/common/common.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/array.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/collection.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/date.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/function.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/lang.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/math.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/number.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/object.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/seq.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/string.d.ts" />
/// <reference path="../node_modules/@types/lodash/common/util.d.ts" /> compile to reproduce: import {mapValues} from 'lodash';
export const mapDispatchToProps = mapValues ts version: |
Should be fixed by #25364, please open a new issue if you see any |
|
|
Is there any chance of getting this out into a 2.9 patch release, so we don't have to wait for v3 (which some of us might not be able to upgrade to immediately)? We've just upgraded to 2.9 and then stumbled into this which is a bit of a pain. |
3.0 should be available next week. |
3.0 arriving soon is great, but allow me to second @OliverJAsh's request for a backport to the 2.9 series; I have a library that this broke and would strongly prefer not to have to set a minimum requirement of 3.0 for people consuming its types. |
I still see #24599 (comment) for tsx files with next typescript. |
A downgrade is necessary to prevent this issue from happening: microsoft/TypeScript#24599
TypeScript Version: 3.0.0-dev.20180601
Search Terms: declaration import types
Code
src/one/two/export.ts:
src/one/two/consumer.ts:
Expected behavior:
consumer.d.ts has something like
Actual behavior:
It has relative paths to node_modules, based on the source file's location at compile time. This places an assumption on the location of the d.ts file when it's consumed externally.
Playground Link: N/A
Related Issues: #24556, but csstype does specify a types key in package.json
The text was updated successfully, but these errors were encountered: