-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
It should be possible to generate TypeScript interfaces without "reserved" prefix for special keywords #1475
Comments
Super easy, there a couple of ways, this one is probably the best approach, overwriting constraint logic (ignoring reserved keywords) and then overwriting the default rendering of interfaces and the property to follow your syntax const generator = new TypeScriptGenerator({
constraints: {
propertyKey: typeScriptDefaultPropertyKeyConstraints({
// Ignore reserved keywords for properties entirely
NO_RESERVED_KEYWORDS: (name) => { return name; }
})
},
modelType: 'interface',
defaultPreset: {
interface: {
property: ({property}) => {
return `'${property.propertyName}': ${property.property.type};`
}
}
}
}); Alternatively, a smaller but a little more hacky approach is just using the unconstrained property name as such: const generator = new TypeScriptGenerator({
modelType: 'interface',
defaultPreset: {
interface: {
property: ({property}) => {
return `'${property.unconstrainedPropertyName}': ${property.property.type};`
}
}
}
}); And that's it 🙂 I wonder if it makes sense to make this the default outcome for interfaces? 🤔 Is there any downside you see @trevordixon? |
Thank you so much! That helps a ton. No downside to doing this by default
as far as I know. It seems possible to do with classes too by the way.
```
class Foo {
get 'static'() { return 1; }
}
(new Foo).static;
```
I think this would be preferable as well for classes, though not as huge a
deal with generated marshal/unmarshal. But with interfaces, it's critical
for me that the interface describes what's actually coming down the wire.
…On Tue, Aug 15, 2023, 11:10 PM Jonas Lagoni ***@***.***> wrote:
Super easy, There two ways, this one is probably the best approach,
overwriting constraint logic (ignoring reserved keywords) and then
overwriting the default rendering of interfaces and the property to follow
your syntax 'static': string;
const generator = new TypeScriptGenerator({
constraints: {
propertyKey: typeScriptDefaultPropertyKeyConstraints({
// Ignore reserved keywords for properties entirely
NO_RESERVED_KEYWORDS: (name) => { return name; }
})
},
modelType: 'interface',
defaultPreset: {
interface: {
property: ({property}) => {
return `'${property.propertyName}': ${property.property.type};`
}
}
}});
Alternatively, a smaller but a little more hacky approach is just using
the unconstrained property name as such:
const generator = new TypeScriptGenerator({
modelType: 'interface',
defaultPreset: {
interface: {
property: ({property}) => {
return `'${property.unconstrainedPropertyName}': ${property.property.type};`
}
}
}});
And that's it 🙂
I wonder if it makes sense to make this the default outcome for
interfaces? 🤔 Is there any downside you see @trevordixon
<https://github.com/trevordixon>?
—
Reply to this email directly, view it on GitHub
<#1475 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJR67LZ2XC344EWN2JPWCLXVPQVXANCNFSM6AAAAAA3Q3MGJM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This issue has been automatically marked as stale because it has not had recent activity 😴 It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation. There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model. Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here. Thank you for your patience ❤️ |
Solved in #1729 |
Instead of generating, for example
reservedStatic
, it could simply quote the property name:How hard is it to get this behavior right now?
The text was updated successfully, but these errors were encountered: