-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: infer Data type from user config
- Loading branch information
Showing
18 changed files
with
182 additions
and
105 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
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
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
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 |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import { Data } from "../types/Config"; | ||
import { rootDroppableId } from "./root-droppable-id"; | ||
|
||
export const setupZone = (data: Data, zoneKey: string): Required<Data> => { | ||
// Force 'zones' to always be present and non-undefined | ||
type WithZones<T extends Data> = T & { zones: NonNullable<T["zones"]> }; | ||
|
||
// Ensuring zones is non-undefined and part of the final type | ||
function ensureZones<UserData extends Data>( | ||
data: UserData | ||
): WithZones<UserData> { | ||
return { | ||
...data, | ||
zones: data.zones || {}, | ||
} as WithZones<UserData>; | ||
} | ||
|
||
export const setupZone = <UserData extends Data>( | ||
data: UserData, | ||
zoneKey: string | ||
): Required<WithZones<UserData>> => { | ||
if (zoneKey === rootDroppableId) { | ||
return data as Required<Data>; | ||
return data as Required<WithZones<UserData>>; | ||
} | ||
|
||
const newData = { ...data }; | ||
|
||
newData.zones = data.zones || {}; | ||
// Preprocess to ensure zones is not undefined | ||
const newData = ensureZones(data); | ||
|
||
newData.zones[zoneKey] = newData.zones[zoneKey] || []; | ||
|
||
return newData as Required<Data>; | ||
return newData as Required<WithZones<UserData>>; | ||
}; |
Oops, something went wrong.