very huge typescript question

playground link: https://www.typescriptlang.org/play?#code/PTAEBcE8AcFMHMCuBDATgEwM4ChYA9oB7VcUAY0IDtNSBLTAeQCMArWM0gXlAAoA3ZABtEsAFyhElANaVCAd0oBKcQOGxQ9UIVbsuAPmygIMWIQBmoVSNCdboAETa2He6ABkby0OsBCO5URBQQBubFwCYlIKajpMADFJDloqG14rMQlpWQVlLzUNTFAEyiSUzgMjKDhzPOtbbnszRPBkyntQ8KISYzhQBikAHgAVPVSAbx6Mxyl22oyh0ABfUPwu0ir1AFFUVAHN0e4JjfF7WB3Z9PFNpY7VyMnQACVYTEDwYYAaUH3U-uHRgA+3x2ez0twi3SaJRaKUIgyGX32-G881yz1egneCO+ozGhlAqFg4EQqEooCOJhOcPsX3SN2wizCd0hzVaoDOu2xSMu3zRLzenxx5PxhOJpPJkxOHJpc3pjM69yhpTJ9HRAq5emRanEkhk8iUKhRBSe-Mxgp+eKMopJZJ4+KM9GYznAWpEincbntkxqrvUyEKFLgAH5xDRULRKPAlooAHQbGx2exhiPwVweL0AbWmMtO5wAujGI2RhOgXjxfaB-RLjqBk5Ho3GTIp8YpQvLmaQlTCVYx4YjNYSMeBxGqzRrcoO3sa-iNhVaiTaCabwI3evUHNS20yIZ3WSl6NtOf2eJPMSPl+a9BPl8bD6C50uxWTTyv4+vc6h2gzt2tQF22WYqCEAAtgAcoEgjIEwgiwJedpGDyCxAgEQSgECkilmYEawOgHz4hyxDiKBVDgUEUEwaC2B8kOAzEZQpGQdBsEjP2Kw7n+e5koBIEMeRzHHvhOyEaAdG8UxlG5L64hIaAKGCGhmSYdh6DuuUJo0aJEF8f8rEKiy0IAUBYFaeJGrwXMDCoIewkyXJCkYbAWGUDhCmaWR4n7HhRgEagIYiSRJkUfsVGiPiQKju8bmMRRLE4mFvBSaAtkQfZlBKc5Kk2KMEW0QF7kxXo-bupaGgWDwPkJtwdkAkCFXrg5Tk4cVXrWuKiXJah6FpY5ymqRURgDdxxn5bAvq0iilnWaglaFFF2n7K2+Lyg6ZXpJNQnTeu1VAmtVkbZVik9RlzUDY+i4cuVG2LUYy1neKcK+utQHTVWc2mVeW56buBkpJIcioMg0CWXBL7njRGpfJhyBvAAaii0m5EMbG-v+v2UP9gPA2ZUOw-DSWSaD6nqkVWVJcjiqcZkGNA0eOLmS+lkACKOdDmJw9qRNjv2CkIviONsyiflDCFSUKeWhM5eOpNDCdpW8Kqy4nsuTMs7jaiKLLRjRDQS5DqkDOoMzZis+A7MiB0p2tT2-RK0O7pBrrbwxnS4j86bKI+KEN3soImDqCVWtUDrbtm+o3AG0bJuhxbA1W7wL59fLva2289uO5iztGq7qsC+rXtLN+X0cT9XGQeAACygPml8ACqmoisuYPEziXl-pQ4jtYnOU1-2Ivd7pHbF8qf5l5X0DV6AdfmWY7dpHjMuk-3cUE43nNYiTalL-s5P6cPZij1XXK1-X85DpZcSz5L3NAuWiFdxePc4oorcz35neLw-vfUQKj8-DfKdnjXpee+NFf5XgfLQMq9BijKgAeAc+ShNbkCDqQYCgML762VqgC+Md5xPnjsuRO+9kAV0BnAr4aDoAX2uksH2fsHyBxiOnLgzCEG4LljwBWQ44EawYbHBc4pHRSB4V6U6DsZ4+DgZndWoiBodxfDNTIeoFCKK3h9L0iw6H+1kXHF8+cbpLULtgbWpBBypCGmJGCPAACMXwPzEHsItEAp0AB6QYwgmNANAICTFgLmIPtAW2XweBKFJmSdcAAGUADsLr2DIMgSgAByUg6BaB8FoKWUATBICgAiY48QD1rERKiWARBoRnGuPcc48AAALTQmhdTZDJKIHgQA
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
20 Replies
nexxel
nexxelOP2y ago
basically im trying to implement a result monad, it has two types, Ok and Err and helper functions to work with it in here i have a flatMap function which maps a Result of Ok type. If the Result is of Err type, leaves it untouched. The map function must return a Result
Brendonovich
Brendonovich2y ago
mm yum so big and huge
nexxel
nexxelOP2y ago
yes but the problem is that for some reason in the example i sent its inferring the Ok type as unknown its working in the compiled js, just have type errors which im not sure where im going wrong would love some help
Brendonovich
Brendonovich2y ago
it's gotta be this part, idk if you noticed it
Brendonovich
Brendonovich2y ago
it's tricky since T doesn't have anything constraining it
Brendonovich
Brendonovich2y ago
but ig u could say the same for errors aye
nexxel
nexxelOP2y ago
yeah it is but like idk what to change to fix it cause errors will always be like that and they are getting inferred correctly
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Brendonovich
Brendonovich2y ago
that's only being returned for the err tho, not the ok
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP2y ago
fromNullable just takes a value and turns it into a Result of Ok type and Err if its either null or undefined will look at the codesandbox now so i guess the only easy way to do this is return a union of Ok and Err? i def don't want unions because in the future i have to make a match function which would be very hard to do on a union (i think) actually now that i think about it thinkspin it could work
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP2y ago
match would take two functions, one would be the function that will run if the result is Ok(x), the other one will run if the result is an Err
Brendonovich
Brendonovich2y ago
map_or_else hehe
nexxel
nexxelOP2y ago
match is sexier
Brendonovich
Brendonovich2y ago
yeah if you've just got results it's fine
nexxel
nexxelOP2y ago
im hating library ts atm sucks to write
Brendonovich
Brendonovich2y ago
aint it fun
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP2y ago
yeah :(
Want results from more Discord servers?
Add your server