Skip to content

Partial<T> where T has only optional members should not yield ... has no properties in common with type 'Partial<...>'error #20999

Closed

Description

@JasonKleban

tsc v2.6.2

Here's an example from jcormont/documentdb-typescript, Collection.d.ts in attempting to support this new ttl field:

storeDocumentAsync<T extends Partial<_DocumentDB.DocumentResource>>(data: T, mode?: StoreMode, maxRetries?: number, options?: AllOptions): Promise<T & _DocumentDB.DocumentResource>;

...

export interface DocumentResource extends Resource {
    ttl?: number;
}

If I opt NOT to include a ttl, I get [ts] Type 'MyDocument' has no properties in common with type 'Partial<DocumentResource>'.

const stored = await myDocuments.storeDocumentAsync(myDocument, StoreMode.CreateOnly);

I can work around it like this, but it is ugly:

const stored = await myDocuments.storeDocumentAsync({ ... myDocument, ttl: undefined }, StoreMode.CreateOnly);

Activity

  1. DanielRosenwasser commented on Jan 4, 2018

    @DanielRosenwasser
    Member

    I believe this is working as intended as part of weak type checking (#16047).

    As a side question, does myDocument not have an id field? I would think MyDocument would extend from Resource at the least.

  2. typescript-bot commented on Jan 20, 2018

    @typescript-bot
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  3. jcormont commented on Feb 17, 2018

    @jcormont

    Just for reference, this has been fixed by adding & object to the type specification for the first parameter of storeDocumentAsync.

    This makes sense: documents are always 'real' objects (not Numbers, Strings etc) and it seems to stop the TypeScript compiler from being overzealous and warning about common properties -- probably because there are common properties such as hasOwnProperty.

  4. locked and limited conversation to collaborators on Jul 3, 2018
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

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions