Skip to content

Typing Promise returning function with Result #430

Answered by chriskrycho
kee-oth asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @kee-oth, thanks for the ask. You will need to provide the type for the initial parameter somehow—this isn’t a True Myth limitation but a TypeScript limitation. Unlike languages like F♯, OCaml, Elm, Haskell, etc., TypeScript does not do Hindley-Milner inference or any other kind of full program inference; any function parameter which is not explicitly typed in some way is implicitly typed as any. (I say “in some way” because callbacks can get their types from the context where they’re used, but the definition of the site they are passed to has to be typed well for that to work.) The best thing you can do is something like your final version or simply providing the type explicitly inline.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@franklin-huang
Comment options

@franklin-huang
Comment options

@chriskrycho
Comment options

@franklin-huang
Comment options

Answer selected by chriskrycho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #427 on September 05, 2022 18:14.