The money-memory-React billing project uses some TypeScript, which is a superset of JavaScript. Now the TS knowledge used in the project is briefly summarized:

  1. UseState

    ([‘ clothes ‘, ‘food ‘,’ house ‘, ‘line ‘]); String [] represents an array of strings
    []>

  2. Type Keys = keyof typeof {‘-‘: ‘spending ‘, ‘+’:’ income ‘}; The type of the Keys is (” – “|” + “)

  3. JS and TS event delegate

// JS uses the event delegate, without declaring the type, to get the clicked element directly via e.target
const onClickButtonWrapper1 = (e) = > {
  consttext = e.targe.textContent; . }// TS uses event delegate, so you need to declare the type. If you do not declare the type, an error message will be reported
const onClickButtonWrapper2 = (e: React.MouseEvent) = > {
  const text = (e.target asHTMLButtonElement).textContent; . }Copy the code
  1. Partial<Type>Represents a subset of Type Type
type Xxx = {
   a: string;
   b: number;
   c: string[];
   d: "-" | "+";
}
// Yyy can have some of the attributes of Xxx
type Yyy = Partial<Xxx>

Copy the code
  1. type NewRecordItem = Omit<RecordItem, 'createAt'> OmitIndicates to exclude the ‘createAt’ type from the RecordItem type