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

More strict null checks work #8340

Merged
merged 72 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
cf8fdb9
getToken/refreshToken
Apr 22, 2024
c48b8f3
src/background/requests.ts
Apr 22, 2024
619e8be
src/contentScript/pageEditor/elementPicker.ts
Apr 22, 2024
96786b0
src/background/partnerIntegrations.ts
Apr 22, 2024
19c60ed
whoops
Apr 22, 2024
fa36bd6
cleanup
Apr 22, 2024
0cdffaf
fix widget and getScopeAndId
Apr 22, 2024
6d37d22
auto-add
Apr 22, 2024
a51514f
src/extensionConsole/pages/mods/GetStartedView.tsx
Apr 22, 2024
48fc706
src/mods/useModViewItems.tsx
Apr 22, 2024
b5b5427
test memo compare dependencies
Apr 22, 2024
e7be3b6
fix scopeAndId tests
Apr 22, 2024
f43adb6
autosuggest
Apr 23, 2024
5eaf7ee
src/background/backgroundPlatform.ts
Apr 23, 2024
ca34895
src/background/restrictUnauthenticatedUrlAccess.ts
Apr 23, 2024
8e45b83
src/bricks/effects/insertHtml.ts
Apr 23, 2024
2cf5876
./bricks/effects/runSubTour.ts
Apr 23, 2024
dce3731
./bricks/effects/scrollIntoView.ts
Apr 23, 2024
58816ce
src/bricks/transformers/controlFlow/WithAsyncModVariable.ts
Apr 23, 2024
80d4a78
mod state / variable context
Apr 23, 2024
ff3aec4
src/bricks/transformers/RunMetadataTransformer.ts
Apr 23, 2024
6c042c6
src/bricks/transformers/splitText.ts
Apr 23, 2024
751dafe
src/components/fields/schemaFields/widgets/varPopup/useTreeRow.ts
Apr 23, 2024
a6c200d
src/components/walkthroughModal/WalkthroughModalApp.tsx
Apr 23, 2024
158020a
src/extensionConsole/pages/brickEditor/BrickHistory.tsx
Apr 23, 2024
6fec24f
fix test
Apr 23, 2024
faef79c
src/extensionConsole/pages/mods/utils/exportBlueprint.ts
Apr 23, 2024
4be6ec3
src/extensionConsole/pages/mods/utils/exportBlueprint.ts
Apr 23, 2024
c570dd7
src/pageScript/elementInfo.ts
Apr 23, 2024
680b86d
src/sidebar/LoginPanel.tsx
Apr 23, 2024
4d45f78
src/testUtils/factories/authFactories.ts
Apr 23, 2024
dddf4b2
src/bricks/effects/attachAutocomplete.ts
Apr 23, 2024
75ee849
more bricks
Apr 23, 2024
f551c8d
fix test
Apr 23, 2024
7be7af1
src/components/fields/schemaFields/fieldTestUtils.ts
Apr 23, 2024
8d01818
add a bunch more
Apr 23, 2024
8cf8705
the rest
Apr 23, 2024
ec7c7c0
cleanup
Apr 23, 2024
134796a
fix lint
Apr 23, 2024
806f211
wip
Apr 23, 2024
db7463e
Merge branch 'main' into dev/strict-null-checks-even-moar
Apr 23, 2024
9b7dd2d
remove file
Apr 23, 2024
e60c85c
remove logs
Apr 23, 2024
597e651
fix factory
Apr 23, 2024
5c7e39e
update counts
grahamlangford Apr 24, 2024
5eb2eb6
extensionPagePlatform
grahamlangford Apr 24, 2024
051ed5f
partnerIntegrations
grahamlangford Apr 24, 2024
bae732a
update counts
grahamlangford Apr 24, 2024
5620c5c
Merge branch 'main' of github.com:pixiebrix/pixiebrix-extension into …
grahamlangford Apr 24, 2024
a93f471
finding cycles
grahamlangford Apr 24, 2024
4d6a41c
documenting cycle
grahamlangford Apr 24, 2024
b4177f5
move starterbricks into separate folders
grahamlangford Apr 24, 2024
d327b91
extract shared types from contextmenu
grahamlangford Apr 24, 2024
2a34559
migrate shared types for menuItemExtension
grahamlangford Apr 24, 2024
be1660b
migrate panel types; migrate more contextMenu types
grahamlangford Apr 24, 2024
da3eaf2
migrate more menuitem types
grahamlangford Apr 24, 2024
ca930a9
migrate quickbar types
grahamlangford Apr 24, 2024
b0b5512
migrate quickbar provider types
grahamlangford Apr 24, 2024
562e0c5
migrate sidebar types
grahamlangford Apr 24, 2024
f268c2a
migrate tour types
grahamlangford Apr 24, 2024
62025ff
update file paths
grahamlangford Apr 24, 2024
147ca6a
auto-add
grahamlangford Apr 24, 2024
01a0ad7
fix types
grahamlangford Apr 24, 2024
4345ca3
auto-add
grahamlangford Apr 24, 2024
420f50e
cleanup
grahamlangford Apr 24, 2024
33c914c
more contentScript messenger migrations
grahamlangford Apr 24, 2024
a0e3074
Merge branch 'main' of github.com:pixiebrix/pixiebrix-extension into …
grahamlangford Apr 24, 2024
fa81576
selectElement
grahamlangford Apr 24, 2024
b605288
lint fix
grahamlangford Apr 24, 2024
f49232d
fix some PR-related issues
grahamlangford Apr 25, 2024
0c221cf
PR-related fixes
grahamlangford Apr 25, 2024
58d9292
revert defaulting to false
grahamlangford Apr 25, 2024
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
19 changes: 12 additions & 7 deletions src/background/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ async function isLikelyEndUserInstall(): Promise<boolean> {
// The CWS install URL differs based on the extension listing slug. So instead, only match on the runtime id.
return likelyOnboardingTabs.some(
(tab) =>
tab.url.includes(DEFAULT_SERVICE_URL) ||
tab.url.includes(browser.runtime.id),
tab.url?.includes(DEFAULT_SERVICE_URL) ||
tab.url?.includes(browser.runtime.id),
);
}

Expand Down Expand Up @@ -105,9 +105,11 @@ export async function openInstallPage() {
// Case 3: there's no Admin Console onboarding tab open

if (appOnboardingTab) {
const appOnboardingTabUrl = new URL(appOnboardingTab.url);
const appOnboardingTabUrl = appOnboardingTab?.url
? new URL(appOnboardingTab.url)
: null;

if (appOnboardingTabUrl.pathname === "/start") {
if (appOnboardingTabUrl?.pathname === "/start") {
// Case 1a/1b: Admin Console is showing a partner onboarding flow

const controlRoomHostname =
Expand Down Expand Up @@ -312,10 +314,13 @@ export function getAvailableVersion(): typeof _availableVersion {
*/
export function isUpdateAvailable(): boolean {
const available = getAvailableVersion();

if (!available) {
return false;
}

const installed = getExtensionVersion();
return (
Boolean(available) && installed !== available && gt(available, installed)
);
return installed !== available && gt(available, installed);
}

async function setUninstallURL(): Promise<void> {
Expand Down
1 change: 0 additions & 1 deletion src/background/messenger/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
getNotifier,
} from "webext-messenger";

export const getAvailableVersion = getMethod("GET_AVAILABLE_VERSION", bg);
export const setPartnerCopilotData = getNotifier(
"SET_PARTNER_COPILOT_DATA",
bg,
Expand Down
10 changes: 3 additions & 7 deletions src/background/messenger/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ import {
ensureContextMenu,
preloadContextMenus,
uninstallContextMenu,
} from "@/background/contextMenus"; // 213 strictNullCheck errors
} from "@/background/contextMenus"; // 205 strictNullCheck errors
import {
requestRunInAllFrames,
requestRunInOtherTabs,
requestRunInOpener,
requestRunInTarget,
requestRunInTop,
} from "@/background/executor"; // Depends on contentScript/messenger to pass strictNullCheck
import { getAvailableVersion } from "@/background/installer"; // 196 strictNullCheck errors
import { removeExtensionForEveryTab } from "@/background/removeExtensionForEveryTab"; // 213 strictNullCheck errors
import { debouncedActivateStarterMods as installStarterBlueprints } from "@/background/starterMods"; // 219 strictNullCheck errors
import { removeExtensionForEveryTab } from "@/background/removeExtensionForEveryTab"; // 207 strictNullCheck errors
import { debouncedActivateStarterMods as installStarterBlueprints } from "@/background/starterMods"; // 211 strictNullCheck errors
import {
collectPerformanceDiagnostics,
initTelemetry,
Expand All @@ -53,7 +52,6 @@ expectContext("background");

declare global {
interface MessengerMethods {
GET_AVAILABLE_VERSION: typeof getAvailableVersion;
PRELOAD_CONTEXT_MENUS: typeof preloadContextMenus;
UNINSTALL_CONTEXT_MENU: typeof uninstallContextMenu;
ENSURE_CONTEXT_MENU: typeof ensureContextMenu;
Expand Down Expand Up @@ -85,8 +83,6 @@ export default function registerMessenger(): void {

INSTALL_STARTER_BLUEPRINTS: installStarterBlueprints,

GET_AVAILABLE_VERSION: getAvailableVersion,

PRELOAD_CONTEXT_MENUS: preloadContextMenus,
UNINSTALL_CONTEXT_MENU: uninstallContextMenu,
ENSURE_CONTEXT_MENU: ensureContextMenu,
Expand Down
2 changes: 2 additions & 0 deletions src/background/messenger/strict/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import type { RemoteResponse } from "@/types/contract";
import { type SanitizedIntegrationConfig } from "@/integrations/integrationTypes";
import { type Nullishable } from "@/utils/nullishUtils";

export const getAvailableVersion = getMethod("GET_AVAILABLE_VERSION", bg);

export const showMySidePanel = getMethod("SHOW_MY_SIDE_PANEL", bg);
export const waitForContentScript = getMethod("WAIT_FOR_CONTENT_SCRIPT", bg);

Expand Down
5 changes: 5 additions & 0 deletions src/background/messenger/strict/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
getPartnerPrincipals,
launchAuthIntegration,
} from "@/background/partnerIntegrations";
import { getAvailableVersion } from "@/background/installer";

expectContext("background");

Expand Down Expand Up @@ -107,6 +108,8 @@ declare global {

GET_PARTNER_PRINCIPALS: typeof getPartnerPrincipals;
LAUNCH_AUTH_INTEGRATION: typeof launchAuthIntegration;

GET_AVAILABLE_VERSION: typeof getAvailableVersion;
}
}

Expand Down Expand Up @@ -158,5 +161,7 @@ export default function registerMessenger(): void {

GET_PARTNER_PRINCIPALS: getPartnerPrincipals,
LAUNCH_AUTH_INTEGRATION: launchAuthIntegration,

GET_AVAILABLE_VERSION: getAvailableVersion,
});
}
16 changes: 8 additions & 8 deletions src/background/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ interface UserSummary {
/**
* The version_name from the manifest.
*/
versionName: string;
versionName?: string;

/**
* The number of active mod components.
*/
numActiveExtensions: number;
numActiveExtensions: number | null;

/**
* The number of active mods.
*/
numActiveBlueprints: number;
numActiveBlueprints: number | null;

/**
* The number of active starer bricks.
*/
numActiveExtensionPoints: number;
numActiveExtensionPoints: number | null;

/**
* The detected operating system.
Expand All @@ -105,7 +105,7 @@ interface UserSummary {
/**
* The detected browser version.
*/
$browser_version: number;
$browser_version: number | null;
}

/**
Expand Down Expand Up @@ -279,9 +279,9 @@ async function collectUserSummary(): Promise<UserSummary> {
// Not supported on Chromium, and may require additional permissions
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/getBrowserInfo
// const {name: browserName} = await browser.runtime.getBrowserInfo();
let numActiveExtensions: number = null;
let numActiveExtensionPoints: number = null;
let numActiveBlueprints: number = null;
let numActiveExtensions: number | null = null;
let numActiveExtensionPoints: number | null = null;
let numActiveBlueprints: number | null = null;

try {
const { extensions } = await getModComponentState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { menuItemFormStateFactory } from "@/testUtils/factories/pageEditorFactor
import { JQueryReader } from "@/bricks/transformers/jquery/JQueryReader";
import registerDefaultWidgets from "@/components/fields/schemaFields/widgets/registerDefaultWidgets";
import { waitForEffect } from "@/testUtils/testHelpers";
import { getAttributeExamples } from "@/contentScript/messenger/api";
import { getAttributeExamples } from "@/contentScript/messenger/strict/api";
import { screen } from "@testing-library/react";
import SchemaFieldContext from "@/components/fields/schemaFields/SchemaFieldContext";
import devtoolFieldOverrides from "@/pageEditor/fields/devtoolFieldOverrides";
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/transformers/jquery/JQueryReaderOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import SelectWidget, {
type SelectLike,
} from "@/components/form/widgets/SelectWidget";
import useAsyncState from "@/hooks/useAsyncState";
import { getAttributeExamples } from "@/contentScript/messenger/api";
import { getAttributeExamples } from "@/contentScript/messenger/strict/api";
import { fallbackValue } from "@/utils/asyncStateUtils";
import { type AttributeExample } from "@/contentScript/pageEditor/types";
import CollapsibleFieldSection from "@/pageEditor/fields/CollapsibleFieldSection";
Expand Down
6 changes: 0 additions & 6 deletions src/contentScript/messenger/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const toggleQuickBar = getMethod("TOGGLE_QUICK_BAR");

export const insertPanel = getMethod("INSERT_PANEL");
export const insertButton = getMethod("INSERT_BUTTON");
export const getAttributeExamples = getMethod("GET_ATTRIBUTE_EXAMPLES");

export const runBlock = getMethod("RUN_SINGLE_BLOCK");
export const runRendererBlock = getMethod("RUN_RENDERER_BLOCK");
Expand All @@ -59,16 +58,11 @@ export const getInstalledExtensionPoints = getMethod(
);
export const checkAvailable = getMethod("CHECK_AVAILABLE");
export const runBrick = getMethod("RUN_BRICK");
export const selectElement = getMethod("SELECT_ELEMENT");

export const runRendererPipeline = getMethod("RUN_RENDERER_PIPELINE");
export const runHeadlessPipeline = getMethod("RUN_HEADLESS_PIPELINE");
export const runMapArgs = getMethod("RUN_MAP_ARGS");

export const getCopilotHostData = getMethod("GET_COPILOT_HOST_DATA");

export const reloadMarketplaceEnhancements = getMethod(
"RELOAD_MARKETPLACE_ENHANCEMENTS",
);

export const showLoginBanner = getMethod("SHOW_LOGIN_BANNER");
21 changes: 5 additions & 16 deletions src/contentScript/messenger/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,27 @@ import {
queueReactivateTab,
reactivateTab,
removePersistedExtension,
} from "@/contentScript/lifecycle"; // 214 strictNullCheck errors
import { insertPanel } from "@/contentScript/pageEditor/insertPanel"; // 216 strictNullCheck errors
import { insertButton } from "@/contentScript/pageEditor/insertButton"; // 222 strictNullCheck errors
} from "@/contentScript/lifecycle"; // 203 strictNullCheck errors
import { insertPanel } from "@/contentScript/pageEditor/insertPanel"; // 31 strictNullCheck errors
import { insertButton } from "@/contentScript/pageEditor/insertButton"; // 37 strictNullCheck errors
import {
clearDynamicElements,
disableOverlay,
enableOverlay,
runExtensionPointReader,
updateDynamicElement,
} from "@/contentScript/pageEditor/dynamic"; // 217 strictNullCheck errors
} from "@/contentScript/pageEditor/dynamic"; // 206 strictNullCheck errors
import {
runBlockPreview,
resetTab,
runRendererBlock,
} from "@/contentScript/pageEditor"; // 219 strictNullCheck errors
} from "@/contentScript/pageEditor"; // 208 strictNullCheck errors
import { runBrick } from "@/contentScript/executor"; // Depends on background/messenger to pass strictNullCheck
import selectElement from "@/contentScript/pageEditor/selectElement"; // 196 strictNullCheck errors
import {
runHeadlessPipeline,
runMapArgs,
runRendererPipeline,
} from "@/contentScript/pipelineProtocol"; // Depends on background/messenger to pass strictNullCheck
import { reloadActivationEnhancements } from "@/contentScript/loadActivationEnhancementsCore"; // 187 strictNullCheck errors
import { getAttributeExamples } from "@/contentScript/pageEditor/elementInformation"; // 185 strictNullCheck errors
import { getCopilotHostData } from "@/contrib/automationanywhere/SetCopilotDataEffect"; // Depends on background/messenger to pass strictNullCheck
import { showBannerFromConfig } from "@/contentScript/integrations/deferredLoginController"; // Depends on background/messenger to pass strictNullCheck

Expand All @@ -69,7 +66,6 @@ declare global {
INSERT_PANEL: typeof insertPanel;
INSERT_BUTTON: typeof insertButton;

GET_ATTRIBUTE_EXAMPLES: typeof getAttributeExamples;
RUN_SINGLE_BLOCK: typeof runBlockPreview;
RUN_RENDERER_BLOCK: typeof runRendererBlock;

Expand All @@ -82,7 +78,6 @@ declare global {
ENSURE_EXTENSION_POINTS_INSTALLED: typeof ensureInstalled;

RUN_BRICK: typeof runBrick;
SELECT_ELEMENT: typeof selectElement;

RUN_RENDERER_PIPELINE: typeof runRendererPipeline;
RUN_HEADLESS_PIPELINE: typeof runHeadlessPipeline;
Expand All @@ -91,8 +86,6 @@ declare global {
GET_COPILOT_HOST_DATA: typeof getCopilotHostData;

SHOW_LOGIN_BANNER: typeof showBannerFromConfig;

RELOAD_MARKETPLACE_ENHANCEMENTS: typeof reloadActivationEnhancements;
}
}

Expand All @@ -106,7 +99,6 @@ export default function registerMessenger(): void {
INSERT_PANEL: insertPanel,
INSERT_BUTTON: insertButton,

GET_ATTRIBUTE_EXAMPLES: getAttributeExamples,
RUN_SINGLE_BLOCK: runBlockPreview,
RUN_RENDERER_BLOCK: runRendererBlock,

Expand All @@ -119,7 +111,6 @@ export default function registerMessenger(): void {
ENSURE_EXTENSION_POINTS_INSTALLED: ensureInstalled,

RUN_BRICK: runBrick,
SELECT_ELEMENT: selectElement,

RUN_RENDERER_PIPELINE: runRendererPipeline,
RUN_HEADLESS_PIPELINE: runHeadlessPipeline,
Expand All @@ -128,7 +119,5 @@ export default function registerMessenger(): void {
GET_COPILOT_HOST_DATA: getCopilotHostData,

SHOW_LOGIN_BANNER: showBannerFromConfig,

RELOAD_MARKETPLACE_ENHANCEMENTS: reloadActivationEnhancements,
});
}
6 changes: 6 additions & 0 deletions src/contentScript/messenger/strict/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ export const notify = {
};

export const cancelSelect = getMethod("CANCEL_SELECT_ELEMENT");

export const reloadMarketplaceEnhancements = getMethod(
"RELOAD_MARKETPLACE_ENHANCEMENTS",
);
export const getAttributeExamples = getMethod("GET_ATTRIBUTE_EXAMPLES");
export const selectElement = getMethod("SELECT_ELEMENT");
9 changes: 9 additions & 0 deletions src/contentScript/messenger/strict/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ import showWalkthroughModal from "@/components/walkthroughModal/showWalkthroughM
import { registerMethods } from "webext-messenger";
import { toggleQuickBar } from "@/components/quickBar/QuickBarApp";
import { cancelSelect } from "@/contentScript/pageEditor/elementPicker";
import { reloadActivationEnhancements } from "@/contentScript/loadActivationEnhancementsCore";
import { getAttributeExamples } from "@/contentScript/pageEditor/elementInformation";
import selectElement from "@/contentScript/pageEditor/selectElement";

declare global {
interface MessengerMethods {
Expand Down Expand Up @@ -75,6 +78,9 @@ declare global {
WALKTHROUGH_MODAL_SHOW: typeof showWalkthroughModal;
TOGGLE_QUICK_BAR: typeof toggleQuickBar;
CANCEL_SELECT_ELEMENT: typeof cancelSelect;
RELOAD_MARKETPLACE_ENHANCEMENTS: typeof reloadActivationEnhancements;
GET_ATTRIBUTE_EXAMPLES: typeof getAttributeExamples;
SELECT_ELEMENT: typeof selectElement;
}
}
export default function registerMessenger(): void {
Expand Down Expand Up @@ -105,5 +111,8 @@ export default function registerMessenger(): void {
WALKTHROUGH_MODAL_SHOW: showWalkthroughModal,
TOGGLE_QUICK_BAR: toggleQuickBar,
CANCEL_SELECT_ELEMENT: cancelSelect,
RELOAD_MARKETPLACE_ENHANCEMENTS: reloadActivationEnhancements,
GET_ATTRIBUTE_EXAMPLES: getAttributeExamples,
SELECT_ELEMENT: selectElement,
});
}
26 changes: 14 additions & 12 deletions src/contentScript/pageEditor/selectElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export default async function selectElement({
mode = "element",
root,
isMulti: initialIsMulti = false,
excludeRandomClasses,
excludeRandomClasses = false,
}: {
mode: SelectMode;
isMulti?: boolean;
root?: string;
excludeRandomClasses?: boolean;
}): Promise<ElementInfo> {
const rootElements = $safeFind(root).get();
const rootElements = root ? $safeFind(root).get() : [];

if (root && rootElements.length === 0) {
throw new NoElementsFoundError(root);
Expand All @@ -59,10 +59,10 @@ export default async function selectElement({

const { selectors } = findContainer(elements);

findSingleElement(selectors[0]);
findSingleElement(selectors[0] ?? "");

return pageScript.getElementInfo({
selector: selectors[0],
selector: selectors[0] ?? "",
});
}

Expand All @@ -71,9 +71,10 @@ export default async function selectElement({

if (isMulti) {
// If there are rootElements, the elements must all be contained within the same root
activeRoot = rootElements?.find((rootElement) =>
elements.every((element) => rootElement.contains(element)),
);
activeRoot =
rootElements?.find((rootElement) =>
elements.every((element) => rootElement.contains(element)),
) ?? null;

return inferMultiElementSelector({
elements,
Expand All @@ -89,11 +90,12 @@ export default async function selectElement({
);
}

const element = elements[0];
// At least one much match, otherwise userSelectElement would have thrown
activeRoot = rootElements?.find((rootElement) =>
rootElement.contains(element),
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- at least one element must be present
const element = elements[0]!;
// At least one must match, otherwise userSelectElement would have thrown
activeRoot =
rootElements?.find((rootElement) => rootElement.contains(element)) ??
null;
Comment on lines +95 to +98
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think the comment here means we could safely use assertNotNullish()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is find can always return undefined. I think this is the simplest from a typing. Other option would be to use !

Copy link
Contributor

Choose a reason for hiding this comment

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

This wouldn't work?

Suggested change
// At least one must match, otherwise userSelectElement would have thrown
activeRoot =
rootElements?.find((rootElement) => rootElement.contains(element)) ??
null;
activeRoot = rootElements?.find((rootElement) => rootElement.contains(element));
// At least one must match, otherwise userSelectElement would have thrown
assertNotNullish(activeRoot);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, cause then I would have to change the typing of activeRoot to allow undefined


return inferSingleElementSelector({
root: activeRoot,
Expand Down
Loading
Loading