The current type system is designed around the experience of writing code like the example below where objects can have two kinds of methods:
let bucket = new cloud.Bucket();
let api = new cloud.Api();
// api.get is a preflight method - it generates cloud infrastructure
api.post("/hello", inflight (req) => {
// bucket.put is an inflight method - it performs data plane operations, at "runtime"
bucket.put("data.txt", req.body ?? "empty");
});
Importantly, if you try calling bucket.put()
outside of one of these "inflight" scopes or try calling api.get()
inside one of these "inflight" scopes, you'll get compilation errors - not runtime errors.
Could this style of API be achieved in an existing language? I think it's an open ended question - I'm not sure. But I reckon it gets into complex framework territory (or may require injecting modifications into existing compilers, which presents other challenges). But I'd love to see more exploration into this direction.