-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 3.3.0-dev.20190119
Search Terms:
Infering type from function return type
Infering from return type
Argument breaks return type inferring
Code
export const createStyles = <
K extends ReturnType<T>,
T extends (theme: { type: string }) => StyleSheet.NamedStyles<K> | StyleSheet.NamedStyles<any>,
>(
fn: T
) => fn;
const styles = createStyles(() => ({
logo: {
width: 70,
height: 70,
},
}));
// here logo type is properly inferred from object
styles().logo.width
const styles = createStyles((theme) => ({
logo: {
width: 70,
height: 70,
},
}));
// here styles function signature is (theme: { type: string }) => any
styles({ 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
Playground Link:
https://codesandbox.io/s/p3414yomnx
Related Issues:
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code