Skip to content

Getting a setter-only property is typed as the setter's parameter's type instead of undefinedΒ #60954

Open
@Gouvernathor

Description

@Gouvernathor

πŸ”Ž Search Terms

setter only

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, from 5.7.3 down to 3.3.3333

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.3#code/MYewdgzgLgBANgQzAcwK4OQUxgXhgbwCgYYJNZhUAnKzMKACjAQFtMAuUqKgSxQEoCxEjCgALHhAB0cEMikAHVBDFNWmfgG5hAXwA0w2ck4BtALowEELrxTmDO7YUQp0WKZRp1YeAEQAxACVfJ1BIClx4JDQMTA9qWnptIA

πŸ’» Code

const language = {
  set current(name: string) {
    this.log.push(name);
  },
  log: [] as string[],
};

language.current = "FR";

const c = language.current;

πŸ™ Actual behavior

Variable c is said to be of type string.

πŸ™‚ Expected behavior

As clearly stated here, it should be undefined.

Note that current is not defined, and any attempts to access it will result in undefined.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions