Skip to content

fix(types): optional properties on RedisOptions allow explicit undefined#2066

Merged
PavelPashov merged 2 commits intoredis:mainfrom
avocadojesus:fix/username-and-password-have-explicit-undefined-types
Feb 10, 2026
Merged

fix(types): optional properties on RedisOptions allow explicit undefined#2066
PavelPashov merged 2 commits intoredis:mainfrom
avocadojesus:fix/username-and-password-have-explicit-undefined-types

Conversation

@avocadojesus
Copy link
Copy Markdown
Contributor

@avocadojesus avocadojesus commented Jan 16, 2026

when exactOptionalPropertyTypes is true in the consuming application's tsconfig, you cannot send in an explicit undefined for these fields, causing the developer to jump through extra hoops needlessly to get i.e. the username and password provided to the options in a type-safe manner. This fix corrects this by explicitly specifying undefined as an allowed type on the username and password properties within RedisOptions.

new Redis({
  ...
  password: process.env.REDIS_PASSWORD,
})

@jit-ci
Copy link
Copy Markdown

jit-ci bot commented Jan 16, 2026

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@jit-ci
Copy link
Copy Markdown

jit-ci bot commented Jan 16, 2026

❌ Security scan failed

Security scan failed: Branch fix/username-and-password-have-explicit-undefined-types does not exist in the remote repository


💡 Need to bypass this check? Comment @sera bypass to override.

@avocadojesus
Copy link
Copy Markdown
Contributor Author

@sera bypass

@avocadojesus avocadojesus changed the title optional properties on RedisOptions allow explicit undefined fix(types): optional properties on RedisOptions allow explicit undefined Jan 16, 2026
@PavelPashov
Copy link
Copy Markdown
Contributor

@avocadojesus Appreciate you putting this together.

When you get a chance, could you apply the same change to keep things consistent in:

@avocadojesus avocadojesus force-pushed the fix/username-and-password-have-explicit-undefined-types branch from 94d04eb to e2ddbb7 Compare January 29, 2026 20:24
@avocadojesus
Copy link
Copy Markdown
Contributor Author

avocadojesus commented Jan 29, 2026

@avocadojesus Appreciate you putting this together.

When you get a chance, could you apply the same change to keep things consistent in:

* [ClusterOptions](https://github.com/redis/ioredis/blob/4cf4d9974788bf1505694a49022f86d473cd3067/lib/cluster/ClusterOptions.ts#L31)

* [SentinelConnectionOptions](https://github.com/redis/ioredis/blob/4cf4d9974788bf1505694a49022f86d473cd3067/lib/connectors/SentinelConnector/index.ts#L34)

absolutely, done! Thanks for maintaining the project and giving me the time of day, I appreciate you 🙏 . Curious, I noticed prettier kicking in, so i went ahead and ran the npm run format, thinking it would remove any changes in code. To the contrary, it kept many of the changes my prettier had made, and then found many more changes to make in files that I did not even touch. I did not end up committing any of them, but I just wanted to say sorry for the prettier spam in this PR.

…erOptions

when exactOptionalPropertyTypes is true in the consuming application's tsconfig, you cannot send in an explicit undefined for these fields, causing the developer to jump through extra hoops needlessly to get i.e. the username and password provided to the options in a type-safe manner. This fix corrects this by explicitly specifying undefined as an allowed type on the username and password properties within RedisOptions, SentinelConnectionOptions, and ClusterOptions.

```ts
new Redis({
  ...
  password: process.env.REDIS_PASSWORD,
})
```
@avocadojesus avocadojesus force-pushed the fix/username-and-password-have-explicit-undefined-types branch from e2ddbb7 to 505bce6 Compare January 30, 2026 21:22
Copy link
Copy Markdown
Contributor

@PavelPashov PavelPashov left a comment

Choose a reason for hiding this comment

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

LGTM

@PavelPashov
Copy link
Copy Markdown
Contributor

I did not end up committing any of them, but I just wanted to say sorry for the prettier spam in this PR.

No worries at all, I also added some more undefined to the remaining optional properties

@PavelPashov PavelPashov merged commit 0a1a898 into redis:main Feb 10, 2026
11 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 12, 2026
## [5.9.3](v5.9.2...v5.9.3) (2026-02-12)

### Bug Fixes

* autopipelining to route writes to masters with scaleReads ([#2072](#2072)) ([8adb1ae](8adb1ae))
* fix issue with moved command for replicas ([#2064](#2064)) ([de4eed4](de4eed4))
* **types:** optional properties on RedisOptions allow explicit undefined ([#2066](#2066)) ([0a1a898](0a1a898))
github-actions bot pushed a commit that referenced this pull request Feb 12, 2026
## [5.9.3](v5.9.2...v5.9.3) (2026-02-12)

### Bug Fixes

* autopipelining to route writes to masters with scaleReads ([#2072](#2072)) ([8adb1ae](8adb1ae))
* fix issue with moved command for replicas ([#2064](#2064)) ([de4eed4](de4eed4))
* **types:** optional properties on RedisOptions allow explicit undefined ([#2066](#2066)) ([0a1a898](0a1a898))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 5.9.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants