-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from Ayc0/symbol
Symbols as keys
- Loading branch information
Showing
2 changed files
with
44 additions
and
14 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
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,28 @@ | ||
import { isMatching, P } from '../src'; | ||
import { Equal, Expect } from '../src/types/helpers'; | ||
|
||
describe('Objects', () => { | ||
it('should work with symbols', () => { | ||
const symbolA = Symbol('symbol-a'); | ||
const symbolB = Symbol('symbol-b'); | ||
const obj: { [symbolA]: { [symbolB]: 'foo' | 'bar' } } = { | ||
[symbolA]: { [symbolB]: 'foo' }, | ||
}; | ||
if (isMatching({ [symbolA]: { [symbolB]: 'foo' } }, obj)) { | ||
type t = Expect<Equal<typeof obj, { [symbolA]: { [symbolB]: 'foo' } }>>; | ||
} else { | ||
throw new Error('Expected obj to match the foo pattern!'); | ||
} | ||
if (isMatching({ [symbolA]: { [symbolB]: 'bar' } }, obj)) { | ||
type t = Expect< | ||
Equal< | ||
typeof obj, | ||
{ [symbolA]: { [symbolB]: 'foo' } } & { | ||
[symbolA]: { [symbolB]: 'bar' }; | ||
} | ||
> | ||
>; | ||
throw new Error('Expected obj to not match the bar pattern!'); | ||
} | ||
}); | ||
}); |