type staffsKeys = {
     name: string, 
     salary: number
}

function getProperty<T extends staffsKeys, K extends keyof staffsKeys>(obj: T, key: K): T[K] {
return obj[key];
}/*
What are Generics?
Generics have been a major feature of strongly typed languages 
like Java and C#. In TypeScript, they allow the types of components 
and functions to be "SPECIFIED LATER" which allows them to be used 
in creating reusable components that can apply to different use cases, 

for example:
*/

function returnInput <Type>(arg: Type): Type {
  return arg;
};
const returnInputStr = returnInput<string>('Foo Bar');
const returnInputNum = returnInput<number>(5);

console.log(returnInputStr); // Foo Bar
console.log(returnInputNum); // 5function identity<T>(arg: T): T {    
    return arg;    
}    
let output1 = identity<string>("myString");    
let output2 = identity<number>( 100 );  
console.log(output1);  
console.log(output2);  function firstElement<Type>(arr: Type[]): Type {
  return arr[0];
}
// s is of type 'string'
const s = firstElement(["a", "b", "c"]);
// n is of type 'number'
const n = firstElement([1, 2, 3]);function identity<Type>(arg: Type): Type {
  return arg;
}
 
let myIdentity: <Input>(arg: Input) => Input = identity;   function identity<T>(arg: T): T {
      return arg;
    }


let fun = identity<string>("hello");
console.log(fun);   

/*T is shorthand for Type, meaning "you can specify the data type later"*/class Greeter<T> {
  greeting: T
  constructor(message: T) {
    this.greeting = message
  }
}

let greeter = new Greeter<string>('Hello, world')function identity<T>(arg: T): T {
  return arg;
}Tryconst clone = <T>(object: T) => {
  const clonedObject: T = JSON.parse(JSON.stringify(object));
  return clonedObject;
};

const obj = {
  a: 1,
  b: {
    c: 3,
  },
};

const obj2 = clone(obj);function firstElement<Type>(arr: Type[]): Type | undefined {
  return arr[0];
}const valueWrapper = <T>(value: T): T[] => {
  return [value];
};

console.log(valueWrapper<number>(10));

TypeScript相关代码片段

emit an argument for event is not provided

eslint with typescript and nodejs

exists status

how to check text length in angular

get current time ts

cannot import bcrypt

reset form in angular typescript

nextjs get url params api app route

select between brackets vscode macbook

vercel config for express

jest it sleep

tailwindcss-debug-screens

MY_MOMENT_FORMATS LT

nextjs multiple image hostnames

DatetimeFormatOptions typescript

typescript generic

typescript Dictionary

npm circuit breaker

angular httpinterceptor + for file uploads

comments using regex

nestjs client streaming grpc client

nodejs curicuit breaker

data table tanstack custom pagination number

typescript interface react

typescript get keys of type

jest testing ts

jest sleep between tests too many requests

disable prop types eslint

exports is not defined

ts any key in object

cypress configure browser size

i18next change language

i18n change language

nextjs 14 route api creation

i18next check current language

arc shortcuts windows

sequelize relation where

typescript omit for enums

setup TypeScript in tsconfig.json

typescript is checking types from user directory

vite.config.ts resolve

zod one of string

sequelize where relationship

collapsable sidebar shadcn

ts disable its value is never used

rtk query programmatically

papa parse convert to object

Overflow:hidden dots at the end

awaited typescript

typescript print to console

git how to view all commits before push

how to use external fonts in react

change shadcn select placeholder color

ts get type of object values

How to add todo

zod error message

tailwindcss screen debugger in nextjs

does fcm automatically starts on reboot?

run vite app

max amount validator

redis client type typescript

omit more than one typescript

vscode md snippets for mdx also

check if user exists firebase

add custom class in tailwindcss

initialize array of specific size

typescript create type from array of strings

shadcn dialog programmatically

nodejs file stream

observablehq copy data

object is possibly 'null'.ts(2531)

start a typescript backend nodejs

nestjs http module

typing when fetching data in ts

ts nspell usage

Custom Painting Template

export import ts interface

how to add fonts to flutter

sequelize literal attributes

passing react component as variables