-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow data classes to be branded with an additional type parameter
- Loading branch information
1 parent
c138fa7
commit 68fe96b
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"effect": minor | ||
--- | ||
|
||
Allow data classes to be branded with an additional type parameter | ||
|
||
```ts | ||
import { Data, HashMap } from "effect" | ||
|
||
export class T extends Data.Class< | ||
{ id: string }, | ||
{ readonly _brand: unique symbol } | ||
> {} | ||
|
||
// type error | ||
export const hashMap1: HashMap.HashMap<T, string> = HashMap.empty().pipe( | ||
HashMap.set({ id: "one" }, "one"), | ||
HashMap.set({ id: "one" }, "two") | ||
) | ||
|
||
// no type error | ||
export const hashMap2: HashMap.HashMap<T, string> = HashMap.empty().pipe( | ||
HashMap.set(new T({ id: "one" }), "one"), | ||
HashMap.set(new T({ id: "one" }), "two") | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters