Skip to content

3.5 regression concerning type inference for non-inferable types #31735

Closed
@eps1lon

Description

@eps1lon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions