Coder Social home page Coder Social logo

Proposal: DeepPartial about type-fest HOT 13 CLOSED

sindresorhus avatar sindresorhus commented on May 22, 2024 4
Proposal: DeepPartial

from type-fest.

Comments (13)

fabiospampinato avatar fabiospampinato commented on May 22, 2024 1

I'm not sure what's about that patch function, but here there's an implementation of DeepPartial:

type DeepPartial<T> = {
  [P in keyof T]?: T[P] extends Array<infer U>
    ? Array<DeepPartial<U>>
    : T[P] extends ReadonlyArray<infer U>
      ? ReadonlyArray<DeepPartial<U>>
      : DeepPartial<T[P]>
};

from type-fest.

sindresorhus avatar sindresorhus commented on May 22, 2024 1

Alright. I'm gonna accept this. It seems it's quite common: https://github.com/search?l=TypeScript&q=DeepPartial&type=Code

It should be named PartialDeep since we already have ReadonlyDeep.

For anyone that wants to tackle this, please read guide for adding a type and also see how ReadonlyDeep was added: 22c3a99 (Note the extensive docs and comments).

from type-fest.

uyeong avatar uyeong commented on May 22, 2024

patch is just an example. I changed the name to fn. thanks for letting me know.

I actually opened this issue because I think type-fest should include the DeepPartial type.

from type-fest.

dylang avatar dylang commented on May 22, 2024

@fabiospampinato Does that handle promises?

Seems like it should have

T[P] extends Promise<infer U>
 ? Promise<Partial<U>>
 : ...

from type-fest.

fabiospampinato avatar fabiospampinato commented on May 22, 2024

@dylang Yeah I don't think it handles promises that way. I'm not sure if you'd necessarily want that though 🤔

from type-fest.

dylang avatar dylang commented on May 22, 2024

@fabiospampinato Thanks for the feedback. It was useful for a deep partial ReturnValue<T> wrapper when mocking functions for our tests, but makes sense that it's not always what developers would expect.

from type-fest.

Psidium avatar Psidium commented on May 22, 2024

Does DeepPartial support arrays?

interface Inter {
	prop: string;
	children: string[];
}

turns into the equivalent of

interface Inter {
	prop?: string;
	children?: Array<string | undefined>;
}

from type-fest.

sindresorhus avatar sindresorhus commented on May 22, 2024

@uyeong Do you have any real-world uses of it that you can link to? It seems useful in theory, but I haven't encountered a situation where I would need it personally.

from type-fest.

fabiospampinato avatar fabiospampinato commented on May 22, 2024

@sindresorhus I think it could be useful when merging a default settings object with another object, the second object would be a deep partial of the default object.

from type-fest.

sindresorhus avatar sindresorhus commented on May 22, 2024

@fabiospampinato Do you have any actual code using that pattern? I'm asking because it's easy to suggest things that look useful, but I'm trying very hard to only add things to type-fest that people would actually use, or are already using in production.

from type-fest.

fabiospampinato avatar fabiospampinato commented on May 22, 2024

@sindresorhus Yes, I do that all the time, here there some examples: 1, 2, 3, 4.

Often though I try to keep the options object flat, in those cases I don't really need DeepPartial.

from type-fest.

issuehunt-oss avatar issuehunt-oss commented on May 22, 2024

@issuehunt has funded $60.00 to this issue.


from type-fest.

issuehunt-oss avatar issuehunt-oss commented on May 22, 2024

@sindresorhus has rewarded $54.00 to @kainiedziela. See it on IssueHunt

  • 💰 Total deposit: $60.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $6.00

from type-fest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.