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

Customizations for typescript #546

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

ThornWalli
Copy link
Contributor

@MrTelanie I have now started testing the PR with the factory adjustment.

So far I can only do this in an external project, because build is required.

This is one point, others will certainly follow ;)

Argument 🤪 is missing when using the calc method

image

The idea is to solve this with an undefined on Result.

There is a lot of any. Could the calc not have a vector as result?

Copy link

pkg-pr-new bot commented Mar 9, 2025

Open in Stackblitz

npm i https://pkg.pr.new/basics/vector/@js-basics/vector@546

commit: ebee175

Copy link

sonarqubecloud bot commented Mar 9, 2025

@ThornWalli
Copy link
Contributor Author

ThornWalli commented Mar 9, 2025

@MrTelanie
How should you proceed with Calc?

Fixed return value, whereby it is then undetermined whether Victor or Vector.

When executing, there are different objects in any case, so you would have to use a generic?

This then returns a number 🙃
Is it because of the argument arg?

image

/**
 *
 * @template T
 * @param {() => T} alg
 * @param {T | (() => T)} [result]
 * @returns {T}
 */
export function operatorCalc<T>(alg: () => T, result?: T | (() => T)): T;

image

Victor + Vector = Vector

@MrTelanie
Copy link
Member

@ThornWalli
if you need more specific types, take a look at jsdoc
like i did here
#545

@MrTelanie
Copy link
Member

@ThornWalli

const vectorResult = calc(() => victorA + vectorA);

for ts the function looks like this in best case () => number
ts does not know what gets calculated here

i think in my impl the first type is used so victor + vector = victor and vector + victor = vector

thats why i think in ts you cant work with calc any more directly
you should switch to factory functions

const vectorResult = victor(() => victorA + vectorA);

@MrTelanie MrTelanie merged commit 4c54924 into feature/factory-types Mar 11, 2025
8 checks passed
@MrTelanie MrTelanie deleted the feature/fix-missing-arguments branch March 11, 2025 07:57
Copy link

🎉 This PR is included in version 2.2.0 🎉

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants