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

feat: add undefined to Model.get return type #1675

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tranhl
Copy link

@tranhl tranhl commented Apr 25, 2024

Summary

Fixes #1622

Code sample

Before

const user = UserModel.get('id')
const id = user.id // ✅ Works, but can lead to runtime errors

After

const user = UserModel.get('id')
const id = user.id // ❌ `id` is potentially undefined

if (user) {
  const id = user.id // ✅ Safe
}

GitHub linked issue

#1622

Type (select 1):

  • Bug fix
  • Feature implementation
  • Documentation improvement
  • Testing improvement
  • Test added to report bug (GitHub issue #---- @---)
  • Something not listed here

Is this a breaking change? (select 1):

  • 🚨 YES 🚨 (Definitely will break in userland)
  • No
  • I'm not sure

Is this ready to be merged into Dynamoose? (select 1):

  • Yes
  • No

Are all the tests currently passing on this PR? (select 1):

  • Yes
  • No

Other:

  • I have read through and followed the Contributing Guidelines
  • I have searched through the GitHub pull requests to ensure this PR has not already been submitted
  • I have updated the Dynamoose documentation (if required) given the changes I made
  • I have added/updated the Dynamoose test cases (if required) given the changes I made
  • I agree that all changes made in this pull request may be distributed and are made available in accordance with the Dynamoose license
  • All of my commits and commit messages are detailed, explain what changes were made, and are easy to follow and understand
  • I have filled out all fields above

@@ -4,7 +4,8 @@
"moduleResolution": "node",
"lib": ["es2015"],
"target": "es2017",
"noEmit": true
"noEmit": true,
"strict": true
Copy link
Author

Choose a reason for hiding this comment

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

Without strict: true (or more specifically strictNullChecks: true, The T | undefined type simply becomes T, rendering these type changes useless. I've mentioned this in the TypeScript documentation above.

Copy link
Contributor

github-actions bot commented May 3, 2024

This pull request is stale because it has been open 7 days with no activity. Remove stale label or comment or this will be closed in 3 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Return type of model.get is missing | undefined
2 participants