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)
- [4.10.0][Regression] failure when type checking with exactOptionalPropertyTypes HOT 5
- IntRange Inclusive HOT 3
- Weird bug report - RangeError: Maximum call stack size exceeded when building HOT 1
- Update Merge type to accept N type arguments HOT 1
- Maintenance strategy: Considering splitting `type-fest` into smaller importable parts HOT 14
- OptionalExcept type HOT 2
- Why do we need to specify the `engines` field in package.json? HOT 1
- Require exactly one key of type `string` HOT 1
- Bug: Nextjs and type-fest camel-case.d.ts Type error: '?' expected.
- `JsonValue` can receive `type` but not `interface` HOT 1
- CamelCasedObjectDeep breaks tuple-types into array-types
- `UnionToUnorderedTuple` type HOT 2
- `NonEmptyObject` fails for objects with dynamic properties HOT 2
- Proposal: `ValueOfDeep<Type, 'key.deepKey'>` HOT 1
- Questions about the types located in the file `/source/basic.d.ts`
- ReadonlyDeep: add test for function or method returning an object? HOT 1
- `RepeatString` type
- `ArraySlice` should support spread array HOT 3
- TS 5.4.2 breaks `ConditionalKeys` and `SetParameterType` HOT 16
- `ReadonlyDeep` / `WritableDeep` not modifying arrays as of TS 5.3.3 HOT 3
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.