---
title: "Xin shen (@lihua) | Hashnode"
description: "Xin shen (@lihua) writes on Hashnode. Read their latest articles and follow their work."
url: "https://hashnode.com/@lihua"
---

@lihua

# Xin shen

@lihua · China Beijing · Joined April 2022

### [Rails add foreign key](https://lihua.hashnode.dev/rails-add-foreign-key?utm_source=hashnode&utm_medium=feed)

when we want to add a foreign key in Rails we can run this command bin/rails g migration add\_author\_to\_books author:references this means one author has one or more books in the database class AddAuthorToBooks < ActiveRecord::Migration\[7.0\] def ch...

1 min read · [lihua.hashnode.dev](https://lihua.hashnode.dev/rails-add-foreign-key?utm_source=hashnode&utm_medium=feed)

[Nov 30, 2022](https://hashnode.com/posts/rails-add-foreign-key/638756ee8b7b2fc48626f8c5)

### [测试 React 应用](https://lihua.hashnode.dev/react?utm_source=hashnode&utm_medium=feed)

使用 create-react-app 除了 Jest 之外，我们还需要另一个测试库，它将帮助我们以测试目的渲染组件。 目前最好的选择是react-testing-library ，这个库在最近几年迅速流行起来。 npm install --save-dev @testing-library/react @testing-library/jest-dom 依赖项 "dependencies": { "@testing-library/jest-dom": "^5.14.1", ...

1 min read · [lihua.hashnode.dev](https://lihua.hashnode.dev/react?utm_source=hashnode&utm_medium=feed)

[Apr 22, 2022](https://hashnode.com/posts/react/626241f3d82f4558aff86c9a)

### [type 和 interface 的区别是什么？](https://lihua.hashnode.dev/type-interface?utm_source=hashnode&utm_medium=feed)

组合方式: interface 使用extends来实现继承，type 使用&来实现联合类型。 扩展方式: interface 可以重复声明用来扩展，type 一个类型只能声明一次 范围不同: type 适用于基本类型，interface 一般不行。 命名方式: interface 会创建新的类型名，type 只是创建类型别名，并没有新创建类型。

1 min read · [lihua.hashnode.dev](https://lihua.hashnode.dev/type-interface?utm_source=hashnode&utm_medium=feed)

[Apr 22, 2022](https://hashnode.com/posts/type-interface/626236d10f819f588af7361a)

### [Git中只merge部分commit](https://lihua.hashnode.dev/gitmergecommit?utm_source=hashnode&utm_medium=feed)

cherry-pick 在Git 1.7.2以上的版本引入了一个 cheery-pick的命令可以只merge 部分的commit而不用直接把整个分支merge过来 git cherry-pick <commit 号> 如： git cherry-pick e43a6fd3e94888d76779ad79fb568ed180e5fcdf 这样就只会把这个e43a6fd3e94888d76779ad79fb568ed180e5fcdf commit的内容pull到当前的分支，不过你会得到一个新的c...

1 min read · [lihua.hashnode.dev](https://lihua.hashnode.dev/gitmergecommit?utm_source=hashnode&utm_medium=feed)

[Apr 22, 2022](https://hashnode.com/posts/gitmergecommit/6262368ad82f4558aff86ad2)

### [TypeScript](https://lihua.hashnode.dev/typescript?utm_source=hashnode&utm_medium=feed)

Type声明基本类型 声明字符串类型 type Name = string const str:Name= 'bot 声明 字符串或数字类型 type Id = string|number const id1:Id = '123' const id2:Id = 123 同时满足两种类型类型为never（写错了可能） type wrongType = string & number 可选类型 type User = { name:string age?:number } c...

1 min read · [lihua.hashnode.dev](https://lihua.hashnode.dev/typescript?utm_source=hashnode&utm_medium=feed)

[Apr 18, 2022](https://hashnode.com/posts/typescript/625cff9f740c26066de656e6)
