Closed
Description
TypeScript Version: typescript@3.6.0-dev.20190603
Search Terms:
3.5, infer
Code
// mocked CssProperties type
type CssProperties = { position: "absolute" | "relative" };
type StylesObject<ClassKey extends string> = Record<ClassKey, CssProperties>;
type PropsBasedstyles<ClassKey extends string, Props extends object> = (
props: Props
) => StylesObject<ClassKey>;
type Styles<ClassKey extends string, Props extends object> =
| StylesObject<ClassKey>
| PropsBasedstyles<ClassKey, Props>;
function createStyles<ClassKey extends string, Props extends object>(
styles: Styles<ClassKey, Props>
): Styles<ClassKey, Props> {
return styles;
}
const styles = createStyles({
root: {
position: "absolute"
}
});
Expected behavior:
Behavior in 3.4.5
typeof styles = Styles<'root', {}>
Actual behavior:
Behavior in >=3.5.0
typeof styles = Styles<'root', object>
Playground Link:
playground
Related Issues: Did not find any
Notes:
Seems like the playground is still using 3.4.
Usage of this behavior is showcased in https://github.com/eps1lon/ts-inference-3.5/blob/master/index.ts with a fix for 3.5.