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

chore(gatsby): Migrate utils/get-public-path.js to ts #22093

Merged
merged 2 commits into from
Mar 9, 2020

Conversation

cola119
Copy link
Contributor

@cola119 cola119 commented Mar 9, 2020

Description

Convert utils/get-public-path to typescript

Documentation

Related Issues

Related to #21995

Copy link
Contributor

@blainekasten blainekasten left a comment

Choose a reason for hiding this comment

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

This looks great, but since we are changing the export signature there are a handful of files that will need to have their require statement updated. Do a grok of the codebase for require(get-public-path) and you'll find a bunch of references that now need to destructure the named export

if (prefixPaths && (assetPrefix || pathPrefix)) {
const normalized = [assetPrefix, pathPrefix]
.filter(part => part && part.length > 0)
.filter((part): part is string => (part ? part.length > 0 : false))
Copy link
Contributor

Choose a reason for hiding this comment

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

part is string is this valid syntax? Why not just part: string I think this line is wrong. I think you want (part: string): boolean => ..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

part is string is valid syntax called type predicate officially. As far as I know, TS cannot infer types exactly inside Array.prototype.reduce() so if it is (part: string): boolean => .. the compiler infers part in the next map as string | undefined
example

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL! V cool, thanks!

@cola119
Copy link
Contributor Author

cola119 commented Mar 9, 2020

since we are changing the export signature there are a handful of files that will need to have their require statement updated

Sorry I missed it. I will fix that right away.

Copy link
Contributor

@blainekasten blainekasten left a comment

Choose a reason for hiding this comment

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

looks great! Thanks!!

@blainekasten blainekasten added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Mar 9, 2020
@gatsbybot gatsbybot merged commit fe04b8e into master Mar 9, 2020
@delete-merged-branch delete-merged-branch bot deleted the chore/ts/get_public_path branch March 9, 2020 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants