Skip to content

string: value interface not assignable to Record<string,unknown> #50087

Description

Bug Report

🔎 Search Terms

unknown record
Index signature

🕗 Version & Regression Information

Bug initially found in v4.7.4
Oldest found version with bug v3.5.1 in typescript playground
Bug found in nightly version v4.8.0-dev.20220728

  • This changed between versions v3.3.3 and v3.5.1

⏯ Playground Link

Playground link with relevant code

💻 Code

interface OldProps {
  name: unknown;
}

type NewProps = Record<string, unknown>;
// or
// type NewProps = { [key:string]:unknown };

function test(oldProps:OldProps) {
  const props:NewProps = oldProps;
  return props;
}

🙁 Actual behavior

OldProps type is not assignable to NewProps.
Typescript returns the following error:

Type 'OldProps' is not assignable to type 'NewProps'.
  Index signature for type 'string' is missing in type 'OldProps'

Error is consistent with old style record syntax.
Error is consistent if OldProps["name"] type is string or any
Error not found if NewProps = Record<string, any>;
Error also not found if [key:string]:[whatever type] is added to OldProps (triggers different expected error if type conflicts with name).

🙂 Expected behavior

OldProps type is assignable to NewProps.

Activity

  1. jcalz commented on Jul 29, 2022

    @jcalz
    Contributor

    This is working as intended. Interface types don't get implicit index signatures as per #15300. The behavior where {[k: string]: unknown} is treated more strictly than {[k: string]: any} was implemented in #30637, released with TS3.5, and was a documented breaking change.

  2. mikeybinns commented on Jul 29, 2022

    @mikeybinns
    Author

    Okay, looks like for my use case, I should be using a type alias instead of an Interface, and (i cut this from the reproduction) instead of extending the interface, I need to intersect two type aliases.
    Thanks for your help 😄

  3. the0rem commented on Aug 29, 2022

    @the0rem

    Joe Calzaretta (@jcalz) we're trying to upgrade from typescript 4.3.5 to 4.6.4 and are now receiving this error.

    Previously an interface like below would allow an interface to be passed in as the generic:

    export interface IIntegration<
      T extends Record<symbol, unknown> = Record<symbol, unknown>
    > {
      type: IntegrationType;
      data: T;
    }
    

    If this has been a breaking change since 3.5 I'm at a loss as to why this would be happening now?

  4. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions