-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
- Loading branch information
Showing
19 changed files
with
150 additions
and
108 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,44 @@ | ||
import { VariableTypeAlias, VariableValue } from './config/models' | ||
|
||
/** | ||
* Used to support strong typing of variable keys in the SDK. | ||
* Usage; | ||
* ```ts | ||
* import '@devcycle/types'; | ||
* declare module '@devcycle/types' { | ||
* interface CustomVariableDefinitions { | ||
* 'flag-one': boolean; | ||
* } | ||
* } | ||
* ``` | ||
* Or when using the cli generated types; | ||
* ```ts | ||
* import '@devcycle/types'; | ||
* declare module '@devcycle/types' { | ||
* interface CustomVariableDefinitions extends DVCVariableTypes {} | ||
* } | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface CustomVariableDefinitions {} | ||
type DynamicBaseVariableDefinitions = | ||
keyof CustomVariableDefinitions extends never | ||
? { | ||
[key: string]: VariableValue | ||
} | ||
: CustomVariableDefinitions | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface VariableDefinitions extends DynamicBaseVariableDefinitions {} | ||
export type VariableKey = string & keyof VariableDefinitions | ||
// type that determines whether the VariableDefinitions interface | ||
// extends the index signature, and thus does not have custom variable | ||
// types defined. | ||
export type CustomVariablesDefined = | ||
keyof CustomVariableDefinitions extends never ? false : true | ||
|
||
export type InferredVariableType< | ||
K extends VariableKey, | ||
DefaultValue extends VariableDefinitions[K], | ||
> = CustomVariablesDefined extends true | ||
? VariableDefinitions[K] | ||
: VariableTypeAlias<DefaultValue> |
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
Oops, something went wrong.