Annotation/diagnostic to enforce exact type definition #1602
firas-assaad
started this conversation in
Ideas
Replies: 1 comment
-
Similar suggestions/feature requests:
In addition to my example (preventing undocumented properties from being defined), the following features would are also desired:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently if you write the following:
You can still add more inline fields to the table without warnings, as long as they're defined before they're used. This is useful because Lua tables are used in many ways and lend themselves to being extended with more fields.
However, sometimes you're working with a strict class definition (e.g. a vendor API) that are not meant to be extended. In these cases, you can end up adding fields to them by mistake. e.g. if you type
c.twwo = 'x'
when you meantc.two
. Another scenario is trying to add a new index to a C/C++ usertype that doesn't support this operation, resulting in a crash that can only be caught at runtime.My suggestion is to introduce an annotation for classes that triggers a diagnostic warning when trying to add a new index to objects of that class. Some name ideas:
@exact
,@closed
,@final
. It could also be part of@class
annotation (e.g.@class exact C
or@class{exact} C
).The suggestion for exact types in TypeScript might be relevant.
Beta Was this translation helpful? Give feedback.
All reactions