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

Add global type defs #37

Merged
merged 3 commits into from
Aug 30, 2021
Merged

Add global type defs #37

merged 3 commits into from
Aug 30, 2021

Conversation

robwierzbowski
Copy link

@robwierzbowski robwierzbowski commented Aug 30, 2021

Problem

Although the JS package isn't written in TS, it's a pain for TS apps to add a module declaration file when they need to use it. The types also need to be exposed through packages like ER that are in TS, and are consumed by TS apps.

Solution

Expose a global TS module def. Check in a TS aware application that this works as expected when importing Log Weasel directly.

image

TODO

After merge:

  • Publish
  • make sure this also works as expected when importing ER into a TS application.

Copy link

@benmvp benmvp left a comment

Choose a reason for hiding this comment

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

Left some small, non-blocking suggestions about updating the comments. Otherwise, this looks great. Thanks for taking the time to do this!

I know both home-ui & shop-collections-ui had to add the dummy module, so it'd be good to socialize this with @brandon-vaughan & @halloffame

@@ -1,6 +1,8 @@
import { ulid } from 'ulid';
import { constantCase } from 'constant-case';

// Keep the type signature of this function in sync with the types exposed in
// index.d.ts
Copy link

Choose a reason for hiding this comment

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

this is actually now in generateId.d.ts. i would also add a companion comment in generateId.d.ts to mention that it has to be kept in sync w/ the source file

Copy link
Author

Choose a reason for hiding this comment

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

Yep! Done.

@@ -1,6 +1,8 @@
import { ulid } from 'ulid';
import { constantCase } from 'constant-case';

// Keep the type signature of this function in sync with the types exposed in
// index.d.ts
const generateId = (key) => {
if (typeof key === 'undefined') {
Copy link

Choose a reason for hiding this comment

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

the nice thing is that a TS app now won't let the key be undefined thanks to these type definitions.

@robwierzbowski robwierzbowski requested a review from benmvp August 30, 2021 19:37
@robwierzbowski robwierzbowski merged commit b1375b9 into master Aug 30, 2021
@robwierzbowski robwierzbowski deleted the KFE-438 branch August 30, 2021 19:50
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.

2 participants