Skip to content

Const strings don't narrow their length property #55338

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

Closed
bbrk24 opened this issue Aug 11, 2023 · 2 comments
Closed

Const strings don't narrow their length property #55338

bbrk24 opened this issue Aug 11, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@bbrk24
Copy link

bbrk24 commented Aug 11, 2023

πŸ”Ž Search Terms

const string length

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about const strings

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgJwTAvDA2gcjpgNDTAIzwOEwF14IZRIoBuAKFuhmmTW0LKpvGibN+sRAgAyAUzCp4SAHQAbKQHMoACyYB6TTF0wAegH4hdNlHFSZ7RSvVadeo4yA

πŸ’» Code

const arr = ['a', 'b', 'c'] as const;
const str = 'abc' as const;

const arrLen = arr.length;
//    ^? const arrLen: 3
const strLen = str.length;
//    ^? const strLen: number

πŸ™ Actual behavior

The length property of the constant string is of type number

πŸ™‚ Expected behavior

The length property of the constant string should be 3, like it is for the constant array.

@fatcerberus
Copy link

Looks like a duplicate of #34692. Related issue: #41037

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 11, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants