元公務員のエンジニア。仕事、プライベートに悩みながらも前向きに生きたいと思ってる成人男性のブログ

ふりかえりって楽しい(2020.04.13 ~ 2020.04.19の週報)

今週考えていたこと


  • ふりかえり会をやる意味について
    • 短期的に達成したいこと
      • コミュニケーション不足の解消
      • コントローラブルなことに目を向けることでのストレス軽減
    • 中期的に達成したいこと
      • あんまり考えてなかったかも
        • まず短期の目標達成が優先
        • 先の計画を立てて行動するのが苦手
          • その時の状況、環境などを考慮して決めていけばいいのでは?
    • 長期的に達成したいこと
      • 会社の文化としてふりかえり会が定着している
        • 会社の文化って誰が作るの?
          • 会社にいる個人の良さがうまくマージ(溶け合って)して出来上がるものというイメージ
          • そうした時に考えるべきことは、自分の良さとか自分が得意なこと、好きなことを黙々とやっていくこと。
          • 意図して作ろうとすると、しらけた感じになりそう

フロント


  • TypeScriptの型
    • Literal型
    let clothSize: "small" | "medium" | "large" = "large"
    
    const cloth = {
    
    color: "white",
    
    size: clothSize
    
    }
    cloth.size = "small" // compile error
  • typeエイリアス
  • void型
    • TypeScriptは関数でundefinedを返すことを許していない
  • unknown型
    • anyより少し厳しい制約がある。
    • 基本的にanyと同じく代入できるが、代入した値を利用する時には、型を保証する必要がある
        let unkniwnInput: unknown
        
        let text: string
        
        unkniwnInput = "hello"
        
        text = unkniwnInput // Type 'unknown' is not assignable to type 'string'.
        
        if (typeof unkniwnInput === "string"){
        
        text = unkniwnInput
        
        }
  • TypeScriptのコンパイラ
    • tsconfig.json
      • include/exclude
      • sorceMap
        • ブラウザでTypeScriptをデバッグしたい時に使用する。
          • JavaScriptからTypeScriptを生成する際に使用される
  • TypeScriptでClassを使う
  • Interface
    • Objectの型
      • オブジェクトのみ利用可能 <=> Type
      • オブジェクトにはInterface, 変数はTypeを利用する
    • Interfaceを満たしているのであれば、問題なし
      • 部分的に構造を定義することが可能
    • Interfaceで関数の型を定義する
            interface addFunc {
              (num1: number, num2: number): number;
            }
  • インターセクション
        type NumberBoolean = number | boolean
        type StringNumber = string | number
        type Mix = NumberBoolean & StringNumber
        
        const TEST1 : Mix = "TEST" //  TS2322: Type '"TEST"' is not assignable to type 'number'.
        const TEST2 : Mix = true  //  TS2322: Type 'true' is not assignable to type 'number'.
        const TEST3 : Mix = 100
  • Type Guard
        class Dog {
          speak() {
            console.log("bow")
          }
        }
        
        class Bird {
          speak(){
            console.log("tweet")
          }
        
          fly(){
            console.log("fly")
          }
        }
        
        type Pet = Dog | Bird
        function havePet(pet: Pet) {
         if(pet instanceof Bird){ 
           pet.fly()
         }
        }
- [https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/instanceof](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/instanceof)
        // HTMLElement => HTMLInputElementへの型アサーション
        const input1 = <HTMLInputElement>document.getElementById("input")
        const input2 = document.getElementById("input") as HTMLInputElement // jsxを使用している時にはこちらの方が紛らわしくない
        (document.getElementById("input") as HTMLInputElement).value = "hogehoge"
        interface Designer {
          name: string;
          age: number;
          [index: string]: string
        } // TS2411: Property 'age' of type 'number' is not assignable to string index type 'string'.
        
        interface Designer{
          name: string;
          age: srting;
          [index: string]: string
        } // ok
  • 関数のオーバロード
        function toUpperCase(x: string): string;
        function toUpperCase(x: number): number;
        function toUpperCase(x: string | number): string | number {
          if (typeof x === "string"){
            return x.toUpperCase()
          }
          return x
        }
        
        const hello1 = toUpperCase("hello")// string
        const hello2 = toUpperCase(20) // number
  • Nullish Coalescing
        const downLoadData: DownLoadedData = {
          id: 1
        }
        
        const userData = downLoadData.user ?? "not-set" // undefined or null の時に「not-set」になる
[https://blog.jxck.io/entries/2019-08-14/nullish-coalescing-optional-chaining.html](https://blog.jxck.io/entries/2019-08-14/nullish-coalescing-optional-chaining.html)
  • LookUp型
    • objectのメンバー型を取得する方法
        interface DownLoadedData {
          id: number;
          user: {
            name?: {
              first: string;
              last: string
            }
          }
        }
        
        type id = DownLoadedData['id'] // number
        type user = DownLoadedData['user'] // user
        function copy<T>(value:T): T {
          return value
        }
        
        console.log(copy<string>("ddd").toUpperCase())

        class DataBase<T extends string | number | boolean> {
          private data:T[] = [];
          add(item: T){
            this.data.push(item)
          }
          remove(item: T){
            this.data.splice(this.data.indexOf(item), 1)
          }
          get(){
            return this.data
          }
        }
        
        const database1 = new DataBase<string>()
        database1.add("string-only")
        
        const database2 = new DataBase<number>()
        database2.add(11)
        
        const database3 = new DataBase<boolean>()
        database3.add(true)
  • kyeof
        // 柔軟なジェネリクスを作りたい時
        function copy<T extends {name: string}, U extends keyof T>(value:T, key: U) {
          return value[key]
        }
        
        copy({name: "test", age: 20}, "age)
        interface Todo {
          title: string;
          text: string;
        }
        
        type Todoable = Partial<Todo> // オプショナル型
        
        const todo: Todoable = {
          title: "s"
        }
  • conditional Types
        type ConditionalType1 = "tomato" extends string ? number : boolean // number
        type ConditionalType2 = string extends "tomato" ? number : boolean // boolean

バックエンド


                    buffer := make([]byte, 4)
                    size, err := io.ReadFull(reader, buffer)
                    r := strings.NewReader("some io.Reader stream to be read\n")
                    
                    if _, err := io.Copy(os.Stdout, r); err != nil {
                        log.Fatal(err)
                    }

その他


学習中


  • https://www.udemy.com/course/typescript-complete/
    • 体系的に学習したい & 倍速でサクッと学習したい
    • ハンズオンなのでわかりやすい
  • Goならわかるシステムプログラミング
    • 会社の上司に勧めらた本
    • 難易度高いな〜と感じてて寝かせてたけど、気合入れて読んでみたら意外と読めてる

Goならわかるシステムプログラミング(紙書籍+PDF版)

学習終了


ドメイン駆動設計入門 ボトムアップでわかる!ドメイン駆動設計の基本