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

Typestrict #89

Merged
merged 6 commits into from
Jul 12, 2024
Merged

Typestrict #89

merged 6 commits into from
Jul 12, 2024

Conversation

jho406
Copy link
Collaborator

@jho406 jho406 commented Jul 8, 2024

This enables strict in tsconfig.json, and we fix those up!

@jho406 jho406 force-pushed the typestrict branch 5 times, most recently from 782707c to 8132aef Compare July 8, 2024 03:24
Comment on lines -68 to -70
err.fetchArgs = fetchArgs
err.url = fetchArgs[0]
err.pageKey = urlToPageKey(fetchArgs[0])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're removing this as all are accessible through the developer's application_visit.js

Comment on lines +180 to +182
const hasPlaceholder = !!(
placeholderKey && getState().pages[placeholderKey]
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Typescript detected an edgecase where placeholder could be undefined.

Comment on lines +58 to +59
pageKey: key, //TODO remove this
savedAt: Date.now()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added to keep parity with what we have today, though I need to move pageKey in another PR as it is superfluous. savedAt was added because that is what a page would contain.

@@ -198,7 +207,7 @@ export abstract class ApplicationBase extends React.Component<Props> {
}

abstract buildStore(
initialState: RootState,
initialState: {pages: AllPages, [key: string]: JSONValue},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When building a store, superglue takes the injected visit response, transforms it to a page and passes it to buildstore. At that point the superglue key hasn't been built, so we swap root state for something a bit more flex

Comment on lines +14 to +22
if (
!(
action instanceof Object &&
'type' in action &&
typeof action.type === 'string'
)
) {
return nextAction
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Typescript detected non standard action types, so we narrow the types here. If the shape doesn't match, just return the action


export type DefermentThunk = ThunkAction<
Promise<void[]>,
RootState,
never,
undefined,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also fixed a typescript err

const isSearchable = /^[\da-zA-Z\-_=.]+$/
import { JSONMappable, JSONValue } from '../types'

const canLookAhead = /^[\da-zA-Z\-_]+=[\da-zA-Z\-_]+$/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This changed the regex to testing for any combination of abcABC123-= to
abcABC123-
=abcABC123-_. In otherwords, it tests for things like foobar=some123id

Comment on lines +25 to +27
throw new KeyPathError(
`Expected to find an Array when using the key: ${key}`
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You may noticed that I've now hoisted the error throwing from getKey to further up the stack. This made it easier to type atKey and getKey.

@@ -106,7 +110,7 @@ export class HandlerBuilder {
linkOrForm: HTMLAnchorElement | HTMLFormElement,
url: string,
opts: VisitProps | RemoteProps
): Promise<Meta> {
): Promise<Meta> | undefined {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Undefined is possible. Thanks typescript

Comment on lines -80 to -83
// This needs to be done better. This is saying to
// remove the content-type header from UJS form
// submissions.
const fromUJSForm = headers['content-type'] === null
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found a better way to todo this. If the body is FormData, we just remove the content-type header. This also changes the tests down below where you'll see removal of the header

@jho406 jho406 marked this pull request as ready for review July 8, 2024 12:43
@jho406 jho406 merged commit 400c9ae into main Jul 12, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant