-
Notifications
You must be signed in to change notification settings - Fork 3
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: keep id if it exists #100
fix: keep id if it exists #100
Conversation
Codecov Report
@@ Coverage Diff @@
## master #100 +/- ##
=======================================
Coverage 93.65% 93.65%
=======================================
Files 6 6
Lines 126 126
Branches 29 26 -3
=======================================
Hits 118 118
Misses 8 8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@targos could you help me to find the best way to check if an optional property exists and return it without converting this to optional |
it is related with the discussion in https://github.com/cheminfo/nmr-processing/issues/205 |
I tried a few ways to do it with a generic type but failed. Maybe it's possible but I don't know. The problem with this implementation is that there is no check inside the implementation that the id is added in the right case (and having to define overloads for it is annoying). /cc @stropitek Maybe you have an idea? Basically we want a function that accepts some type, possibly with an id inside. If there's an id, the return value contains an id as well, otherwise it doesn't. This playground show the idea (maybe it's a red herring and there's a completely different way to do it), but I don't know how to implement the body of the function: https://www.typescriptlang.org/play?#code/C4TwDgpgBAyg9gWwgFXNAvFA3gDwFxQB2ArggEYQBOAvgFCiRQDywAFlao5liASeVToAzYoQDGwAJZxCUYBADOwADzIoEHPMIATBbEQo0APgAUANwCGAG2IQCyAJT31miDr1Yok7QSWVJhADmUNRQAPzMbBxoUABk2N6+wP5BoQQs7JSc0Fi0UPlQlBDAxJSyuQWVULxQljYQAHQ4ADR5BdQA3LR0tJaUhYoAjFCY8komuASD1A60RQqDDSBzQw3etL0W-fMATCNyisAT+FCDzV4+UADkY8BXMysKO0uPz+tAA |
I've played around with the examples and I could not come up with a solution that circumvents the limitations @targos mentioned. |
I got a possible solution that avoid overloads, is it ok? |
src/index.ts
Outdated
@@ -35,6 +36,10 @@ export interface OptimizedPeak { | |||
shape: Shape1D; | |||
} | |||
|
|||
type PeakWithIDOrNot<T extends Peak> = T extends { id: string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you extend Peak
and not OptimizedPeak
?
Also why call it PeakWithIDOrNot
rather than OptimizedPeakWithIDOrNot
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There T is the type of input data, that is why I'm using Peak
.
@targos This approach is what you expect ? |
@stropitek PTAL |
9b815d2
to
f2d6494
Compare
Published prerelease version To install it, run: npm install ml-spectra-fitting@4.1.0-pre.1661357854 |
close: #99