Methuselah96 / immutable-js

Immutable persistent data collections for Javascript which increase efficiency and simplicity.
http://facebook.github.io/immutable-js/
MIT License
0 stars 2 forks source link

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

Open Methuselah96 opened 4 years ago

Methuselah96 commented 4 years ago

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 commented 4 years ago

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.