Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Narrow String#toLowerCase/toUpperCase return types via Lowercase/Uppercase#9

Open
hbrooks wants to merge 1 commit into
mainellipsis-dev-test/TypeScript:mainfrom
demo/pr-63460ellipsis-dev-test/TypeScript:demo/pr-63460Copy head branch name to clipboard
Open

Narrow String#toLowerCase/toUpperCase return types via Lowercase/Uppercase#9
hbrooks wants to merge 1 commit into
mainellipsis-dev-test/TypeScript:mainfrom
demo/pr-63460ellipsis-dev-test/TypeScript:demo/pr-63460Copy head branch name to clipboard

Conversation

@hbrooks

@hbrooks hbrooks commented May 28, 2026

Copy link
Copy Markdown

Originally PR microsoft#63460 in microsoft/TypeScript by @ljharb

…rcase

Make String.prototype.toLowerCase and toUpperCase preserve string-literal
types in their return type, by typing them as
`<T extends string>(this: T): Lowercase<T>` and `Uppercase<T>` respectively.

For non-literal `string` receivers, `Lowercase<string>` resolves to `string`,
preserving existing behavior. For literal receivers (e.g. `"FOO".toLowerCase()`),
the result narrows to the corresponding literal (`"foo"`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.