Skip to content

Const variables initialized with parenthesized arrow expression cannot get expando properties #46284

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

Open
jcalz opened this issue Oct 9, 2021 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@jcalz
Copy link
Contributor

jcalz commented Oct 9, 2021

Bug Report

πŸ”Ž Search Terms

expando, property assignments, arrow expression, #26368, #44988, #42203

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried since TypeScript 3.1

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type DescribableFunction = {
    description: string;
    (someArg: number): boolean;
};

const ok: DescribableFunction = (x: number) => false;
ok.description = 'description';

const ko: DescribableFunction = ((x: number) => false); // error!
//    ~~ <-- Property 'description' is missing
ko.description = 'description';

πŸ™ Actual behavior

ko is not recognized as a function capable of having expando properties added to it, while ok is recognized as such.

πŸ™‚ Expected behavior

Both ok and ko should behave the same way and allow expando properties as implemented in #26368. I don't know if it's common or not to use parentheses in this situation, but it was surprising to me when I ran into this discrepancy. I see from #44988 and #42203 that sometimes parentheses will disrupt things, so this is presumably an unanticipated use case that may not be important enough for anyone to address.

@andrewbranch
Copy link
Member

Is this a common syntactic pattern? In general we try to ignore parens in semantic analysis, but like, I wouldn’t expect a function-returning IIFE to work, so it seems like a bit of a gray area to me.

@andrewbranch andrewbranch added Bug A bug in TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript and removed Bug A bug in TypeScript labels Oct 11, 2021
@andrewbranch
Copy link
Member

Meh, going to call it a suggestion. If there’s evidence that this is causing confusion, I’m open to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants