Q:

TypeScript write "if" in short

I am beginner web developer.
I am not good at English , sorry.
export class Vector{
    protected x : number = 0
    protected y : number = 0
    protected z : number = 0

    set(x?: number , y? : number , z? : number){
        this.x = x ? x : this.x
        this.y = y ? y : this.y
        this.z = z ? z : this.z
    }
}

I want to erase ":this.x" from "this.x = x ? x : this.x"
I want to write shortly , and I want to erase else part.
set(x?: number , y? : number , z? : number){
    if(x){
      this.x = x
    }
}

I don't want to write like this.
Because it is not cool.
Anyone please tell me cool way to write this code.
--Add---
What I want to do is something like this.
set(x?: number , y? : number , z? : number){
            this.x = x ? x : DO NOTHING(WRITE NOTHNG)
        }

----------To Lars Holdaas----------

Here! Under the equal!
Saying ";" is required.

A:

Usually x && this.x=x would be the shortest syntax to get this done.
However x, y and z are all numbers. It's a bit dangerous to use this short-hand syntax for numbers. Consider the case where set is called with x=0. 0 && this.x=x would not execute this.x as 0 is falsey in Javascript. From reading your code this does not seem like what you want to achieve, instead you want to skip setting this.x in the case x is undefined.
In that case, I suggest the following code:
set(x?: number , y? : number , z? : number){
    typeof x === 'number' && (this.x = x);
    typeof y === 'number' && (this.y = y);
    typeof z === 'number' && (this.z = z);
}

That way your set-function will support sending 0 as an argument, which it currently does not.

