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

Can't assign string to string | null for object in immutable map #6

Open
Methuselah96 opened this issue Oct 16, 2020 · 1 comment
Open

Comments

@Methuselah96
Copy link
Owner


Migrated from don't!
Originally created by @JoshuaLamusga on Thu, 10 Sep 2020 20:24:13 GMT


What happened

With typescript 3.9.7 and immutable-js version 3.8.2, the following code unexpectedly throws an error:

type TestAbcType = IImmutableMap<{ a: boolean, b: string | null }>
const testAbc = createImmutableMap({ a: true, b: null })
const testXyz: TestAbcType = testAbc

With the error being:

Type 'IImmutableMap<{ a: boolean; b: null; }>' is not assignable to type 'TestAbcType'.
  Type 'string | null' is not assignable to type 'null'.
    Type 'string' is not assignable to type 'null'.

This is surprising because according to the type definition, b can be a string or null. In this case, b is null and should satisfy the condition of string | null. This code works if it's not wrapped with IImmutableMap, indicating the problem lies with this library.

@Methuselah96
Copy link
Owner Author


Migrated from don't reference!
Original comment by @conartist6 on Wed, 16 Sep 2020 13:25:28 GMT


You hav not included the definition of IImmutableMap.

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