-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Allow value pointing to a class or whose type has a new signature to be used as a type #45013
Comments
But you can refer to it using the
|
@MartinJohns true, but that's got pretty bad ergonomics. See the linked issue -- library authors shouldn't have to force the constituents into using type shenanigans like that. |
I really don't see how this is "type shenanigans". It's just how the type system is designed and works. And I'd say But const variables not introducing new types is the intended behavior. Your feature request goes in the same direction as #44681. |
Name resolution isn't allowed to have fallback behavior. Doing this creates a semantic trap where adding a new top-level type possibly changes the meaning of existing code. And obviously we can't change the behavior to prefer an inner-scoped |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Suggestion
π Search Terms
refers to value used as type static class generic
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
When a class is created by a static method, there doesn't seem to be a way to directly use it as a class type.
π Motivating Example
While
CreatedClass
is indeed a value, it's a value that happens to be equal to a class.π» Use Cases
In general, class factories like this are rather unwieldy to set up in the type system.
For a specific use case, see gr2m/javascript-plugin-architecture-with-typescript-definitions#57, as posted in SO at https://stackoverflow.com/questions/68201386/how-to-make-required-constructor-options-optional-when-they-were-set-using-mycla. Those Oktokit classes have a static
defaults
member that returns a new class. That new class has a constructor parameter whose type information must be informed by the previous static class' generic.See this playground link for a version that uses an interface to describe the class, and this playground link for a verson that purely uses a static class. The former would be resolved nicely by this issue's requested feature; the latter would be doable in a more complex way if #26242 and/or #5863 are implemented.
cc @gr2m
The text was updated successfully, but these errors were encountered: