Skip to content

Commit

Permalink
only wrap objects with string keys in Config.Wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jun 5, 2024
1 parent 8c5d280 commit 95bdf79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-boxes-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

only wrap objects with string keys in Config.Wrap
12 changes: 5 additions & 7 deletions packages/effect/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ export declare namespace Config {
* @since 2.0.0
* @category models
*/
export type Wrap<A> = [NonNullable<A>] extends [infer T] ? [T] extends [Function] ? Config<A> :
[T] extends [ReadonlyArray<infer _>] ? Config<A> :
[T] extends [Record<string, any>] ?
| {
[K in keyof A]: Wrap<A[K]>
}
| Config<A>
export type Wrap<A> = [NonNullable<A>] extends [infer T] ?
[T] extends [Record<string, any>] ? [Exclude<keyof T, string>] extends [never] ?
| { readonly [K in keyof A]: Wrap<A[K]> }
| Config<A>
: Config<A>
: Config<A>
: Config<A>
}
Expand Down
13 changes: 11 additions & 2 deletions packages/effect/test/Config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ describe("Config", () => {
_: Config.Config.Wrap<{
key1: number
list: ReadonlyArray<number>
option: Option.Option<number>
secret: Secret.Secret
nested?:
| Partial<{
key2: string
Expand All @@ -396,20 +398,27 @@ describe("Config", () => {
const config = wrapper({
key1: Config.integer("key1"),
list: Config.array(Config.integer(), "items"),
option: Config.option(Config.integer("option")),
secret: Config.secret("secret"),
nested: {
key2: Config.string("key2")
}
})
assertSuccess(config, [["key1", "123"], ["items", "1,2,3"], ["key2", "value"]], {
assertSuccess(config, [["key1", "123"], ["items", "1,2,3"], ["option", "123"], ["secret", "sauce"], [
"key2",
"value"
]], {
key1: 123,
list: [1, 2, 3],
option: Option.some(123),
secret: Secret.fromString("sauce"),
nested: {
key2: "value"
}
})
assertFailure(
config,
[["key1", "123"], ["items", "1,value,3"], ["key2", "value"]],
[["key1", "123"], ["items", "1,value,3"], ["option", "123"], ["secret", "sauce"], ["key2", "value"]],
ConfigError.InvalidData(["items"], "Expected an integer value but received value")
)
})
Expand Down

0 comments on commit 95bdf79

Please sign in to comment.