Skip to content

Allow setter type to be incompatible with the getter typeΒ #43662

Closed
@saschanaz

Description

@saschanaz

Suggestion

πŸ” Search Terms

differing accessor types

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

#42425 forces the getter type to be assignable to the setter type. This makes the feature limited on the following DOM typing case, and thus it could be great if the limitation can be lifted.

πŸ“ƒ Motivating Example

[Exposed=Window]
interface CSSStyleRule : CSSRule {
  attribute CSSOMString selectorText;
  [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
};
interface CSSStyleRule extends CSSRule {
    selectorText: string;
    get style(): CSSStyleDeclaration;
    set style(cssText: string); // currently an error
}
document.body.style = "display: none" // thus still an error while the actual behavior allows it πŸ€”

πŸ’» Use Cases

Allows Web IDL readonly attributes to be assignable, and thus the DOM typing better matches the actual behavior.

Transferred from microsoft/TypeScript-DOM-lib-generator#996.

Metadata

Metadata

Assignees

Labels

Experience EnhancementNoncontroversial enhancementsFix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.SuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions