#Why is TS compiler resolving result of function with generics to never?

9 messages · Page 1 of 1 (latest)

tropic phoenix
#

I'm trying to map strings to prefixed versions and preserve the type, eg. 'required' becomes 'fieldNameRequired'

Any help in figuring out why label1-3 resolves to never but label4 resolves correctly would be hugely appreciated because I'm stumped! 😁

I've tested all my generics individually in the attached fine and they all resolve correctly. I've also replicated the logic and typings of my mapping function and that also resolves correctly as label4, but I don't understand why using the function itself doesn't behave the same way 🤔

#

I'm convinced GitHub Copilot has no idea what it's talking about, every other suggestion either includes a parse error or is just wrong 😆

gaunt agate
#

please don't send text files for your code, put the code in the playground and send a link

tropic phoenix
gaunt agate
#

you should probably reduce it to a minimal reproducable example then

tropic phoenix
#

Boom:

(It's now label2 which resolves correctly and label1 which doesn't)

naive ridgeBOT
#
mashmango#0

Preview:```ts
// ========== Some field types...

type FieldName = {
firstNameLabel: 'First Name';
firstNameRequired: true;
lastNameLabel: 'Last Name';
lastNameRequired: true;
};

type FieldAddress = {
address1Label: 'Address 1';
address1Required: true;
address2Label: 'Address 2';
...```

gaunt agate
#

field in getSubFieldName is Field instead of F

tropic phoenix
#

ahhhh!! doh, thanks so much! 🙏