Narrow argument type to the specific event being listened to (#16714)
This commit is contained in:
1 parent
3ae53a4b6e
commit
6d133c26f8
7 files changed
+71
-12
No files matched your search
@@ -8,7 +8,7 @@ import ReactDom from "react-dom";
|
||||
|
||||
// Because we don't import from @calcom/embed-react, this file isn't able to test if the build is successful or not and thus npm package would work or not correctly.
|
||||
// There are tests in test/built which verifiy that the types from built package are correctly generated and exported correctly.
|
||||
import Cal, { getCalApi } from "./src/index";
|
||||
import Cal, { getCalApi, type EmbedEvent } from "./src/index";
|
||||
|
||||
const api = getCalApi({
|
||||
namespace: "inline",
|
||||
@@ -49,6 +49,27 @@ function App() {
|
||||
action: "*",
|
||||
callback,
|
||||
});
|
||||
|
||||
// Also, validates the type of e.detail.data as TS runs on this file
|
||||
const bookingSuccessfulV2Callback = (e: EmbedEvent<"bookingSuccessfulV2">) => {
|
||||
const data = e.detail.data;
|
||||
console.log("bookingSuccessfulV2", {
|
||||
endTime: data.endTime,
|
||||
startTime: data.startTime,
|
||||
title: data.title,
|
||||
});
|
||||
|
||||
// Remove the event listener after it is fired once as I don't need it.
|
||||
api("off", {
|
||||
action: "bookingSuccessfulV2",
|
||||
callback: bookingSuccessfulV2Callback,
|
||||
});
|
||||
};
|
||||
|
||||
api("on", {
|
||||
action: "bookingSuccessfulV2",
|
||||
callback: bookingSuccessfulV2Callback,
|
||||
});
|
||||
});
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -5,6 +5,9 @@ import EmbedSnippet from "@calcom/embed-snippet";
|
||||
|
||||
import Cal from "./Cal";
|
||||
|
||||
// Exporting for consumption by @calcom/embed-react user
|
||||
export type { EmbedEvent } from "@calcom/embed-core";
|
||||
|
||||
export function getCalApi(options?: {
|
||||
embedJsUrl?: string;
|
||||
namespace?: string;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"@calcom/embed-snippet": ["../embed-snippet/src"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "env.d.ts"],
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "env.d.ts", "*.tsx", "*.ts"],
|
||||
// Exclude "test" because that has `api.test.ts` which imports @calcom/embed-react which needs it to be built using this tsconfig.json first. Excluding it here prevents type-check from validating test folder
|
||||
"exclude": ["node_modules", "test"]
|
||||
}
|
||||
Reference in new issue
Block a user