Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record with more keys should be assignable to Record with less keys if type is a subset of the first one #1934

Open
jdeniau opened this issue Feb 7, 2023 · 0 comments

Comments

@jdeniau
Copy link
Member

jdeniau commented Feb 7, 2023

import { RecordOf } from 'immutable';

export type Id = {};

type A = RecordOf<{ id: Id, param: boolean  }>;
type B = RecordOf<{ id: Id}>;

const a: A = null as any;
const b: B = a;

errors with

Type 'A' is not assignable to type 'B'.
  Type 'A' is not assignable to type 'Record<{ id: Id; }>'.
    Types of property 'has' are incompatible.
      Type '(key: string) => key is "id" | "param"' is not assignable to type '(key: string) => key is "id"'.
        Type predicate 'key is "id" | "param"' is not assignable to 'key is "id"'.
          Type '"id" | "param"' is not assignable to type '"id"'.
            Type '"param"' is not assignable to type '"id"'.

Originally posted by @thatsmydoing in #1930 (comment)

This should work as it does work with plain objects as B is a subset of A: https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCSATOBeOBvOANwC44BnGKASwDsBzOAXwG4AoVpFOAQR3zioZSmADRwwAQygSAtqQBGECABtgEmnCYdkqAEJ8Cg4VkbsAxhBoU4E0r1yGh-EnADkARldMxk6XIRQAK6oLKwWVvDypPq4EsxAA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant