question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add related error spans for getter/setters with different types

See original GitHub issue

Now that we support multiple related spans for errors (#10489, #22789, #24548), we’d like to improve an existing error message.

Currently, we provide a diagnostic for a pair of get/set accessor’s types not matching:

Code:

let x = {
  get foo() { return 100; }
  set foo(value: string): { }
}

Current error:

'get' and 'set' accessor must have the same type.

We’d like to give a better error message. For example:

Primary span:

A 'get-' and 'set-' accessor must have the same type, but this 'get' accessor has the type '{0}'.

Related span:

The respective 'set' accessor has the type '{0}'.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
siriancommented, Mar 21, 2020

setters and getters MAY HAVE different types

image

get zIndex(): string
set zIndex(value: string | number | null | undefined)

Another example:

class MY_URL {
    get query(): Record<string, string>
    set query(value: string | Record<string, string | number | null |undefined>);
}

const url = new MY_URL();
url.query = "foo=1&bar=2" // string setter
url.query = {foo: 1, bar: "2"} // Record<string, ...> setter

assert("1" === url.query.foo && "2" === url.query.bar)

@RyanCavanaugh

4reactions
acagastyacommented, Feb 6, 2020

There is no restriction on get set in ECMA specification, so adhering to the standard, shouldn’t this restriction be lifted? I mean “‘get’ and ‘set’ accessor must have the same type”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to dynamically map keys to getters/setters of ...
I know these are not real getters and setters but it mimics the behaviour. type Example = { prop: number; }; type Mapped<T>...
Read more >
Using Widgets in Catalog Items - ServiceNow Elite
Use widgets within catalog items and build awesome customizations for your Service Catalog.
Read more >
Documentation - TypeScript 3.9
The function's types declare that it takes two string s so that other TypeScript users can get type-checking errors, but it also does...
Read more >
ngModelOptions - AngularJS: API
This directive allows you to modify the behaviour of ngModel directives within your application. You can specify an ngModelOptions directive on any element....
Read more >
Getters And Setters In Java: Common Mistakes, And ... - Xperti
Mistake 3: Returning the object reference directly in the getter. Mistake 4: Writing getters and setters in Java for mutable data types. Mistake...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found