You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To improve use with Typescript I have a few improvements that can help developer experience and stability of products based on @actions/core. The key thing here is the signature of any input function, such as getInput, getMultilineInput etc.
Let's look at the getInput signature: getInput(name: string, options?: InputOptions): string. In InputOptions we have a required: boolean option we can set. This is nicely built to throw when the input is missing, which is nice.
A way we can improve this is by casting whether the input is required or not. Because right now, getInput is returning string but defaults to required being false, which means that developers might expect a value but there is none. We can solve this by some using function overloading.
/** * Interface for getInput options */exportinterfaceInputOptions{/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */required?: boolean/** Optional. Whether leading/trailing whitespace will be trimmed for the input. Defaults to true */trimWhitespace?: boolean}exportinterfaceRequiredInputOptionsextendsInputOptions{required: true;}exportinterfaceOptionalInputOptionsextendsInputOptions{required: false;}exportfunctiongetInput(name: string,options: RequiredInputOptions): stringexportfunctiongetInput(name: string,options: OptionalInputOptions): string|undefinedexportfunctiongetInput(name: string,options?: InputOptions): string{ ... }
This might look more bloaty in the types / code for @actions/core, but will improve what the developer sees when using it.
My motivation is trying to remove some of the heavy boilerplate we've got over at Pulumi Actions. We're using runtypes to validate our configuration, which is quite cumbersome compared to using only this package :)
Again, thank you so much!
The text was updated successfully, but these errors were encountered:
Thank you for this nice product (and toolkit).
To improve use with Typescript I have a few improvements that can help developer experience and stability of products based on
@actions/core
. The key thing here is the signature of any input function, such asgetInput
,getMultilineInput
etc.Let's look at the
getInput
signature:getInput(name: string, options?: InputOptions): string
. InInputOptions
we have arequired: boolean
option we can set. This is nicely built to throw when the input is missing, which is nice.A way we can improve this is by casting whether the input is required or not. Because right now,
getInput
is returningstring
but defaults torequired
beingfalse
, which means that developers might expect a value but there is none. We can solve this by some using function overloading.This might look more bloaty in the types / code for
@actions/core
, but will improve what the developer sees when using it.Check out this example: https://codesandbox.io/s/actions-core-improvements-o6stpw?file=/src/index.ts
My motivation is trying to remove some of the heavy boilerplate we've got over at Pulumi Actions. We're using
runtypes
to validate our configuration, which is quite cumbersome compared to using only this package :)Again, thank you so much!
The text was updated successfully, but these errors were encountered: