Skip to content
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

refactor: more concise typings for isDefined utility function #2159

Merged
merged 2 commits into from
Dec 15, 2023

Conversation

reybok
Copy link
Contributor

@reybok reybok commented Jul 10, 2023

Description

When using the utility function isDefined, typescript can properly ignore undefined and null with stricter typing.

Example

function example(param?: string) {
  if (!isDefined(param)) return
  console.log(param.charAt(0)) // Typescript now knows that param _must_ be a string and does not throw a warning param might be undefined
}

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified → it wasn't )
  • documentation added or updated ← stays the same
  • I have run the project locally and verified that there are no errors

Fixes

This change is so simple, I hoped we don't need to clutter the issue tracker. If you want me to open a feature request, I'll gladly do so.

@reybok
Copy link
Contributor Author

reybok commented Jul 13, 2023

Dear Maintainers,

let me preface this with a big thank you for this awesome library that I use excessively in my NestJS server 👍

Just letting you know that I won't be available until 1st of August but I still want to see this PR through and love to contribute in any helpful way once I'm back.

Thanks in advance ☀️

@reybok reybok changed the title refactor: more concise typings for isDefined utility function refactor: more concise typings for isDefined utility function Sep 4, 2023
Copy link
Member

@braaar braaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better typings are always great to see. Thanks!

@braaar
Copy link
Member

braaar commented Dec 15, 2023

Keep in mind that this is an internal validation function only used by the IsDefined validator, so this doesn't really affect usage of the library.

@braaar braaar merged commit 6cbf5a1 into typestack:develop Dec 15, 2023
5 checks passed
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants