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

fix: updates to typescript w/n the env command #6905

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

tlane25
Copy link
Contributor

@tlane25 tlane25 commented Oct 28, 2024

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes #Typescript in Env Command

Fixes all $TSFixMe and @ts-ignore within Env command directory. Added additional types for functions and API methods associated with env command.

Thanks for the help @wconrad265!


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

wconrad265 and others added 11 commits October 23, 2024 11:30
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Will <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
Co-authored-by: Thomas Lane <[email protected]>
@tlane25 tlane25 requested a review from a team as a code owner October 28, 2024 15:45
@tlane25
Copy link
Contributor Author

tlane25 commented Oct 30, 2024

@DanielSLew Will you review this when you have a moment?

Copy link
Contributor

@DanielSLew DanielSLew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a few small changes!

body: EnvVar
}

interface createEnvVarParams {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface createEnvVarParams {
interface CreateEnvVarParams {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been updated

[key: string]: Record<string, unknown>;
}

// Processing Settings Interface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need all these comments, they're all basically just saying the name of the interfaces are

scopes = scopes.filter((sco) => !/post[-_]processing/.test(sco))
}

// if the passed context is unknown, it is actually a branch name
// @ts-expect-error TS(7006) FIXME: Parameter 'ctx' implicitly has an 'any' type.
let values = contexts.map((ctx) =>
let values: Value[] = contexts.map((ctx) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the Value type supposed to be? Can we give it a more descriptive name

export const AVAILABLE_SCOPES = ['builds', 'functions', 'runtime', 'post_processing']
import { GetEnvelopeEnvParams, ProcessedEnvVars } from './types.js'

export const AVAILABLE_CONTEXTS: Context[] = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change that to DeployContext, context on its own is too vague

Suggested change
export const AVAILABLE_CONTEXTS: Context[] = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']
export const AVAILABLE_CONTEXTS: DeployContext[] = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']

@tlane25
Copy link
Contributor Author

tlane25 commented Nov 4, 2024

Suggested changes were made w/ @wconrad265!

@@ -26,7 +27,7 @@ export const envGet = async (name: string, options: OptionValues, command: BaseC
}

if (!value) {
const contextType = AVAILABLE_CONTEXTS.includes(context) ? 'context' : 'branch'
const contextType = context === undefined ? 'branch' : AVAILABLE_CONTEXTS.includes(context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed? It now returns a boolean instead of a string

Comment on lines +37 to +39
if (isAPIEnvError(error)) {
throw error.json ? error.json.msg : error
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're doing this we should add an else to throw. Otherwise we're swallowing the error if it if (isAPIEnvError(error)) returns false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or could we do something like this?

Suggested change
if (isAPIEnvError(error)) {
throw error.json ? error.json.msg : error
}
throw (error as APIError).json ? (error as APIError).json.msg : error

Comment on lines +63 to +65
if (error && typeof error === 'object' && 'message' in error && typeof error.message === 'string') {
log(error.message)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, we could just do

Suggested change
if (error && typeof error === 'object' && 'message' in error && typeof error.message === 'string') {
log(error.message)
}
log((error as APIError).message)

Comment on lines +96 to +97
const errortoThrow = isAPIEnvError(error_) ? error_.json.msg : error_
throw errortoThrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is what I was mentioning above, to do it this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants