Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Created November 13, 2022 00:04
Show Gist options
  • Save zakuroishikuro/de84483374b3dbc08614441079776573 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/de84483374b3dbc08614441079776573 to your computer and use it in GitHub Desktop.
console.logするだけのgetter生やしたい
Object.defineProperty(Object.prototype, "out", {
get() {
console.log(this.toString());
return this;
},
});
interface Object {
get out(): any; // ここをanyじゃなくoutを呼んでいるインスタンスの型にしたい
}
"abc".out.slice(1).out; // .out以降がanyになってしまうのでslice等がサジェストされない
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment