https://serverless-stack.com/ logo
#help
Title
# help
t

Tim

05/09/2022, 5:30 PM
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

Adam Fanello

05/09/2022, 5:43 PM
In v1, I had to use
sst.Api<any>
.
t

Tim

05/09/2022, 5:44 PM
thanks, that works
f

Frank

05/09/2022, 11:26 PM
@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