-
Notifications
You must be signed in to change notification settings - Fork 10
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
ESLintify the library and its examples, enable linting in CI #112
Conversation
examples/index.js
Outdated
@@ -1,3 +1,5 @@ | |||
/* eslint-disable no-unused-vars, react/jsx-no-undef, react/prop-types*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn't part of a project but a repertoire of snippets exploring how Rollbar may be used.
So, these checks are bothersome, and the snippets are more explanatory if they look "as if" they were part of an actual larger project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may end up adding this as a file comment, actually.
index.d.ts
Outdated
@@ -26,7 +26,7 @@ export interface ErrorBoundaryProps { | |||
errorMessage?: string | (() => string) | |||
extra?: Extra | ((error: Error, errorInfo: ErrorInfo) => Extra) | |||
level?: LEVEL | (() => LEVEL) | |||
callback?: Callback<any> | |||
callback?: Callback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When omitting the type parameter, it defaults to any
already.
render(ui, { | ||
wrapper: (props: { children?: ReactNode }) => ( | ||
<Provider {...{ children: props.children ?? <></> }} {...providerProps} /> | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was a fun type-structure puzzle.
So, Provider
expects a ProviderProps
-type-like structure which is defined like so:
export interface ProviderProps {
Rollbar?: new (options: Configuration) => Rollbar
children: ReactNode
config?: Configuration | (() => Configuration)
instance?: Rollbar
}
The solution is two-fold.
First
We need to acknowledge that we're providing the expected type structure through two arguments, props
supplies the only required prop children
, and providerProps
supplies the rest of the props which are all optional.
Second
This is one is a bit harder to explain. The function render
is loosely declared as: render(_, RenderOptions)
, we only care about the second argument RenderOptions
which has a bunch of props and a wrapper?: React.ComponentType
which is in turn, the one we care about.
ComponentType is defined as:
type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
Since we're passing a function (props) => ...
, we are matching FunctionComponent
's structure which has a bunch of props and the main one, the function, which is defined as:
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
...
}
So, the props we get here: (props) => <Provider {...props} {...providerProps} />,
is of type PropsWithChildren
which is defined:
type PropsWithChildren<P> = P & { children?: ReactNode | undefined };
And therein lies the second problem. The children
prop is optional, but ProviderProps
requires it. So, we solve this by creating a new object that matches the structure in ProviderProps
, and we either pass props.children
if there's something in it, or an empty node.
And voila, all types check!
Fun for the whole family.
A note on P
: Given there's no type parameter defined in wrapper?: React.ComponentType
, we know for a fact that that P = {}
, therefore props
is effectively of type { children?: ReactNode }
.
1a2d280
to
efe4580
Compare
Most changes come from the updated
package-lock.json
in the nextjs example project.Description of the change
This is the ESLint portion of the prettier/eslint + ci effort. All warnings and errors have been addressed.
Explanatory comments in file changes.
Type of change
Checklists
Development
Code review