Search code examples
typescriptbabel-loader

Different implementations of Partial in Typescript?


I am trying to use Partial of typescript by following the examples of Fast-dna repo and i notice that in my repo I have a different implementation of Partial

For them Partial is defined as

enter image description here

For me it is coming as

enter image description here

The only difference i see is that they are using babel and i am not. Is this the reason?

But i still don't get how there can be two different implementations ?

I am using Create react app with typescript template.


Solution

  • There are not two different implementations of Partial there is just one, the difference comes from typescript settings.

    When you have strictNullChecks turned on, typescript automatically adds to the type of optional properties, a | undefined (union with undefined). This makes sense as under strict null checks, ts keeps track of undefined and null as separate types, and optional properties can always be undefined. If this option is turned off there is no separate tracking of undefined and this it is not added.

    You can see this in the playground as well:

    With strictNullChecks: enter image description here

    Without null checks:

    enter image description here