-
Notifications
You must be signed in to change notification settings - Fork 246
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
Move the "optional" attribute from TypeReference to Parameter #296
Comments
So I wanted a function like such: method(anchor: Construct | undefined, realParameter: string, optionalParameter?: string) {
} Because that method order made most sense (and yet we didn't necessarily have the first argument always available), but this was rejected. I've had to reorder arguments, which is not a BIG deal but it was suboptimal to my mind. |
@rix0rrr I think is a different issue than where we model optionality of parameters. This is basically about nullibility of parameters, which is currently not supported by jsii (and should in my mind). Care to raise a separate issue? |
Isn't adding type nullability something that we need to tackle as part of solving this ticket anyway? |
it’s a related topic but not the same. This issue is basically just a modeling improvement (move the “optional” indication from the type reference to the parameter/property specification). Nullability is a different attribute of type references which is not the same as optionality. If at all, nullability should be part of the type-reference while optionality should be part of the consuming specification. |
Method `Parameters` now carry an `optional` flag that indicates whether they are optional or required, and the `TypeReference#optional` field was renamed to `TypeReference#nullable` to better reflect its semantics. This also brings more flexibility in that it is now possible to model a method with a nullable or defaulted argument that is followed by some non-optional argument, and still obtain a reasonable type specification, where previously this was an error. Finally, in order to better reflect the type model of TypeScript and Javascript, all `any` type references are now denoted `nullable`. BREAKING CHANGE: JSII assemblies generated by older versions of the tool will fail loading with this new version, and vice-versa. Re-compile your projects in order to fix this. Fixes #296 Fixes #414
Method `Parameters`, `Properties` and method return types now carry an `optional` flag that indicates whether they are optional or required, and the `TypeReference#optional` field was removed. BREAKING CHANGE: JSII assemblies generated by older versions of the tool will fail loading with this new version, and vice-versa. Re-compile your projects in order to fix this. Fixes #296 Fixes #414
The specification models the
optional
attribute of parameters on theirTypeReference
instead of directly on the parameter. This creates a confusion betweennull
able andoptional
.The specification needs to be modified so optional parameters carry an
optional
attribute, whileTypeReferences
carry anullable
attribute.Related: #230 #284 #295
The text was updated successfully, but these errors were encountered: