Improve types
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
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 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
*/
export interface InputOptions {
/** 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
}
export interface RequiredInputOptions extends InputOptions {
required: true;
}
export interface OptionalInputOptions extends InputOptions {
required: false;
}
export function getInput(name: string, options: RequiredInputOptions): string
export function getInput(name: string, options: OptionalInputOptions): string | undefined
export function getInput(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.
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the @actions/core TypeScript signatures for getInput, getMultilineInput, and the other input functions mentioned in the issue. Review how required and optional inputs are currently represented, then define the consistent typing behavior and confirm that the resulting declarations match the requested developer experience.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100