Skip to content

Commit f445b87

Browse files
authored
Fix Types.DeepMutable mapping over functions (#5752)
1 parent 0fbd1c2 commit f445b87

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

.changeset/gold-swans-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
Fix Types.DeepMutable mapping over functions

packages/effect/dtslint/Types.tst.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,25 @@ describe("Types", () => {
144144
>().type.toBe<[string, number, boolean, bigint, symbol, never, null, "a", 1, true]>()
145145
})
146146

147+
it("functions", () => {
148+
expect<Types.DeepMutable<(arg: 1) => 2>>().type.toBe<(arg: 1) => 2>()
149+
})
150+
151+
it("built in objects", () => {
152+
expect<
153+
[
154+
Types.DeepMutable<String>,
155+
Types.DeepMutable<Number>,
156+
Types.DeepMutable<Boolean>,
157+
Types.DeepMutable<BigInt>,
158+
Types.DeepMutable<Symbol>,
159+
Types.DeepMutable<Date>,
160+
Types.DeepMutable<RegExp>,
161+
Types.DeepMutable<Generator>
162+
]
163+
>().type.toBeAssignableTo<[String, Number, Boolean, BigInt, Symbol, Date, RegExp, Generator]>()
164+
})
165+
147166
describe("Branded", () => {
148167
it("should leave a string brand unchanged", () => {
149168
type T = string & Brand.Brand<"mybrand">

packages/effect/src/Types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export type Mutable<T> = {
261261
*/
262262
export type DeepMutable<T> = T extends ReadonlyMap<infer K, infer V> ? Map<DeepMutable<K>, DeepMutable<V>>
263263
: T extends ReadonlySet<infer V> ? Set<DeepMutable<V>>
264-
: T extends string | number | boolean | bigint | symbol ? T
264+
: T extends string | number | boolean | bigint | symbol | Function ? T
265265
: { -readonly [K in keyof T]: DeepMutable<T[K]> }
266266

267267
/**

0 commit comments

Comments
 (0)