Skip to content

Conversation

antonioconselheiro
Copy link
Contributor

@antonioconselheiro antonioconselheiro commented May 22, 2025

'Decode' function is not returning specific type for specific parameters signature.
In this request I'm including alternative specific signatures if the first generic signature fails, this will solve complexity of extra validation after decoding or forcing cast using 'as' keyword.

To validate this implementation I have remove the keyword 'as' for cast into unit tests, so the unit tests validates the returning type also. 'As' keyword will force the return to the type dev wish, but if the parameter change it'll keep returning the forced type and will show no type error.

Currently (one signature, multiple return):
image

With the changes of this pull request (fixed):
image

@antonioconselheiro antonioconselheiro changed the title Typescript type inference for 'decode' function for nip19 is not working fully Typescript type inference for 'decode' function in nip19 is not working fully May 22, 2025
@fiatjaf
Copy link
Collaborator

fiatjaf commented May 22, 2025

Good evening, @antonioconselheiro.

@antonioconselheiro
Copy link
Contributor Author

Good morning from here,
God bless you fiatjaf

@fiatjaf
Copy link
Collaborator

fiatjaf commented May 22, 2025

Your PRs always make me want to switch to raw JavaScript.

@antonioconselheiro
Copy link
Contributor Author

antonioconselheiro commented May 22, 2025

I worked in large systems with raw JavaScript, TypeScript types helped me sleep better.

@fiatjaf fiatjaf merged commit 9132b72 into nbd-wtf:master Jun 1, 2025
0 of 2 checks passed
@antonioconselheiro antonioconselheiro deleted the improve-decode-function-signature branch June 3, 2025 11:53
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