microsoft / microsoft/TypeScript
Refine JSON.stringify return type for booean value
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
JSON.stringify "true" "false"
Suggestion
I'd like to have additional typings for the return type of JSON.stringify, namely when given a boolean, the return type should be 'true' | 'false'
Use Cases
In React assigning the ARIA boolean attributes requires a boolean-string, currently you have to do:
<div aria-expanded={isExpanded ? 'true' : 'false'}/>
With the change you could simplify that to:
<div aria-expanded={JSON.stringify(isExpanded)}/>
Examples
const r1: 'true' | 'false' = JSON.stringify(true);
// Or if we could have it be even more granular:
const r2a: 'true' = JSON.stringify(true);
const r2b: 'false' = JSON.stringify(false);
``
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test path is named in the issue. Start by locating the TypeScript declaration and existing tests for JSON.stringify, then compare boolean inputs with the requested literal return types. Done means the boolean examples type-check with the intended return type while existing stringify behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100