generic type for …args?

Issue I have a function time const time = <T>(fn: (…args: any[]) => Promise<T>, …args: any[]): Promise<T> => { return new Promise(async (resolve, reject) => { const timer = setTimeout(() => reject(`Error: ${fn.name} timed out`), ms) try { resolve(await fn.bind(thisArg)(…args))

Continue reading

Template Literal type equivalent

Issue Good morning, I have an enum like so: export enum ApiFunctions { "setHidden" = "HIDE", "setReadOnly" = "SET_READ_ONLY", "setVisible" = "SHOW", "setDescription" = "SET_DESCRIPTION", "setName" = "SET_NAME", "makeRequest" = "MAKE_REQUEST" } Earlier today I created a new type from

Continue reading

Type for basic HTML tags?

Issue I have an exported type called Tags that defines available tags for some components: export type Tags = | ‘div’ | ‘article’ | ‘section’ | ‘aside’ | ‘nav’ | ‘figure’ | ‘main’ | ‘header’ | ‘footer’; Obviously, this is

Continue reading

Angular build fails with ckeditor – Getter and setter accessors do not agree in visibility

Issue I tried to install ckeditor5-angular and ckeditor5-build-classic according to https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/frameworks/angular.html . When Building, I got the error message: Error: node_modules/@types/ckeditor__ckeditor5-ui/src/editableui/editableuiview.d.ts:7:9 – error TS2379: Getter and setter accessors do not agree in visibility. 7 get _hasExternalElement(): boolean; ~~~~~~~~~~~~~~~~~~~ Error: node_modules/@types/ckeditor__ckeditor5-ui/src/editableui/editableuiview.d.ts:8:19

Continue reading

Typing svelte $store variable

Issue I wanted to know if it is possible de type the dollar sign value of a custom svelte store ? From this example : app.svelte <script> import { count } from ‘./stores.js’; </script> <h1>The count is {$count}</h1> <button on:click={count.increment}>+</button>

Continue reading

TypeScript – [string] vs string[]

Issue In TypeScript, which one is right? [string] vs string[] public searchOption: [string] = [‘date’]; public searchOption: string[] = [‘date’]; Solution The second one is right. If you want, you can take a look here https://www.typescriptlang.org/docs/handbook/basic-types.html Answered By – geo

Continue reading

TypeScript – [string] vs string[]

Issue In TypeScript, which one is right? [string] vs string[] public searchOption: [string] = [‘date’]; public searchOption: string[] = [‘date’]; Solution The second one is right. If you want, you can take a look here https://www.typescriptlang.org/docs/handbook/basic-types.html Answered By – geo

Continue reading

Type guards for types of arrays

Issue Using typeof type guards for non-array types is pretty straightforward (example from the docs): function padLeft(value: string, padding: string | number) { if (typeof padding === “number”) { return Array(padding + 1).join(” “) + value; } if (typeof padding

Continue reading

how to use prevstate to localstorage in typescript(react)

Issue type allergyProps = { filterAllergy: allergyArray[]; setRemoveAllergy: Dispatch<SetStateAction<string>>; setSearchAllergy: Dispatch<SetStateAction<string>>; }; type allergyArray = { id: number; name: string; }; const Allergy = ({ setSearchAllergy, filterAllergy }: allergyProps) => { const [isInput, setIsInput] = useState(false); const [removeAllergy, setRemoveAllergy] =

Continue reading

Trouble understanding type indexing

Issue I’m having trouble understanding the following type definition: type MergeHandlersReturnType<H extends Record<string, any>> = { [K in keyof H]: ReturnType<H[K]> }[keyof H] Decomposing the above definition using similar types I’m not getting why the following is giving me compiler

Continue reading