-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow variable merge with namespace when value of variable is a allowed merging declaration #45975
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
Comments
Is there a scenario where you need to use |
With I have: const Scene: React.FC< ...
namespace Scene { ... And I cannot change to: function Scene(props: { children ... Because |
But I don’t think that helps you, because we couldn’t know that the return of |
Yes, I'm realizing it now. It is not possible to guarantee that the return value does not have other properties than those declared in the interface, as long as it respects the interface.
Maybe, it can still be useful for scenarios with arrow functions (although it doesn't solve the problem that made me open the suggestion) |
In this code, I was trying to re-export a export const Scene: React.FC<Scene.Props> & { LatencyCategory: typeof ATOM.Scene.LatencyCategory } = (
React.forwardRef((props, ref) => {
return React.createElement(Tag.SCENE, { ...props, ref }, props.children)
}) as any
) This works even if the variable has a property with the same name, as seen here Would allowing merge with |
How That way I don't run the risk of overwriting any additional property returned. const Scene: Scene = React.forwardedRef() // ...
interface Scene extends React.FC {
LatencyCategory: typeof ATOM.Scene.LatencyCategory // Is a `const enum`
}
namespace Scene { // ... Closing the issue. Maybe I open another only about arrow function in the future to allow this: const MyComponent: React.FC<MyProps> = props => {
// ...
}
namespace MyComponent {
// ...
} |
If it's useful for someone else, better discuss it in a separate and more specific issue. |
Suggestion
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
It is not allowed merging namespace with variables. But, in some cases, it should be when the value itself is a allowed merging.
This is allowed:
But this is not:
As
class A {...
andconst A = class {...
are equivalent, it should compile with no erros.The text was updated successfully, but these errors were encountered: