Skip to content

toString doesn't work on getter #628

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

Closed
trusktr opened this issue Jun 3, 2019 · 4 comments
Closed

toString doesn't work on getter #628

trusktr opened this issue Jun 3, 2019 · 4 comments

Comments

@trusktr
Copy link
Member

trusktr commented Jun 3, 2019

I have:

class Vector2 {
	public constructor(
		public x: f64 = 0,
		public y: f64 = 0
	) {}

	get X(): f64 {
		return this.x
	}
	set X(val: f64) {
		this.x = val
	}
}

const v = new Vector2(1, 2)
const x: string = v.x.toString() // works fine
const X: string = v.X.toString() // ERROR TS2339: Property 'toString' does not exist on type 'f64'.

The use of toString doesn't work on the result of the getter.

@trusktr trusktr changed the title But with getters/setters and toString on f64? Bug with getters/setters and toString on f64? Jun 3, 2019
@trusktr trusktr changed the title Bug with getters/setters and toString on f64? toString doesn't work on getter Jun 3, 2019
@trusktr
Copy link
Member Author

trusktr commented Jun 3, 2019

As a workaround, I can first save the result in a new var:

const _X = v.X
const X: string = _X.toString() // it works

@willemneal
Copy link
Contributor

This is a bigger issue than just toString and something that I have been meaning to make an issue about. The problem is the resolution of the property in the expression. Which is why your fix to separate the resolution into two steps fixed the issue.

@dcodeIO
Copy link
Member

dcodeIO commented Jun 4, 2019

Related: #473

@trusktr
Copy link
Member Author

trusktr commented Jun 11, 2019

closing as duplicate

@trusktr trusktr closed this as completed Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants