Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export types from /server entrypoint #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"./server": {
"node": {
"types": "./dist/types/single-spa-layout-server.d.ts",
"types": "./dist/types/single-spa-layout-server-interface.d.ts",
"import": "./dist/esm/single-spa-layout-server.min.js",
"require": "./dist/umd/single-spa-layout-server.min.cjs"
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file exists so that typescript understands the following:
// import 'single-spa-layout/server'
export * from "../single-spa-layout-server";
export * from "../single-spa-layout-server-interface";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create a separate single-spa-layout-server-interface file rather than add the exports to src/server/index.ts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types for the package's /server entry point are located in ./dist/types/single-spa-layout-server.d.ts, as specified in the package.json file.

As far as I can tell, the src/server/index.ts file is not used by TypeScript, which means we cannot rely solely on it for type definitions. However, it's possible that older versions of TypeScript might still use src/server/index.ts. I don't know about that, but after all the file was certainly added for a reason.

In the end, I followed the same approach as with the package's default entry point by creating the single-spa-layout-server-interface file. Additionally, I added the rexport in src/server/index.ts to be on the safe side for older TypeScript versions.

10 changes: 10 additions & 0 deletions src/single-spa-layout-server-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export * from "./single-spa-layout-server";
export {
HTMLTemplateOptions,
ServerLayout,
} from "./server/constructServerLayout";
export {
AppToRender,
ApplicationRenderResult,
RenderResult,
} from "./server/sendLayoutHTTPResponse";