Skip to content

Commit

Permalink
Fix #208 - O.Invert doesn't work for interfaces (just for types)
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Mar 2, 2021
1 parent ec4a953 commit c582e7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sources/Object/Invert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type _Invert<O extends Record<Key, Key>> =
* type test1 = O.Invert<O>
* ```
*/
export type Invert<O extends Record<Key, Key>> =
export type Invert<O extends Record<keyof O, Key>> =
O extends unknown
? _Invert<O>
: never
17 changes: 15 additions & 2 deletions tests/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ checks([
const INVERT_SYM = Symbol('')

type O_INVERT = {
A: 'Av',
B: typeof INVERT_SYM,
A: 'Av';
B: typeof INVERT_SYM;
C: 42;
};

Expand All @@ -439,8 +439,21 @@ type INVERT_O = {
42: 'C';
};

interface O_INVERT1 {
A: 'Av';
B: typeof INVERT_SYM;
C: 42;
}

interface INVERT1_O {
Av: 'A';
[INVERT_SYM]: 'B';
42: 'C';
}

checks([
check<O.Invert<O_INVERT>, INVERT_O, Test.Pass>(),
check<O.Invert<O_INVERT1>, INVERT1_O, Test.Pass>(),
])

// ---------------------------------------------------------------------------------------
Expand Down

0 comments on commit c582e7a

Please sign in to comment.