I’m trying to export an api from a stack so I can ...
# help
t
I’m trying to export an api from a stack so I can pass it to another stack
Copy code
export default class ApiStack extends sst.Stack {
  api: sst.Api;

  constructor(scope: <http://sst.App|sst.App>, id: string, props: ApiStackProps) {
    const api = new sst.Api(this, 'Api', {
      ...
    });

    this.api = api;
  }
}
but assigning to
this.api
gives me a typescript error
Copy code
Type 'Api<{ Authorizer: { type: "user_pool"; userPool: { id: string; clientIds: string[]; }; }; }>' is not assignable to type 'Api<Record<string, never>>'.
the advice here https://serverless-stack.slack.com/archives/C01JG3B20RY/p1649883144610549 was to rely on type inference, but in the props for the stack I’m passing it to I don’t see how I can do that
I’m trying to avoid having to type it as
api: any
in the other stack’s props
a
In v1, I had to use
sst.Api<any>
.
t
thanks, that works
f
@Tim give functional stack a try, type gets inferred (cc @thdxr). Here’s an example https://docs.serverless-stack.com/constructs/Api#sharing-an-api-across-stacks