Ah <@U01MV4U2EV9> has been flexing his TypeScript ...
# general
r
Ah @thdxr has been flexing his TypeScript muscles
t
haha we're planning on taking it way too far
r
Oooo, is this what I think it is? No more
class Stack
constructor stuff?
t
Yeah - this is a quiet release as we're planning on updating docs to do an official release. But for those interested this is now supported:
Copy code
function Api(props: StackContext) {
  const api = new sst.Api(props.stack, "myapi", {...})
  return api
}

function Frontend(props: StackContext) {
  const api = use(Api)
  const site = new sst.StaticSite(props.stack, "mysite", { environment: { API_URL: api.url } })
}
r
It may be a bit too magical, but would/could the functions bind
this
to the
EmptyStack
so
new Construct(this, props)
still works? Not sure if there might be a downside
t
we're actually thinking baout removing the need for
this
all together
r
eg
Copy code
function Api(this: Stack, props: StackProps) {
  const api = new Api(this, "Api", { /* ... */ });
}
t
and infer the the current stack
so it'd be
new Api("api", {...})
r
Hrmm. That sounds nice, but it feels like it would make it very confusing for new comers if/when they try and use non-SST resources
c
ha great, the functional stacks are live
t
@Richard Simpson yeah that's why we didn't do it, cdk constructs would still require it and the inconsistency isn't great. Binding to
this
is an interesting idea, let me play with it