microsoft / microsoft/TypeScript
Expando function declarations cant emit non-identifier properties
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
expando properties function declaration symbol computed
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
export const sym = Symbol()
const dashes = 'my-prop'
export function decl() {}
decl.foo = 1
decl[sym] = 2
decl[dashes] = ''
decl[10] = ''
decl["100"] = ''
export const arrow = () => {}
arrow.foo = 1
arrow[sym] = 2
arrow[dashes] = ''
arrow[10] = ''
arrow["100"] = ''
🙁 Actual behavior
export declare const sym: unique symbol;
export declare function decl(): void;
export declare namespace decl {
var foo: number;
}
export declare const arrow: {
(): void;
foo: number;
10: string;
"100": string;
[sym]: number;
"my-prop": string;
};
🙂 Expected behavior
I'd expect decl to be transformed into an object instead of a namespace. That would allow the same properties to be emitted for decl as the ones that are emitted for arrow.
The object variant was the first choice by @sandersn here but then it got changed to a namespace. I didn't find any reason given for this change/decision in the PR comments though. Is there anything that the namespace can deliver here that the object variant can't?
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 compare the declaration output for decl with the output for arrow. Review the historical PR linked in the issue for the namespace decision; done means function declarations emit the same non-identifier properties as the reproduced arrow-function case without regressing the other declarations.
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
- 35/100