-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(P.infer): Fix inference of array containing tuples
- Loading branch information
Showing
4 changed files
with
30 additions
and
16 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
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,25 @@ | ||
import { P } from '../src'; | ||
import { Equal, Expect } from '../src/types/helpers'; | ||
|
||
describe('P.infer', () => { | ||
describe('array', () => { | ||
it('should correctly narrow types of arrays containing tuples', () => { | ||
const QuizValue = P.union('initial', 'correct', 'incorrect'); | ||
const QuizState = { | ||
answerEntries: P.array([P.string, QuizValue]), | ||
appendOnlyAnswerEntries: P.array([P.string, P.array(QuizValue)]), | ||
}; | ||
|
||
type QuizValue = P.infer<typeof QuizValue>; | ||
type expected1 = 'initial' | 'correct' | 'incorrect'; | ||
type test1 = Expect<Equal<QuizValue, expected1>>; | ||
|
||
type QuizState = P.infer<typeof QuizState>; | ||
type expected2 = { | ||
answerEntries: [string, QuizValue][]; | ||
appendOnlyAnswerEntries: [string, QuizValue[]][]; | ||
}; | ||
type test2 = Expect<Equal<QuizState, expected2>>; | ||
}); | ||
}); | ||
}); |
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