What do you want to save?
Add Code snippet
New code examples
-
TypeScript 2021-11-05 03:15:21
typescript use object keys as index
{ [key in keyof IUser]: boolean } Add solution -
Javascript 2021-10-27 13:10:13
javascript nameof
// TypeScript // NameOf.ts export const NameOf = <T>(name: keyof T) => name; // Setup class User { Name: string; Age: number; } // Usage import {NameOf} from './NameOf'; function UseNameOf() { console.log(NameOf<User>('Name')); } /... Add solution -
TypeScript 2021-10-23 06:17:10
typescript keyof
interface Person { name: string; age: number; location: string; } type K1 = keyof Person; // "name" | "age" | "location" type K2 = keyof Person[]; // "length" | "push" | "pop" | "conc... Add solution -
TypeScript 2021-10-21 10:22:04
typescript valueof interface
type ValueOf<T> = T[keyof T]; Add solution -
Javascript 2021-09-30 21:26:04
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type { }. No index signature with a parameter of type 'string' was found on type '{ develop: string; staging: string; production: string; }'.ts(7053)
const DNATranscriber = { G: 'C', C: 'G', T: 'A', A: 'U' }; export default class Transcriptor { toRna(dna: string) { const codons = [...dna]; if (!isValidSequence(codons)) { throw Error('invalid sequence'); ... Add solution -
TypeScript 2021-09-20 21:27:03
deep partial typescript
//You can simply create a new type, say, DeepPartial, which basically references itself: type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]>; }; //Then, you can use it as such: const foobar: DeepPartial<Foobar> = { foo: 1, ... Add solution -
Other 2021-09-12 19:16:02
typescript template literal dot notation
type PathImpl<T, Key extends keyof T> = Key extends string ? T[Key] extends Record<string, any> ? | `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` | `${Key}.${Exclude<keyof T[Key], ke... Add solution