Skip to content
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

only wrap objects with string keys in Config.Wrap #2923

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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