René's URL Explorer Experiment


Title: Importing same class that is in 2 different files does not identify it as same class · Issue #8052 · microsoft/TypeScript · GitHub

Open Graph Title: Importing same class that is in 2 different files does not identify it as same class · Issue #8052 · microsoft/TypeScript

X Title: Importing same class that is in 2 different files does not identify it as same class · Issue #8052 · microsoft/TypeScript

Description: Lets say I have a class called AbstractClass: // animal.ts export abstract class Animal { public abstract talk(): String; } // cat.ts import {Animal} from "./animal"; export class Cat extends Animal { public talk(): String { return "meow...

Open Graph Description: Lets say I have a class called AbstractClass: // animal.ts export abstract class Animal { public abstract talk(): String; } // cat.ts import {Animal} from "./animal"; export class Cat extends Anima...

X Description: Lets say I have a class called AbstractClass: // animal.ts export abstract class Animal { public abstract talk(): String; } // cat.ts import {Animal} from "./animal"; export class Cat ext...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/8052

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Importing same class that is in 2 different files does not identify it as same class","articleBody":"Lets say I have a class called `AbstractClass`:\n\n```\n// animal.ts\nexport abstract class Animal {\n   public abstract talk(): String;\n}\n\n// cat.ts\nimport {Animal} from \"./animal\";\n\nexport class Cat extends Animal {\n    public talk(): String {\n        return \"meow\";\n   }\n}\n\n// dog.ts\nimport {Animal} from \"./animal\";\n\nexport class Dog extends Animal {\n   public talk(): String {\n       return \"whoof whoof\";\n   }\n}\n```\n\nNow I have another module that has dependency on that class.\n\n```\nimport {Animal} from \"animal-module/animal\";\n\n// play-with-animal.ts\nexport class PlayWithAnimal {\n    private animal: Animal;\n\n    constructor(animal: Animal) {\n        this.animal = animal;\n    }\n\n   public makeAnimalTalk(): void {\n        console.log(this.animal.talk());\n   }\n}\n```\n\n```\n// animal.component.ts\nimport {PlayWithAnimal} from \"play-with-animal-module/play-with-animal.ts\"\nimport {Cat} from \"animal-module/cat\";\n\nsomeFunction() {\n    let cat: Cat = new Cat();\n    let playWithAnimal: PlayWithAnimal = new PlayWithAnimal(cat);\n\n   // here I get error saying:\n  // TS2345: Argument of type 'Cat' is not assignable to parameter of type 'Animal'. 'Animal' is not a class derived from 'Animal'. \n}\n\n```\n\nHere is how the folder structure is. I am using `node` to resolve the modules.\n\n```\n- app\n   animal.component.ts\n   // app has dependency of animal-module\n- node_modules\n   - animal-module\n        animal.ts\n        cat.ts\n        dog.ts\n   - play-with-animal-module\n      play-with-animal.ts\n      // talking-animal-module has dependency of animal-module\n      - node_modules\n         - animal-module\n            animal.ts\n            cat.ts\n            dog.ts\n\n```\n\nMy finding so far is that, as in the `dog.ts` or `cat.ts`, I have imported the `Animal` as `import {Animal} from \"./animal\";`. Notice the relative path.\n\nHowever in `PlayWithAnimal` or `AppComponent` the module is resolved using the node resolution. Somehow typescript thinks that they are separate classes (eventhough) they are same as they are being loaded from different file paths.\n\nIf I wrap Animal in a `exports module 'SomeModule'` and update the code to use `SomeModule.Animal` then it works fine even if I load the class from 2 different files. However if I do so then I lose ability to import multiple classes like import `{Animal, SomeotherClass}`.\n\nSo my question is:\n1. Is this by design or its an issue?\n2. If this is by design then how are we meant to resolve the modular dependencies?\n\nThanks.\n","author":{"url":"https://github.com/adikari","@type":"Person","name":"adikari"},"datePublished":"2016-04-13T00:48:38Z","url":"https://github.com/microsoft/TypeScript/issues/8052"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8fdfeac7-d34a-6cc2-f8b5-6fe06b088b96
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE8B0:258059:168C508:1F7B0E5:6AFA3C22
html-safe-nonce85e56da7e2b5dee86f80bd87ecfbf384a7eec0462211d856793585156ded2311
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEIwOjI1ODA1OToxNjhDNTA4OjFGN0IwRTU6NkFGQTNDMjIiLCJ2aXNpdG9yX2lkIjoiMTQzNzY5ODE4NzY4MTQ3OTcxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9103eebf8d684a9432c007a2c918b573adf714973f763401a63909a588dc8fc9
hovercard-subject-tagissue:147914059
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/8052/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4afaaf45a1ab6387fece19550310b3ad1605f90e54ad7eb3b5778eb6ff288727/microsoft/TypeScript/issues/8052
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4afaaf45a1ab6387fece19550310b3ad1605f90e54ad7eb3b5778eb6ff288727/microsoft/TypeScript/issues/8052
og:image:altLets say I have a class called AbstractClass: // animal.ts export abstract class Animal { public abstract talk(): String; } // cat.ts import {Animal} from "./animal"; export class Cat extends Anima...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameadikari
hostnamegithub.com
expected-hostnamegithub.com
None612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release072e34035c13c31543fba9f025cbbbda4210dae4
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/8052#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F8052
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F8052
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/8052
Reloadhttps://github.com/microsoft/TypeScript/issues/8052
Reloadhttps://github.com/microsoft/TypeScript/issues/8052
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests340 (340)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/pulse
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/8052
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/8052
Importing same class that is in 2 different files does not identify it as same classhttps://github.com/microsoft/TypeScript/issues/8052#top
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
https://github.com/adikari
subash adhikari (adikari)https://github.com/adikari
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#issue-147914059
https://github.com/aluanhaddad
Aluan Haddad (aluanhaddad)https://github.com/aluanhaddad
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#issuecomment-209328162
subash adhikari (@adikari)https://github.com/adikari
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#issuecomment-209546195
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#event-626100048
https://github.com/adikari
subash adhikari (adikari)https://github.com/adikari
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#issuecomment-209674181
Aluan Haddad (@aluanhaddad)https://github.com/aluanhaddad
https://github.com/adikari
subash adhikari (adikari)https://github.com/adikari
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#issuecomment-209679906
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Apr 13, 2016https://github.com/microsoft/TypeScript/issues/8052#issuecomment-209681714
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on May 20, 2016https://github.com/microsoft/TypeScript/issues/8052#issuecomment-220526376
#8486https://github.com/microsoft/TypeScript/pull/8486
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on May 20, 2016https://github.com/microsoft/TypeScript/issues/8052#event-666740350
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/8052#event-1689831856
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/8052
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/8052
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.