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

In certain cases TS 2.9 outputs incorrect definitions (.d.ts) #25511

Closed
d4rkr00t opened this issue Jul 9, 2018 · 9 comments · Fixed by #25850
Closed

In certain cases TS 2.9 outputs incorrect definitions (.d.ts) #25511

d4rkr00t opened this issue Jul 9, 2018 · 9 comments · Fixed by #25850
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@d4rkr00t
Copy link
Contributor

d4rkr00t commented Jul 9, 2018

TypeScript Version: 2.9.2 and 3.0.0-dev.201xxxxx

Search Terms: relaxed, declarations

Expected behavior:
Definitions have correct import statements.

Actual behavior:

In certain cases e.g. monorepo structure where dependencies are linked inside packages from the root node_modules folder (you can read about that more here: bolt) output .d.ts files contain pretty weird paths...

Code: https://github.com/d4rkr00t/tsc29-test-relaxed-resolve

// packages/package-a/src/index.ts
import { css } from 'styled-components';

export const styles = css`
	display: table;
`;

Outputs definition file:

// packages/package-a/dist/index.d.ts
export declare const styles: import("../../../../../../../../Users/username/tsc29-test-relaxed-resolve/packages/package-a/node_modules/styled-components").InterpolationValue[];

I've also tried that with TS 3.0 it's a little bit better, first file gets correct deffinitions:

// packages/package-a/dist/index.d.ts
export declare const styles: import("styled-components").InterpolationValue[];

But another module that imports the previous one still gets wrong definitions (even though, they look sort of reasonable, but probably the fact that package-a is inside node_modules should indicate that this is a module, i'm not sure if it's fair to assume that :) ):

export declare function getStyles(): import("../../package-a/node_modules/styled-components/typings/styled-components").InterpolationValue[];

In version below 2.9 we had to import those things manually and it used to work, but now we can't do it manually anymore as it has no difference...

@alex3165
Copy link

alex3165 commented Jul 9, 2018

Having the same issue with a monorepo like structure too using oao and with Typescript 2.9.2

@jaredpalmer
Copy link

jaredpalmer commented Jul 11, 2018

Formik has this issue and I'm not sure how to proceed.

import * as React from 'react';
import { FormikContext } from './types';
export declare const FormikProvider: React.ComponentClass<import("../../../../../../../Users/jared/workspace/github/jaredpalmer/formik/node_modules/create-react-context").ProviderProps<FormikContext<any>>>, FormikConsumer: React.ComponentClass<import("../../../../../../../Users/jared/workspace/github/jaredpalmer/formik/node_modules/create-react-context").ConsumerProps<FormikContext<any>>>;
export declare function connect<OuterProps, Values = {}>(Comp: React.ComponentType<OuterProps & {
    formik: FormikContext<Values>;
}>): React.ComponentClass<OuterProps> & {
    WrappedComponent: React.ComponentClass<OuterProps & {
        formik: FormikContext<Values>;
    }>;
};

jaredpalmer/formik#720

@jaredpalmer
Copy link

Update: I bumped to v3.0.0-dev and this has been fixed. New output looks like:

import * as React from 'react';
import { FormikContext } from './types';
export declare const FormikProvider: React.ComponentClass<import("create-react-context").ProviderProps<FormikContext<any>>>, FormikConsumer: React.ComponentClass<import("create-react-context").ConsumerProps<FormikContext<any>>>;
export declare function connect<OuterProps, Values = {}>(Comp: React.ComponentType<OuterProps & {
    formik: FormikContext<Values>;
}>): React.ComponentClass<OuterProps> & {
    WrappedComponent: React.ComponentClass<OuterProps & {
        formik: FormikContext<Values>;
    }>;
};

@d4rkr00t
Copy link
Contributor Author

@jaredpalmer Yeah, as i mentioned before TS@3.0 solves some of the issue, but it doesn't solve it completely for us :( I should actually try new monorepo support in 3.0 (a.k.a references) and see how it goes...

@d4rkr00t
Copy link
Contributor Author

I just tried references, and it didn't help...

@jaredpalmer
Copy link

More specifically, installing today's release worked:

"typescript": "^3.0.0-dev.20180711",

@n8agrin
Copy link

n8agrin commented Jul 12, 2018

@jaredpalmer I was experiencing similar issues with StyledComponents and today's release did fix my problems. Thank you!

@mhegazy mhegazy added the Bug A bug in TypeScript label Jul 12, 2018
@mhegazy mhegazy added this to the TypeScript 3.0.1 milestone Jul 12, 2018
@drew-y
Copy link

drew-y commented Jul 13, 2018

This is happening to me in a non-monorepo setup with typescript 2.9.2.

This function:

export const robotError = (code: number, trace?: Error) => errors.error(code, trace);

Is converted to this declaration:

export declare const robotError: (code: number, trace?: Error | undefined) => import("../../../../../../../Users/drew/projects/versabuilt/drivers/robot/node_modules/@vb/error/dist/definitions").VBError;

I think it must be implicit return type causing the issue.

@weswigham
Copy link
Member

weswigham commented Jul 20, 2018

The issue most people here are harping on should have been fixed by #25364 and #25364. There's some comments in this threads stating that recent releases have worked for people in this thread - anyone here still having issues should try the latest 3.0 nightly and open a new issue (ideally with detailed repro steps, including full filesystem paths of the involved files) if it still reproduces under some set of circumstances for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
7 participants