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: keep id if it exists #100

Merged
merged 5 commits into from
Aug 26, 2022

Conversation

jobo322
Copy link
Member

@jobo322 jobo322 commented Aug 16, 2022

close: #99

@jobo322 jobo322 linked an issue Aug 16, 2022 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #100 (9b815d2) into master (6a25647) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 9b815d2 differs from pull request most recent head f2d6494. Consider uploading reports for the commit f2d6494 to get more accurate results

@@           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           
Impacted Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)
src/util/internalPeaks/getInternalPeaks.ts 85.71% <100.00%> (-0.83%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jobo322
Copy link
Member Author

jobo322 commented Aug 16, 2022

@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

@jobo322
Copy link
Member Author

jobo322 commented Aug 16, 2022

it is related with the discussion in https://github.com/cheminfo/nmr-processing/issues/205

@targos
Copy link
Member

targos commented Aug 17, 2022

I tried a few ways to do it with a generic type but failed. Maybe it's possible but I don't know.

Here's the best I could come up with: https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABDAzgQQE4YIYE8DqMUAFgJIAmAFNlngFyJwBGAVgKbQDaAugJQM0cuZCkQBlKBhhgA5hR6IA3gChEaxBjZQQGJAHIY5PciSC8nAAzcA3MoC+y5aEiwEiYthQVKAN2wAbEDYGZnZofkQ-QLYRcUlpOXIlVXVNbV1EAyMTSICg2wdlKFwABxiJKVkKRABeJWRyBhR42UQHYrLEQhIKAB4AFQA+WsR+xAAyOMrEotKYgFk8JjZusnIB4bqxgB8uojWNx2koNgxgbAgYgGE4OAxyURV1RAAPBjAQAFtljFtn3HeXx+BUczmg8CQ5DgICY-jYNzuD18eWCiAR9xQEXRD1sYNckOhsPhtwxyOiDFWfWxKEGEUp62pg1x4HBbihMLh1LJQQYi1wy3pvUZET5Av2VJJD0GT3UMGAiEoHi8VCiQV4vGSz2eaR0SBlWq1hgYqrYADpDAAaFIG55vXLRU0vRAAKkQACYrTatQD7UFTcJXR7rVqHM87Ig2P4UDF9VqdRlY167SbHS73Z6veofSmA+ng2Hgw5Cn4MBo2CgAIwjdlErmKBoMPQnZp6C2vBgVts+t1tXi2TSV83kZQDiuO2zKEtllA9uo1zmSlCURR2zuIbt2Xgj8tuofbmeO5RAA

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

@stropitek
Copy link
Member

I've played around with the examples and I could not come up with a solution that circumvents the limitations @targos mentioned.

@jobo322
Copy link
Member Author

jobo322 commented Aug 17, 2022

I got a possible solution that avoid overloads, is it ok?

@targos targos requested a review from stropitek August 17, 2022 15:21
src/index.ts Outdated
@@ -35,6 +36,10 @@ export interface OptimizedPeak {
shape: Shape1D;
}

type PeakWithIDOrNot<T extends Peak> = T extends { id: string }
Copy link
Member

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 ?

Copy link
Member Author

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.

@lpatiny
Copy link
Member

lpatiny commented Aug 18, 2022

@targos This approach is what you expect ?

@targos
Copy link
Member

targos commented Aug 19, 2022

@stropitek PTAL

@jobo322 jobo322 self-assigned this Aug 24, 2022
@mljs-bot
Copy link
Contributor

Published prerelease version 4.1.0-pre.1661357854 to npm.

To install it, run:

npm install ml-spectra-fitting@4.1.0-pre.1661357854

@jobo322 jobo322 merged commit be15d31 into master Aug 26, 2022
@jobo322 jobo322 deleted the 99-keep-id-property-if-exists-in-the-input-peaks branch August 26, 2022 16:27
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.

keep id property if exists in the input peaks
5 participants