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

esModuleInterop: true with class static method #45133

Closed
bluelovers opened this issue Jul 21, 2021 · 2 comments · Fixed by #60262
Closed

esModuleInterop: true with class static method #45133

bluelovers opened this issue Jul 21, 2021 · 2 comments · Fixed by #60262
Assignees
Labels
Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@bluelovers
Copy link
Contributor

bluelovers commented Jul 21, 2021

Bug Report

🔎 Search Terms

class static import

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?module=1#code/JYWwDg9gTgLgBAYQJIBEA0cDedgGdkpwC+cAZlBCHAOQDGwAJrtQNwCwAUJwKYAeksMgFcAdrRjAIIuGACGMABYAVCAkYAKegwBccXDCjARAczgAfRKgCUu-YZOdMnAJDBScdQQB0eApsZWVi5OHM7OUNwwQlDSWl4wEADKBkbG6kGhRJwuEVExcHERYAA2srTc6gD0AHoAOpXAYADaIqQAurj1lRjU1BlZXBx8AvCkouKS0nKKKmoMAEz+OnopJuaWKDYr9saOLm4evqhLgcEu4ZHRsYzxSatpGc4DOZf5hdwlZRU19Y0t7Z1Kt0aH1OM8ONNlKoNL0MpDZoxFrDOEA

💻 Code

import CID, { isCID } from 'cids';

export function pathToCid(cid: string | CID): string
{
	if (CID.isCID(cid))
	{
		return cid.toString()
	}

	return cid.replace(/^\/ip[nf]s\//, '')
}

export function pathToCid2(cid: string | CID): string
{
	if (isCID(cid))
	{
		return cid.toString()
	}

	return cid.replace(/^\/ip[nf]s\//, '')
}

pathToCid('')
pathToCid2('')

🙁 Actual behavior

TypeError: (0 , cids_1.isCID) is not a function

🙂 Expected behavior

  • no error on output js file
  • or show typescript error for warn this
@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript labels Jul 21, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.5.0 milestone Jul 21, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 15, 2021
@rbuckton
Copy link
Member

Normally I would say this should be considered an error as a native ES module wouldn't normally provide the entire module as the default export. However, that's exactly what NodeJS does for its built-ins like fs when you use import in a native module.

It is odd that the following works:

import CID from 'cids'; // passes through __importDefault
import { isCID } from 'cids'; // directly accesses module object

while the combined version doesn't:

import CID, { isCID } from 'cids'; // passes through __importStar, doesn't adjust for default import

@andrewbranch, @weswigham: Any thoughts on this? I'm leaning towards trying to make it work under --esModuleInterop rather than reporting an error, given that the individual declarations work in this mode.

@rbuckton
Copy link
Member

Fixed by #60262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants