Skip to content
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

Embracing symbols as a solution #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,35 @@ import { myExtension } from './myExtension'
foo[myExtension]();
```

Extensions to interfaces extend `Object` (yes `Object`, read on...).
Extensions to interfaces extend `Object` (yes `Object`, more on this later...).

### Embracing symbols as a solution

Here is how translation between typescript and javascript could possibly work.

```ts
// myExtension.ts
namespace MyApp {
export function myExtension(this: Foo) { ... }
}

// could compile to
const export myExtension = Symbol("MyApp.myExtension");
Foo.prototype[myExtension] = (this: Foo) { ... };


// foo.ts
import { myExtension } from './myExtension' // <-- optional??
...
foo.myExtension();

// could compile to
import { myExtension } from './myExtension'
...
foo[myExtension]();
```

Once we embrace the `Symbol` as an implementation solution. There are many ways to actually handle the translation. The important thing to take away is that there is no need for a new runtime artifact created by the Transcript compiler, like "Callsite rewriting". No, if Symbols is the solution provided by javascript to address this very issue. And it is acceptable by Ryan (are you there???), and the everyday typescript user that would likely love syntactic sugar on top of javascript compatible Symbols. Then it probably is the best option we have.

### What about performance?

Expand Down