Comments (13)
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.
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.
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.
@fabiospampinato Does that handle promises?
Seems like it should have
T[P] extends Promise<infer U>
? Promise<Partial<U>>
: ...
from type-fest.
@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.
@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.
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.
@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.
@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.
@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.
@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 has funded $60.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
from type-fest.
@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)
- IfAny circular constraint in TS 5.4+ HOT 2
- Make the second argument to RequireAllOrNone optional HOT 1
- Use `NoInfer`?
- Type for serializable objects? HOT 3
- Proposal: SetKeyRequired with key required, but allow undefined value HOT 2
- OverrideProperties changes undefined as optional HOT 2
- Exclude / Pick type in Paths / only add leaf nodes HOT 2
- `Proposal`: add option with exclude/keep specified type on deep type HOT 5
- Unify `Get` and `Paths` / `PickDeep` etc HOT 1
- `Paths` is unable to escape dots in property names
- DistributedOmit may not need to constraint the second type argument HOT 6
- A type util to produce an alternation of function overloads. HOT 1
- PositiveIntegerString type HOT 4
- Type-fest based prelude HOT 1
- ArrayExceptLastElement type HOT 7
- Zero is not exported by ... HOT 1
- `And` and `Or` is not exported at `index.d.ts`
- ConditionalKeys does not correctly filter out `never` type HOT 3
- Paths<T> should handle recursive types
- `PickDeep` strips `null` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from type-fest.