atom-archive / xray

An experimental next-generation Electron-based text editor
MIT License
8.48k stars 235 forks source link

Even more types! #145

Closed joshaber closed 5 years ago

joshaber commented 5 years ago
  1. Fix an example in the README
  2. Make another array readonly
  3. Give our type aliases more specific type-level semantics.

(3) is nice because it gives type-level semantics to what would otherwise be plain type aliases. For example, even though FileId is represented as a string, it can't be just any string. It should only be a string that Memo vends. This lets us encode that in the type system:

workTree.remove("my-made-up-id")
                ^^^ type error

const fileId = workTree.fileIdForPath("my-file.txt")
workTree.remove(fileId)
                ^^^ just fine

but it also gets erased at compile time so it doesn't change runtime semantics.

as-cii commented 5 years ago

Nice, thanks! ⚡️

nathansobo commented 5 years ago

Very cool.