Skip to content
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

Wrong import path on "relaxed" declaration file #25769

Closed
netanelgilad opened this issue Jul 18, 2018 · 10 comments
Closed

Wrong import path on "relaxed" declaration file #25769

netanelgilad opened this issue Jul 18, 2018 · 10 comments
Labels
Duplicate An existing issue was already created

Comments

@netanelgilad
Copy link

TypeScript Version: 2.9.2

Search Terms:
wrong import declaration file
import relative to root

Code

A link to a repo for reproduction

// Check.ts
export type Inner = {
    something: number;
}
// Another.ts
import {  Inner } from './Check';

export function foo(): Inner {
    return {
        something: 1
    };
}
// index.ts
import { foo } from './Another';

export function bar() {
    return foo();
}

Expected behavior:

Declaration file for index.d.ts should be

export declare function bar(): import("./Check").Inner;

Actual behavior:

Declaration file for index.d.ts is

export declare function bar(): import("../../../../../Users/netanelgilad/Development/typescript-declaration-import-bug/src/Check").Inner;

Related Issues:
N/A

So I encountered this issue with [email protected]. I did a few checks with different versions. using typescript@next or [email protected], this works fine. I don't know what your strategy for supporting version 2 of TypeScript, but since the next version of TypeScript is a major release, I would rather not upgrade to it until I feel it has stabilized and there are not breaking changes that affect my projects. Will you consider fixing this in 2.9 release line of TypeScript? It would be greatly appreciated.

@j-oliveras
Copy link
Contributor

j-oliveras commented Jul 18, 2018

Duplicate of #25279, should be fixed at version 3.

Or related to it.

@netanelgilad
Copy link
Author

Hey @j-oliveras, thanks for the quick reply!
I am aware of issues like #25279, but I'm missing how this issue is a duplicate? This one is not about quick fixes/suggested import but about emitted paths in declaration files.

I assume the cause is the same, and as I mentioned I know it was fixed in typescript@next, but the version the fix gets into has a meaningful impact. If this gets fixed by version 3 and vs code picks up version 3, all is good for the quick fixes. But even if version 3 gets released and vs code picks it up, it doesn't change the way I'm compiling my projects (which is still on the version 2 release line).

So the main point of this issue is to know whether you intend to keep support for version 2 release line and if so, in my humble opinion, this should make it into a 2.9.3 kind of version.

Thanks again for taking the time!

@j-oliveras
Copy link
Contributor

Sorry, incorrect issue.

Duplicate of #24599, that should be fixed at version 3 too.

I think they will publish version 3 this week or next week, @mhegazy or @DanielRosenwasser can answer it.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 18, 2018

I believe this should be fixed in typescript@next. can you please give it a try and let us know if that is not the case.

3.0 should not have breaking changes vs 2.9. so you should be able to upgrade from 2.9 to 3.0.

[email protected] is out already. [email protected] should be available before the end of the month, and the next VSCode should have the fix. We have no plans on shipping a new 2.9 release.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jul 18, 2018
@bradleyayers
Copy link

bradleyayers commented Jul 19, 2018

This isn't fixed for me in 3.1.0-dev.20180717, https://unpkg.com/@heydovetail/[email protected]/lib.es2015/compose.d.ts shows import("src/composing") instead import("./composing"). It looks like it's emitting an absolute import for a relative path, so my issue might actually be different from this one.

Update: For now I've written a script that I run after tsc to fix all the imports.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 19, 2018

Do you have baseUrl set in your tsconfig.json?

@bradleyayers
Copy link

I have baseUrl set to ./ and the emit is import("src/composing"), when I set it to ./src the emit is import("composing"). In both cases it's emitting an absolute import when I'd expect a relative import. For more details see tsconfig.lib.es2015.json extending tsconfig.lib.json extending tsconfig.json. I'm currently on TypeScript 3.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 19, 2018

Do you need the baseUrl?

@bradleyayers
Copy link

Nope—removing it fixes the imports. Excellent! I think the reason I had it was that I usually copy a tsconfig from an existing project when starting a new project. And in this case I'd copied a config used by an app (something built with webpack where I don't build declarations) for use in a library (where I do build declarations).

Thanks for the help, much appreciated!

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

TinyMan added a commit to TinyMan/rxjs-inspector that referenced this issue Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants