microsoft / microsoft/TypeScript
Explicitly annotated unique symbols are widened in return positions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
widening return unique symbol
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
export const test = Symbol()
export function fn() {
const alias: typeof test = test;
return alias
}
🙁 Actual behavior
this declaration file is emitted:
export declare const test: unique symbol;
export declare function fn(): symbol;
🙂 Expected behavior
this declaration file to be emitted:
export declare const test: unique symbol;
export declare function fn(): typeof test;
Additional information
getWidenedLiteralLikeTypeForContextualReturnTypeIfNeeded calls getWidenedLiteralLikeTypeForContextualType and that calls getWidenedUniqueESSymbolType when there is no contextual type provided.
some issues that are (partially~) related:
https://github.com/microsoft/TypeScript/issues/32242
https://github.com/microsoft/TypeScript/issues/35896#issuecomment-569466046
https://github.com/microsoft/TypeScript/issues/36876
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
Start with the linked TypeScript Playground and reproduce the emitted declaration for the example. Read getWidenedLiteralLikeTypeForContextualReturnTypeIfNeeded, getWidenedLiteralLikeTypeForContextualType, and getWidenedUniqueESSymbolType as identified in the issue. Done means the declaration preserves the explicit unique-symbol type as typeof test rather than widening fn's return type to symbol.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100