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

Fix/address left config typing issues #27

Merged
merged 10 commits into from
Jan 12, 2021

Conversation

casaper
Copy link
Collaborator

@casaper casaper commented Nov 22, 2020

  • Add @type definitions for svg2ttf and ttf2woff2
  • fix generator woff2 to use ttf2woff2 according to type definition
  • remove these two declarations in "src/types/modules" and add the rest that are still there to the tsconfig.json
  • replace custom type declarations with @types packages for ttf2eot, ttf2woff and svgicons2svgfont
  • simplify RunnerOptions to one interface optional properties instead of merging another type with required properties as Optional properties... the concept was just a bit complicated, when typescript actually does optional properties on an interface so well 😉

@casaper casaper force-pushed the fix/address-left-config-typing-issues branch from eedda71 to 502b218 Compare November 22, 2020 19:02
@casaper casaper requested a review from tancredi November 22, 2020 19:15
@casaper
Copy link
Collaborator Author

casaper commented Nov 24, 2020

@tancredi

The @types packages were now all merged and the packeges released, so I could now include them as packages. This one is now definitly ready for review

Copy link
Owner

@tancredi tancredi left a comment

Choose a reason for hiding this comment

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

Thank you so much for taking the time to get these typings published 🙏 looks good, just a couple comments (I think the type changes to Partial is the most important)

src/constants.ts Outdated
import { FontAssetType, OtherAssetType } from './types/misc';

export const TEMPLATES_DIR = resolve(__dirname, '../templates');

export const DEFAULT_OPTIONS: RunnerOptionalOptions = {
export const DEFAULT_OPTIONS: Partial<RunnerOptions> = {
Copy link
Owner

Choose a reason for hiding this comment

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

The reason I had split the optional options was to ensure that as they grew or changed this const definition would break if any of these default options was missing. This looks cleaner, but is less safe (as I could just comment out for example name from defaults)

The Options are not nullable / can't be undefined when they get to the generator, optional just means they come from default values rather than necessarily user input.

Hence Partial doesn't quite serve the same purpose here. Make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It frankly is a bit too far back in time. I don't remember what my reasons were here, and I currently do not have the time to dig into this problem. Perhaps in a week or two.

Copy link
Collaborator Author

@casaper casaper Dec 22, 2020

Choose a reason for hiding this comment

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

I replaced the partial with an Omit now: e47c2ac

export const DEFAULT_OPTIONS: Omit<RunnerOptions, 'inputDir' | 'outputDir'> = {

Would it be OK for you like that @tancredi ?

Copy link
Owner

Choose a reason for hiding this comment

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

Lots of good work in this PR just wished this was a separate PR as it was a bit off scope here and made it difficult more me to review / merge (sorry for taking lots of time) as I care about keeping option types very very explicit and controllable - reverted just this and made a few additions here and there :)

(({
formatOptions: { [FontAssetType.WOFF2]: woffOptions }
} as unknown) as FontGeneratorOptions);
(({} as unknown) as FontGeneratorOptions);
Copy link
Owner

Choose a reason for hiding this comment

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

Why are we removing the woff options mock from tests? They check that the generator options are correctly passed to the font generator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hello @tancredi

Fiddling in these @types/ definitions I discovered that ttf2woff2 does not have such options. For unknown rason it used to work, but anyhow, the lib will not process and do anything with it. So I removed the options from the font options type, and this spec conflicted with that fix. It expected the non-existent font option to be passable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tancredi

Yes, I verified that now. It is definiteley because I found out taht ttf2woff2 simply does not have any such second param.

See:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ttf2woff2/index.d.ts#L8

And in TTF2WOFF2 itself:

https://github.com/nfroidure/ttf2woff2/blob/master/jssrc/index.js#L5

No second param there...

Copy link
Owner

Choose a reason for hiding this comment

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

That's great to know! I've removed some other unnecessary format options from the types! cheers

…itions

and add the rest of the declarations to the tsconfig
And the metadata will be inherited from the ttf anyhow
- no more joins of multiple times and duplicates
- the optional properties are real type script optional properties
- the templates object allows only template paths for actually possible
  templateable formats
Replacing the custom declarations for external packages with fresh @types:
- @types/svgicons2svgfont
- @types/ttf2eot
- @types/ttf2woff
@casaper casaper force-pushed the fix/address-left-config-typing-issues branch from 59d58a7 to e0e692a Compare December 22, 2020 10:19
@tancredi tancredi merged commit a4fbc04 into master Jan 12, 2021
@tancredi tancredi deleted the fix/address-left-config-typing-issues branch January 12, 2021 20:22
@github-actions
Copy link

🎉 This PR is included in version 1.0.31 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants