Skip to content

Conversation

@camden11
Copy link
Contributor

Description and Context

Was working with the new lang objects and found another opportunity to do some type checking and reduce copy errors. With the satisfies operator, we can default every function in the lang objects to expect only strings or numbers as arguments. This will help reduce accidentally passing in undefined, objects, or anything else unexpected. We can override lang functions on a case by case basis if they need to accept other types (see noAppsElgible) - I think this is rare enough that the extra checks will be worth the slightly higher effort in those cases.

Who to Notify

@brandenrodgers @joe-yeager @kemmerle

lang/en.ts Outdated
Comment on lines 4 to 9
type LangFunction = (...args: string[] | number[]) => string;

type LangObject = {
[key: string]: string | LangFunction | LangObject;
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

lang/en.ts Outdated
// @ts-nocheck
import chalk from 'chalk';

type LangFunction = (...args: string[] | number[]) => string;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be ...args: (string | number)[]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah actually... you'd think so, but for some reason this works as expected (typing each individual arg as string or number). But I think what you suggested is clearer towards we actually want so I'll update it

joe-yeager
joe-yeager previously approved these changes Apr 24, 2025
Copy link
Contributor

@joe-yeager joe-yeager left a comment

Choose a reason for hiding this comment

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

LGTM, just a question about one of the types

@camden11 camden11 merged commit 72086ab into main Apr 24, 2025
1 check passed
@camden11 camden11 deleted the type-lang-objects branch April 24, 2025 18:03
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