TypeScript type ignore case

NEW ANSWER FOR TYPESCRIPT 4.1+ Welcome back! Now that TypeScript 4.1 has introduced template literal types and the Uppercase/Lowercase intrinsic string mapping types, we can now answer this question without needing regular expression types. There are two main approaches. The “brute force” approach makes heavy use of recursive conditional types and unions to turn your … Read more

Is there a way to define type for array with unique items in typescript?

The only possible way this could work at compile time is if your arrays are tuples composed of literals. For example, here are some arrays with the same runtime values, but with different types in TypeScript: const tupleOfLiterals: [1, 2, 2] = [1, 2, 2]; const tupleOfNonLiterals: [number, number, number] = [1, 2, 2]; const … Read more

React TypeScript: Correct type for useLocation() from react-router-dom

You can create a particular type or interface to describe your location state and then use it when calling a useLocation hook: import React from “react”; import { useLocation } from “react-router-dom”; interface LocationState { from: { pathname: string; }; } const AuthLayer: React.FC = (props) => { const location = useLocation<LocationState>(); const { from … Read more

What does /// mean?

These are referred to as “Triple Slash Directives” (Typescript docs) As stated on the first line of that link: Triple-slash directives are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives. So yes, the typescript compiler is picking this up during compilation and taking the appropriate action. … Read more

Narrowing a return type from a generic, discriminated union in TypeScript

Like many good solutions in programming, you achieve this by adding a layer of indirection. Specifically, what we can do here is add a table between action tags (i.e. “Example” and “Another”) and their respective payloads. type ActionPayloadTable = { “Example”: { example: true }, “Another”: { another: true }, } then what we can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)