Request for a new interface (or whatever) to declare object types in TypeScript #53408
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Feature Request
Describe the feature you'd like
I would like to be able to define a variable with the type of an object in TypeScript. Currently, the syntax
let theObject: object
is deprecated and there is no other way to declare a variable as an object type.Describe how you'd like the feature to work
I propose adding a new interface called
IObject
, which would allow us to define variables with the type of an object in a way that is both clear and concise. Here is an example of what the interface might look like:With this interface, we could then define an object variable like this:
Provide examples of how the feature would be used
Here are some examples of how this new feature would be used in TypeScript:
Describe any potential drawbacks or challenges
One potential challenge of this feature is that it may not be as performant as other object types, since the
[key: string]: unknown
syntax allows for any key-value pair. However, I believe that the flexibility and clarity of theIObject
interface would outweigh any performance concerns.Additional Context
What motivated you to propose this feature?
I find that declaring variables as
object
types already deprecated. I believe that theIObject
interface would provide a clear and concise way to define variables as objects in TypeScript.Are there any existing solutions or workarounds?
Currently, the
object
type is deprecated and there is no other built-in way to define a variable as an object type in TypeScript. However, we can use an index signature to define an object type, like so:While this works, I believe that the
IObject
interface would provide a more elegant and readable solution.Would you be willing to contribute this feature?
While I am not currently in a position to contribute to the development of this feature, I would be happy to provide feedback and testing during the development process.
The text was updated successfully, but these errors were encountered: