mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-24 06:14:01 +08:00
28 lines
672 B
JavaScript
28 lines
672 B
JavaScript
// The commander shape in miniature: a getter/setter method whose declared
|
|
// OVERLOADS (index.d.ts) say `name(): string` / `name(v): this`, while the
|
|
// JS body infers the union `string | Chainy` — chained program-side calls
|
|
// typecheck against the .d.ts and FAIL against the inferred surface.
|
|
'use strict';
|
|
|
|
class Chainy {
|
|
constructor() {
|
|
this._name = '';
|
|
this._tag = '';
|
|
}
|
|
name(v) {
|
|
if (v === undefined) return this._name;
|
|
this._name = v;
|
|
return this;
|
|
}
|
|
tag(v) {
|
|
if (v === undefined) return this._tag;
|
|
this._tag = v;
|
|
return this;
|
|
}
|
|
render() {
|
|
return this._name + '#' + this._tag;
|
|
}
|
|
}
|
|
|
|
module.exports = { Chainy };
|