Skip to content

Commit b668325

Browse files
committed
fix: use more readable and stronger typespec
1 parent 3269016 commit b668325

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Stays/Stays.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import nock from 'nock'
22
import { Duffel } from '../index'
33
import { MOCK_SEARCH_RESULT } from './mocks'
4+
import { StaysSearchParams } from './StaysTypes'
45

56
const duffel = new Duffel({ token: 'mockToken' })
67
describe('Stays', () => {
@@ -10,7 +11,7 @@ describe('Stays', () => {
1011

1112
it('should post location params to /stays/search when `search` is called', async () => {
1213
const mockResponse = { data: { results: [MOCK_SEARCH_RESULT] } }
13-
const mockSearchParams = {
14+
const mockSearchParams: StaysSearchParams = {
1415
location: {
1516
radius: 5,
1617
geographic_coordinates: {
@@ -36,7 +37,7 @@ describe('Stays', () => {
3637

3738
it('should post accommodation params to /stays/search when `search` is called', async () => {
3839
const mockResponse = { data: { results: [MOCK_SEARCH_RESULT] } }
39-
const mockSearchParams = {
40+
const mockSearchParams: StaysSearchParams = {
4041
accommodation: {
4142
ids: ['acc_12345'],
4243
fetch_rates: true,
@@ -59,7 +60,7 @@ describe('Stays', () => {
5960

6061
it('should alternatively accept `guests` with `accommodation` as a search criteria and post it to /stays/search', async () => {
6162
const mockResponse = { data: { results: [MOCK_SEARCH_RESULT] } }
62-
const mockSearchParams = {
63+
const mockSearchParams: StaysSearchParams = {
6364
accommodation: {
6465
ids: ['acc_12345'],
6566
fetch_rates: true,
@@ -87,7 +88,7 @@ describe('Stays', () => {
8788

8889
it('should alternatively accept `guests` with `location` as a search criteria and post it to /stays/search', async () => {
8990
const mockResponse = { data: { results: [MOCK_SEARCH_RESULT] } }
90-
const mockSearchParams = {
91+
const mockSearchParams: StaysSearchParams = {
9192
location: {
9293
radius: 5,
9394
geographic_coordinates: {

src/Stays/StaysTypes.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,11 @@ export interface StaysBooking {
612612
key_collection: StaysBookingKeyCollection | null
613613
}
614614

615-
export type Guest = {
616-
type: string
617-
age?: number
618-
}
615+
// Age is not required for adult, but required for child
616+
type Adult = { type: 'adult'; age?: number }
617+
type Child = { type: 'child'; age: number }
618+
619+
export type Guest = Adult | Child
619620

620621
type OccupancyCriteria = {
621622
rooms: number

0 commit comments

Comments
 (0)