Skip to content

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

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

Closed
JasonKleban opened this issue Jan 4, 2018 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@JasonKleban
Copy link

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);
@DanielRosenwasser
Copy link
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.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 4, 2018
@typescript-bot
Copy link
Collaborator

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

@jcormont
Copy link

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.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants