I really love this idea by @yinon. He proposes that we could use an as
keyword to merge the given props of an object into a new one.
const { x, y } as coordinates = point;
Sadly, it's not showing any signs of progress. So I'd like to add some new use cases for that.
Exports
It's not uncommon when we need to export some variables as a new object.
let x = 0;
let y = 1;
export { x, y } as coordinates;
We can do it this way too. But it pollutes the namespace.
export const coordinates = { x, y };
Imports
We can import and encapsulate only what we need like this...
import { createElement, FC, useState } as React from "react";
Function Arguments
function plot({ x, y } as coordinates) {
// coordinates = { x, y }
}
Thank you .