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

Declaration file references global augmenting package #35343

Closed
AviVahl opened this issue Nov 25, 2019 · 1 comment · Fixed by #38151
Closed

Declaration file references global augmenting package #35343

AviVahl opened this issue Nov 25, 2019 · 1 comment · Fixed by #38151
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@AviVahl
Copy link

AviVahl commented Nov 25, 2019

This issue came up as part of a real component library breaking for its consumers, demanding @emotion/core.

I was able to get a much smaller reproduction ready to show the behaviour.

TypeScript Version: 3.7.2 & 3.8.0-dev.20191125

Search Terms:
triple slash reference declaration

Steps to reproduce
clone https://github.com/AviVahl/ts-declaration-reference
yarn
yarn build

Expected behavior:
dist/inferred-comp-export.d.ts should not contain a reference to @emotion/core..

Actual behavior:
dist/inferred-comp-export.d.ts contains: /// <reference types="@emotion/core" />

Playground Link:
Cannot reproduce in playground. It has to do with declaration emit and third party augmenting package.

Related Issues:
#34749
#11849

Observations:

  • @emotion/core/types/index.d.ts contains:
declare module 'react' {
  interface DOMAttributes<T> {
    css?: InterpolationWithTheme<any>
  }
}

commenting it out removes the triple slash from emit.

  • commenting out export * from '@emotion/core'; from src/some-other-file.ts gets rid of the triple slash reference.
  • In our more-complex real case, we import @storybook/react, which imports @storybook/theming, which re-exports @emotion/core.
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jan 8, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Jan 8, 2020
@weswigham
Copy link
Member

Yeah, I'm going to file this as a bug - given

// @declaration: true
// @filename: node_modules/foo/index.d.ts
export = React;
declare namespace React {
    export interface Component<P={}> { }
}
// @filename: node_modules/bar/index.d.ts
import { Component } from 'foo';
declare module "foo" {
    export interface Component<P> {
        css?: P;
    }
}
// @filename: reexport.ts
export * from "bar";
// @filename: get.ts
import { Component } from 'foo';
export function getComp(): Component {
    return {} as any as Component;
}
// @filename: use.ts
import { getComp } from "./get";

export const obj = {
    comp: getComp()
};

we produce

/// <reference types="bar" />
export declare const obj: {
    comp: import("foo").Component<{}>;
};

for use.ts, while if foo/index.d.ts is just

export interface Component<P={}> { }

we produce

export declare const obj: {
    comp: import("foo").Component<{}>;
};

Clearly we don't always think the triple slash reference is needed, and at somepoint we're confusing an export-assigned-namespace with a referenced-augmentation or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants