-
Notifications
You must be signed in to change notification settings - Fork 11
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
[FEATURE] Refinement of Type Generation in CDS-Typer for Optional / Nullable Fields #87
Comments
Hi @tsteckenborn , thanks for opening this feature request! 👍 Hi @daogrady , could it be also possible to provide TS type without optional keyword Also, could you please say approximately in which lib's release we might expect the delivery of this feature? 🙂 |
Hi @siarhei-murkou, it is currently not explicitly planned, as other more pressing matters need to be addressed first. Regarding Best, |
Hi @daogrady , Thanks, The only missing part is to compile nullable fields to TS prop |
Hi you two, As both |
Hi @tsteckenborn , just wanted to let you know @siarhei-murkou is currently working on a PR to introduce the nullable behaviour. Best, |
Hi @daogrady , Yeah I saw that. I'm currently not quite sure on how I'd interpret the absence of values (indicated by not having With TypeScript recommending enabling the option |
I had a brief talk about this with the runtime team and they confirmed
We already have case 3., which is the default behaviour of cds-typer when not specifying const o: {
x: string | undefined,
y?: string
} = {
x: undefined
}
console.log('x' in o) // true
console.log(Object.hasOwn(o, 'x')) //true
console.log('y' in o) // false
console.log(Object.hasOwn(o, 'y')) // false An absent property and one that is set to I believe it is fair to assume that a property in a CDS entity is either absent, which is covered by the default I therefore think |
Question
Background
When using the CDS-Typer tool to generate TypeScript types for SAP CAP CDS services, it's observed that the tool does not explicitly differentiate between fields that can be null and those that can't. This becomes particularly problematic when TypeScript's exactOptionalPropertyTypes is enabled.
Current Behavior
Both the following CDS definitions for getUserDetails() yield the TypeScript type
example?: string;
, even though one specifies nullability:Expected Behavior
The type generation should be more specific. For instance, a more explicit type definition like
example?: string | null
; would be more informative and compatible with exactOptionalPropertyTypes.Note
I'm uncertain on the handling of undefined properties. It might also make sense to check whether
example?: string | undefined
is an option for the first,example?: string | undefined | null
for the second case.The text was updated successfully, but these errors were encountered: