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

Types inside a namespace disappear when the namespace is exported through HoC #46194

Closed
cdpark0530 opened this issue Oct 4, 2021 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@cdpark0530
Copy link

Bug Report

🔎 Search Terms

namespace disappear, namespace lost

🕗 Version & Regression Information

4.3.5
also tested: 3.9.10, 4.0.8, 4.1.6, 4.2, 4.4.3

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about namespace

⏯ Playground Link

Couldn't use it as the issue occurs in a script importing another script.

💻 Code

// Child.tsx
import React from "react";

function Child(props: Child.Props) {
    return <>{props.name}</>;
}

namespace Child {
    export interface Props {
        name: string;
    }

    export const constant = "Hello, World!";
}

function hoc<C extends React.ComponentType<any>>(component: C) {
	return component;
}

export default hoc(Child);
// Parent.tsx
import Child from "./Child";

const constant = Child.constant; // Child.constant is visible
type childProps = Child.Props; // Child.Props is not visible

🙁 Actual behavior

Child.Props is not visible in Parent.tsx

🙂 Expected behavior

Child.Props is visible in Parent.tsx because I think it should be as Child.constant is visible in Parent.tsx.

@andrewbranch
Copy link
Member

@DanielRosenwasser I know we’ve talked about this as a feature request before but I can’t for the life of me find anything to link it to. Tried searching for “function return namespace” but no luck.

@DanielRosenwasser
Copy link
Member

I think any time we discuss namespaces being carried together with values, the feature is "associated types" which allow values' types to contain other types, effectively turning them into namespaces.

#17588

@andrewbranch
Copy link
Member

I looked at that issue and even searched “associated types” but that particular proposal is so complicated that I felt like there must have been a simpler proposal to link to 😅

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 6, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants