powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature request: NonNullable return type for parameters

Open artkhod opened this issue 5 months ago • 1 comments

Use case

Fetching a non-existing parameter usually results in an error from sdk (not sure about every provider secrets/appconfig etc). Not receiving a param usually block an execution flow. If developers need to, they can account for such errors and do some actions on catch.

However, since powertools parameters utility uses Map for caching, it is by default typed to be T | undefined, even though it's the utility that is responsible for adding the parameter to the map, and it can guarantee if something has indeed been added to the Map. Hence, is it possible to return NonNullable<T> in the get method of the params util? If it's not a desirable maybe with throwOnUndefined option?

This would greatly reduce boilerplate of checking if the returned param is not undefined or throwing an error otherwise.

Solution/User Experience

Return NonNullable<T> for get method of the params utilities.

Alternative solutions


Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

artkhod avatar Jun 24 '25 15:06 artkhod

Hi @artkhod, thank you for opening this issue.

I think the request addresses a known papercut of using the parameters utility and even when I use it, I always find myself writing a version of this:

const param = await getParameter('foo');
if (!param) {
  // do something, most likely throw an error
}

I need a bit more time to think whether this should be the default behavior or if it should have a flag like you suggested, but I'm definitely keen on considering improving this experience that customers have a way of setting the operation as not nullable, and avoid boilerplate.

dreamorosi avatar Jun 24 '25 18:06 dreamorosi