Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.12.1",
"@babel/preset-typescript": "^7.16.7",
"@cypress/code-coverage": "^3.9.12",
"@cypress/react": "^5.10.3",
"@cypress/webpack-dev-server": "^1.7.0",
Expand All @@ -132,8 +132,8 @@
"@types/tabbable": "^3.1.0",
"@types/url-parse": "^1.4.3",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"argparse": "^2.0.1",
"autoprefixer": "^9.8.6",
"axe-core": "^4.1.1",
Expand Down Expand Up @@ -205,7 +205,7 @@
"puppeteer": "^5.5.0",
"raw-loader": "^4.0.1",
"react": "^16.12.0",
"react-docgen-typescript": "^1.20.5",
"react-docgen-typescript": "^2.2.2",
"react-dom": "^16.12.0",
"react-helmet": "^6.1.0",
"react-redux": "^7.2.1",
Expand All @@ -228,7 +228,7 @@
"start-server-and-test": "^1.11.3",
"style-loader": "^1.2.1",
"terser-webpack-plugin": "^4.1.0",
"typescript": "4.1.3",
"typescript": "4.5.3",
"uglifyjs-webpack-plugin": "^2.2.0",
"url-loader": "^4.1.0",
"webpack": "^4.46.0",
Expand All @@ -247,6 +247,6 @@
"prop-types": "^15.5.0",
"react": "^16.12",
"react-dom": "^16.12",
"typescript": "~4.1.3"
"typescript": "~4.5.3"
Comment thread
cee-chen marked this conversation as resolved.
}
}
2 changes: 1 addition & 1 deletion src-docs/src/components/guide_section/guide_section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const GuideSection: FunctionComponent<GuideSection> = ({
const isPlaygroundUnsupported =
typeof window !== 'undefined' &&
typeof document !== 'undefined' &&
!!window.MSInputMethodContext &&
!!(window as any).MSInputMethodContext &&
// @ts-ignore doesn't exist?
!!document.documentMode;

Expand Down
7 changes: 3 additions & 4 deletions src/components/header/header_links/header_links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,15 @@ export const EuiHeaderLinks: FunctionComponent<EuiHeaderLinksProps> = ({
popoverProps,
...rest
}) => {
const { onClick: _onClick, iconType = 'apps', ...popoverButtonRest } = {
...popoverButtonProps,
};
const { onClick, iconType = 'apps', ...popoverButtonRest } =
popoverButtonProps || {};

const [mobileMenuIsOpen, setMobileMenuIsOpen] = useState(false);

const onMenuButtonClick: MouseEventHandler<
HTMLButtonElement & HTMLAnchorElement
> = (e) => {
_onClick && _onClick(e);
onClick?.(e);
setMobileMenuIsOpen(!mobileMenuIsOpen);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const EuiPinnableListGroup: FunctionComponent<EuiPinnableListGroupProps>
);

// Add the pinning action unless the item has it's own extra action
if (onPinClick && !itemProps.extraAction && pinnable) {
if (pinnable && !itemProps.extraAction) {
// Different displays for pinned vs unpinned
if (pinned) {
itemProps.extraAction = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/markdown_editor/markdown_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export const EuiMarkdownEditor = forwardRef<
const parsed = parser.processSync(value);
return [parsed, null];
} catch (e) {
return [null, e];
return [null, e as EuiMarkdownParseError];
}
}, [parser, value]);

Expand Down
11 changes: 5 additions & 6 deletions src/components/overlay_mask/overlay_mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,18 @@ export const EuiOverlayMask: FunctionComponent<EuiOverlayMaskProps> = ({
}, [className, headerZindexLocation]);

useEffect(() => {
if (!overlayMaskNode.current || !onClick) return;
const portalTarget = overlayMaskNode.current;
if (!portalTarget || !onClick) return;

const listener = (e: Event) => {
if (e.target === overlayMaskNode.current) {
if (e.target === portalTarget) {
onClick();
}
};
overlayMaskNode.current.addEventListener('click', listener);
portalTarget.addEventListener('click', listener);

return () => {
if (portalTarget && onClick) {
portalTarget.removeEventListener('click', listener);
}
portalTarget.removeEventListener('click', listener);
};
}, [onClick]);

Expand Down
3 changes: 2 additions & 1 deletion src/components/search_bar/query/default_syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ const validateFieldValue = (
try {
schemaField.validate(value);
} catch (e) {
const message = e instanceof Error ? e.message : e;
error(
`Invalid value \`${expression}\` set for field \`${field}\` - ${e.message}`,
`Invalid value \`${expression}\` set for field \`${field}\` - ${message}`,
location
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export class EuiSearchBar extends Component<EuiSearchBarProps, State> {
this.notifyControllingParent({ query, queryText, error: null });
this.setState({ query, queryText, error: null });
} catch (e) {
const error: Error = { name: e.name, message: e.message };
const error: Error =
e instanceof Error
? { name: e.name, message: e.message }
: { name: 'Unexpected error', message: String(e) };
Comment on lines +172 to +175

@cee-chen cee-chen Feb 2, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Obligatory https://stackoverflow.com/a/68257472/4294462: In TS 4.4+ caught errors default to unknown instead of any. We could disable this via useUnknownInCatchVariables in tsconfig.json, but honestly I think it's a legit change and it's worth checking for a valid Error instance since something like throw 'foo' is an allowed error. LMK if you have other thoughts however!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe check for 'message' in e - possibly with a type guard to catch some non-error-but-still-compatible objects?

@cee-chen cee-chen Feb 2, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm, I'd be more tempted to JSON.stringify() a custom error object with a message key - that way the user can always get the full error no matter what. This seems like it might be worth DRYing out a helper that checks for instanceof Error and tries to return a valid Error type if not. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably too engineery at that point, and leaving as-is makes more sense? 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair enough! We can keep it in our back pockets for later if we add more try/catches

this.notifyControllingParent({ query: null, queryText, error });
this.setState({ queryText, error });
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/suggest/suggest_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const EuiSuggestItem: FunctionComponent<EuiSuggestItemProps> = ({
<button
onClick={onClick}
className={classes}
{...(rest as PropsForButton)}
{...(rest as Omit<PropsForButton, 'onClick' | 'className'>)}
>
{innerContent}
</button>
Expand Down
Loading