microsoft / microsoft/TypeScript
Preserve `set`-only accessors in declaration emit
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Related to https://github.com/microsoft/TypeScript/issues/58112#issuecomment-2043419380
export let same = {
set x(value: string) {
},
get x(): string {
throw new Error("Not implemented.")
},
};
export let divergent = {
set x(value: string) {
},
get x(): number {
throw new Error("Not implemented.")
},
};
export let readonly = {
get x(): string {
throw new Error("Not implemented.")
},
};
export let writeonly = {
set x(value: string) {
},
};
Current
Notice that in the declaration of writeonly, we don't preserve the accessor at all.
export declare let same: {
x: string;
};
export declare let divergent: {
get x(): number;
set x(value: string);
};
export declare let readonly: {
readonly x: string;
};
export declare let writeonly: {
x: string;
};
Expected
If we had a writeonly modifier, I'd argue we could just use that as a parallel to the readonly declaration; however, we do support accessors in declaration emit, and we could emit that in the case of a write-only accessor.
It is technically a breaking change though for consumers of older TypeScript versions, and the only way to opt out would be to declare a no-op get accessor.
export declare let same: {
x: string;
};
export declare let divergent: {
get x(): number;
set x(value: string);
};
export declare let readonly: {
readonly x: string;
};
export declare let writeonly: {
set x(): string;
};
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 Playground and reproduce the declaration output for the same, divergent, readonly, and writeonly accessors. Trace the TypeScript declaration-emission path for object accessors and compare existing accessor-related tests or baselines; done means a write-only accessor is preserved in the emitted declaration without changing the other shown outputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100