Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Simplify TypeScript in setSettings #55

Open
jschuur opened this issue Apr 25, 2023 · 0 comments
Open

Refactor: Simplify TypeScript in setSettings #55

jschuur opened this issue Apr 25, 2023 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@jschuur
Copy link
Owner

jschuur commented Apr 25, 2023

This mess of code with explicit individual references to settings was needed to not get TypeScript errors (details on Stackoverflow):

function setSetting(setting: Setting, value: SettingsTypes) {
  // all this to keep typescript happy. there has to be a better way?
  // https://stackoverflow.com/questions/75809343/type-string-number-is-not-assignable-to-type-never-when-dynamically-settin/75809489#75809489
  if ((setting === 'maxTokens' || setting === 'historyLength') && typeof value === 'number')
    settings[setting] = value;
  if (
    (setting === 'model' || setting === 'system' || setting === 'apiKey') &&
    typeof value === 'string'
  )
    settings[setting] = value;
  if ((setting === 'wordWrap' || setting === 'clipboard') && typeof value === 'boolean')
    settings[setting] = value;

  console.log(`${pc.cyan(setting.toLowerCase())} set to ${pc.magenta(String(value))}`);
}

See if something can be done, since now every time a new setting is added, it needs to go into the right if block.

@jschuur jschuur converted this from a draft issue Apr 25, 2023
@jschuur jschuur changed the title Refactor: Simplify TypeScript in setSettings Refactor: Simplify TypeScript in setSettings Apr 25, 2023
@jschuur jschuur added the help wanted Extra attention is needed label Apr 25, 2023
@jschuur jschuur pinned this issue Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
Status: Paused
Development

No branches or pull requests

1 participant