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 non-exported types are importable #38592

Closed
mheiber opened this issue May 15, 2020 · 5 comments
Closed

Declaration file non-exported types are importable #38592

mheiber opened this issue May 15, 2020 · 5 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@mheiber
Copy link
Contributor

mheiber commented May 15, 2020

TypeScript Version: 3.9.2, 3.8.3, 3.1.6 3.0.3 (and likely more)

Search Terms:

declaration file export, non-exported types, implicit export, dts, .d.ts, es-modules declaration

Code

module.d.ts

export declare const explicitlyExported: {};
declare const implicitlyExported: {};

importer.d.ts

import { implicitlyExported } from "./module"; // no error, is usable import

Expected behavior:

Error: Module '"./module"' has no exported member 'implicitlyExported'.

Actual behavior:

No error.

Even thought it wasn't exported, implicitlyExported is available for import.

Playground Link:

n/a (declaration file issue)

Related Issues:

@mheiber mheiber changed the title No error. implicitlyExported is available for import even though it was not exported implicitlyExported is available for import even though it was not exported May 15, 2020
@mheiber mheiber changed the title implicitlyExported is available for import even though it was not exported Declaration file non-exported types are importable May 15, 2020
@mheiber
Copy link
Contributor Author

mheiber commented May 21, 2020

As far as we can tell, this is how TS currently decides which mode to use for declaration files. Is this intended? What is the use case for implicit exports / mixed mode?

has export declaration no export declaration
has >= 1 import or export statement ESM-style implicit exports (mixed mode)
no import or export statements ESM-style ambient

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 8, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 8, 2020
@weswigham
Copy link
Member

Yeah, this is unfortunately... by design... if you add export {}, you'll get correct private-ness. We could opt to change this, but it'd definitely be a breaking change that walks back something that we've been calling "working as intended" for a long time.

@mheiber
Copy link
Contributor Author

mheiber commented Jun 29, 2020

Thanks @weswigham

@renet
Copy link

renet commented Mar 24, 2021

Are there any plans on changing this behavior, maybe in a major release some time?

@RyanCavanaugh
Copy link
Member

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants