You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inferring ReturnType<T> from function with arguments falling back to any #29499
Search Terms:
Infering type from function return type
Infering from return type
Argument breaks return type inferring
Code
exportconstcreateStyles=<KextendsReturnType<T>,Textends(theme: {type: string})=>StyleSheet.NamedStyles<K>|StyleSheet.NamedStyles<any>,>(fn: T)=>fn;conststyles=createStyles(()=>({logo: {width: 70,height: 70,},}));// here logo type is properly inferred from objectstyles().logo.widthconststyles=createStyles((theme)=>({logo: {width: 70,height: 70,},}));// here styles function signature is (theme: { type: string }) => anystyles({type: 'dark'}).logo.width
Expected behavior:
It is possible to infer the return type of the function for both situations
Actual behavior:
Type inferring only for the function that doesn't have any parameters and falling to any if any parameters applied
changed the title [-]Inferring from function with arguments falling back to any[/-][+]Inferring ReturnType<T> from function with arguments falling back to any[/+]on Jan 20, 2019
Ryan Cavanaugh (@RyanCavanaugh) Thanks for clarifying. But for react native it's required to infer type through NamedStyles to be sure that strings like textAlign are proper enum values.
And here is a question - is it possible to make it works with inferring ReturnType through NamedStyles
Activity
[-]Inferring from function with arguments falling back to any[/-][+]Inferring ReturnType<T> from function with arguments falling back to any[/+]RyanCavanaugh commentedon Jan 23, 2019
Seems like you just have too many type parameters. This code works better:
dmtrKovalenko commentedon Jan 26, 2019
Ryan Cavanaugh (@RyanCavanaugh) Thanks for clarifying. But for react native it's required to infer type through
NamedStylesto be sure that strings liketextAlignare proper enum values.And here is a question - is it possible to make it works with inferring
ReturnTypethroughNamedStylesdmtrKovalenko commentedon Jan 26, 2019
I understand that here we getting circular dependency between types, referring each other. But maybe there is some way to not fall back to any?
dmtrKovalenko commentedon Jan 26, 2019
And why it's breaking only if function has argument 🤔
dmtrKovalenko commentedon Feb 7, 2019
Duplicate of #241