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 generic option type #768

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

HansAarneLiblik
Copy link

What issue does this pull request resolve?
#704

What changes did you make?
Add generic Option through out the codebase

Is there anything that requires more attention while reviewing?

@HansAarneLiblik HansAarneLiblik force-pushed the add-generic-option-type branch from 53a0c70 to 4ece5e0 Compare March 16, 2023 15:55
@HansAarneLiblik
Copy link
Author

How can I build this and use it in my own project to test out that it actually works? 😆

@HansAarneLiblik HansAarneLiblik marked this pull request as ready for review March 16, 2023 16:27
@HansAarneLiblik HansAarneLiblik force-pushed the add-generic-option-type branch from e9d6650 to 700abf2 Compare May 19, 2023 09:38
@HansAarneLiblik
Copy link
Author

@ericgio Can you guide me, on how can I build this (With types), so I can test it out on my own project?

@ericgio
Copy link
Owner

ericgio commented May 25, 2023

Hey @HansAarneLiblik you can run yarn build:types in the project root to build all the types, or just yarn build to build everything.

@ericgio
Copy link
Owner

ericgio commented May 25, 2023

Looking through your changes, you seem to be taking the approach that was somewhat discouraged on the issue thread, ie: propagating the option type throughout the whole codebase. While this technically correct, the concern raised on the thread is that it would add a lot of overhead to the maintenance of the project. I wonder if there's a lighter-weight approach, maybe something essentially like what DefinitelyTyped was doing where just the public interface is typed using the generic? 🤷

@HansAarneLiblik
Copy link
Author

HansAarneLiblik commented May 25, 2023

Sure, I'll take a look at DT, to see if that can instead be used... Don't know if types of that kind can be applied here or need to be a separate types package.

Regarding building - it didn't add types to the build folder together with dist. Need to take another look at it

@HansAarneLiblik
Copy link
Author

Going forward with the DT way, won't that overwrite the types you've already defined here? Or will it just extend the current types?

@ericgio
Copy link
Owner

ericgio commented Jul 20, 2023

Going forward with the DT way, won't that overwrite the types you've already defined here? Or will it just extend the current types?

I think the idea would be to define a new public interface only. I'm not 100% sure on the implementation, but what I'm thinking of is something like

declare module 'react-bootstrap-typeahead' {
  export interface TypeaheadComponent<O> {
    labelKey: string | (option: O) => string;

    // Re-define public interface that relies on option type here.
  }
}

I would test this out by adding a similar declaration to a project that uses this library.

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