Add string literal types to function

This commit is contained in:
Ethan Lane 2024-06-19 13:45:07 +01:00
parent a20bdacbe5
commit b1c7de7e8c
3 changed files with 2 additions and 42 deletions

View file

@ -1,6 +1,6 @@
export default interface ICliOptions {
subreddit: string,
json?: boolean,
sort: string,
sort: "new" | "hot" | "top",
queryMetadata?: boolean,
}

View file

@ -7,15 +7,7 @@ import { ErrorCode } from "./constants/ErrorCode";
import ErrorMessages from "./constants/ErrorMessages";
import ImageHelper from "./imageHelper";
const sortable = [
'new',
'hot',
'top'
];
export default async function randomBunny(subreddit: string, sortBy: string = 'hot'): Promise<IReturnResult> {
if (!sortable.includes(sortBy)) sortBy = 'hot';
export default async function randomBunny(subreddit: string, sortBy: "new" | "hot" | "top" = 'hot'): Promise<IReturnResult> {
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json?limit=100`)
.then((res) => {
return res;