-
Notifications
You must be signed in to change notification settings - Fork 1.4k
docs: translate Built-in utility types to Japanese #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
//// { order: 3, compiler: { strictNullChecks: true } } | ||
|
||
// ある型がほとんどのコードベースで有効性があると感じられた場合、 | ||
// その型はTypeScriptに追加され、他の誰もが使えるようになります。 | ||
// TypeScriptに追加されたら、いつでもその型が使えることが | ||
// 保証されます。 | ||
|
||
// Partial<Type> | ||
|
||
// オブジェクト型を型引数として受け取り、そのプロパティを | ||
// すべて任意プロパティへと変換します。 | ||
|
||
interface Sticker { | ||
id: number | ||
name: string | ||
createdAt: string | ||
updatedAt: string | ||
submitter: undefined | string | ||
} | ||
|
||
type StickerUpdateParam = Partial<Sticker> | ||
|
||
|
||
// Readonly<Type> | ||
|
||
// オブジェクト型を型引数として受け取り、そのプロパティを読み取り専用にします。 | ||
|
||
type StickerFromAPI = Readonly<Sticker> | ||
|
||
|
||
// Record<KeysFrom, Type> | ||
|
||
// KeysFrom からプロパティの一覧を受け取り、 | ||
// 各プロパティの値をType型にした型を作成します。 | ||
|
||
// 型キーの一覧: | ||
type NavigationPages = 'home' | 'stickers' | 'about' | 'contact' | ||
|
||
// 上記キーに対応するデータの型: | ||
interface PageInfo { | ||
title: string | ||
url: string | ||
axTitle?: string | ||
} | ||
|
||
const navigationInfo: Record<NavigationPages, PageInfo> = { | ||
home: { title: 'Home', url: '/' }, | ||
about: { title: 'About', url: '/about' }, | ||
contact: { title: 'Contact', url: '/contact' }, | ||
stickers: { title: 'Stickers', url: '/stickers/all' }, | ||
} | ||
|
||
// Pick<Type, Keys> | ||
|
||
// 型の第一引数に受け取ったオブジェクトから、第二引数に任意のプロパティ名を定義して | ||
// そのプロパティと対応する値の型を持つ型を作成します。 | ||
// 型のホワイトリストのようなものです。 | ||
|
||
type StickerSortPreview = Pick<Sticker, 'name' | 'updatedAt'> | ||
|
||
|
||
// Omit<Type, Keys> | ||
|
||
// 型の第一引数に受け取ったオブジェクトから、第二引数に任意のプロパティ名を定義して | ||
// そのプロパティを除外した型を作成します。 | ||
// 型のブラックリストのようなものです。 | ||
|
||
type StickerTimeMetadata = Omit<Sticker, 'name'> | ||
|
||
|
||
// Exclude<Type, RemoveUnion> | ||
|
||
// 型の第一引数に受け取ったユニオン型から、第二引数に受け取ったユニオン型を | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 共用体型でも良いかもしれない There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 共用体型は馴染みがなさそう‥と思ったけど、Union Type の説明文はおそらく共用体型になりそうと思ったので共用体型に変えました。:+1: |
||
// 除外した型を作成します。 | ||
|
||
type HomeNavigationPages = Exclude<NavigationPages, 'home'> | ||
|
||
|
||
// Extract<Type, MatchUnion> | ||
|
||
// 型の第一引数に受け取ったユニオン型から、第二引数に受け取ったユニオン型に | ||
// 当てはまる型を作成します。 | ||
|
||
type DynamicPages = Extract<NavigationPages, 'home' | 'stickers'> | ||
|
||
|
||
// NonNullable<Type> | ||
|
||
// 型引数に受け取ったユニオン型から、nullとundefinedを除外した型を返します。 | ||
// 値のバリデーションに使えるでしょう。 | ||
|
||
type StickerLookupResult = Sticker | undefined | null | ||
type ValidatedResult = NonNullable<StickerLookupResult> | ||
|
||
|
||
// ReturnType<Type> | ||
|
||
// 型引数に受け取った関数型から、その返り値の型を作成します。 | ||
|
||
declare function getStickerByID(id: number): Promise<StickerLookupResult> | ||
type StickerResponse = ReturnType<typeof getStickerByID> | ||
|
||
|
||
// InstanceType<Type> | ||
|
||
// クラスインスタンス、またはコンストラクタ関数を持つオブジェクトから、 | ||
// そのインスタンスの型を作成します。 | ||
|
||
class StickerCollection { | ||
stickers: Sticker[] | ||
} | ||
|
||
type CollectionItem = InstanceType<typeof StickerCollection> | ||
|
||
|
||
// Required<Type> | ||
|
||
// 型引数に受け取ったオブジェクト型からオプショナルのプロパティをすべて | ||
// 必須に変換した型を作成します。 | ||
|
||
type AccessiblePageInfo = Required<PageInfo> | ||
|
||
|
||
// ThisType<Type> | ||
|
||
// 他の型とは違い、ThisTypeは新しい型を返しません。 | ||
// 関数で使われる this の型を型引数に受け取った型に変換します。 | ||
// ThisType は TSConfig の noImplicitThis が true | ||
// の場合にしか使えません。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nits] 上記と同じく、半角スペースの件です
|
||
|
||
// https://www.typescriptlang.org/docs/handbook/utility-types.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nits]
KeysFrom から
英単語の日本語の境界に半角スペースが入っています。基本的には英日単語境界の半角スペースは不要と思うのですが、どうでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
個人的にはスペースあったほうが読みやすいと感じます。
ただ、Textlint無い状態で、句読点の後等色んなケースを考えると、スペース無しで統一したほうが良いと思います。:+1:
スペース無しに修正しましたー
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇