-
Notifications
You must be signed in to change notification settings - Fork 204
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
Replace instanceof checks with other type check #740
Comments
https://github.com/algorand/js-algorand-sdk/blob/develop/src/composer.ts#L343 in fact we already have a check for TransactionWithSigner |
Hi @algoanne @barnjamin |
yes @shubhamshd, contributions are welcome here! |
Hello @algoanne @jasonpaulos. Wanted to supply some more detailed context for a similar edge case resulting in identical issue due to use of js-algorand-sdk/src/transaction.ts Line 1376 in 4e1073d
@joe-p initially reported the bug to us when playing with AlgoKit appclients generated by algokit-client-generator-ts on a React project that uses vite. AlgoKit TS AppClients are inspired by Why it fails on
|
Hi @aorumbayev, thank you for that information! Before making a decision on
Asking because I'm first trying to understand how there can be two different |
I can't recall the exact details but I know this also happened prior to A solution that seemed to work for packages that required I think an improved type check could (?) help here since it'd look at the fields on the object which should (?) be version independent |
Hello @jasonpaulos and thanks for extra context @barnjamin ;) To be specific the bug in @joe-p 's report occured for a vite based project with dependency scenario 1 (so it's option 1 in your follow up): graph TB
subgraph Scenario1
B[User's vite based project]
C[algorandfoundation/algokit-utils]
D[algosdk]
B --> C
B --> D
end
Here is an easily reproducible live sandbox where you can observe the error yourself: CodeSandbox Steps to replicate:
As I mentioned in the previous message the reason why we suspect that its highly likely caused by vite dev mode itself is due to the fact that if you then navigate to I also tried option 2 from your message, you can also easily replicate that by removing project level algosdk and reinstalling via npm install. That way the problem still persists because vite will still grab the Additionally, as @barnjamin outlined, this was also the case for similar scenarios prior to algokit utils so I am pretty sure this can be reproduced on vite dev mode for any scenario 1,2 (where you have root project with algosdk + As discussed during the call, using peerDependencies is not fixing the issue. We will have an item on backlog and turn algosdk into a peer dependency in a separate work thread regardless though |
Hey @jasonpaulos just checking on the current state for this item, from algokit side we can both bump the algosdk version and make it a peer dep within the same pr whenever this is addressed on the algosdk side. Feel free to ping us whenever there is a pr opened for this, can aid with running algosdk from a pr branch to confirm whether |
To confirm, I believe the main problem is the instanceof checks used on the If so, let me give some background on the We are actively working on a v3 release, and it's possible we could change this behavior in that release. Specifically, we could make it so that these functions would only accept Would this be an acceptable solution? From a development perspective, it would be much preferred to remove the need for this check entirely instead of trying to retrofit the existing v2 code to perform the check without |
@jasonpaulos thanks for the response, and I agree that sounds like it will solve the main edge case we hit with vite. Regardless though we have found a solution and fixed it on utils ts side so it's no longer an issue on the algokit side. Presumably once your proposed solution is in place any similar edge cases on non algokit projects with similar setup are going to be fixed 👍 |
Problem
when a different version of the algosdk is used from another dependency, the instanceof checks fail and result in confusing error messages.
Instead we should find another way to do the type check like https://www.typescriptlang.org/docs/handbook/2/typeof-types.html#the-typeof-type-operator
The text was updated successfully, but these errors were encountered: