0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

TypeScriptのInterfaceまとめ

Last updated at Posted at 2022-04-19

タイプエイリアスの復習

type Human = {
    name: string;
    age: number;
}

const human: Human = {
    name: "Quill",
    age: 38
}

let developer: Human;

Interfaceの定義

interface Human {
    name: string;
    age: number;
    greeting(message: string): void;
}

const human: Human = {
    name: "Quill",
    age: 38,
    greeting(message: string) {
        console.log(message);
    }
}

let developer: Human;

Interfaceで関数の型を定義する

interface addFunc {
    (num: number, num2: number): number;
}
let addFunc: addFunc;
addFunc = (n1: number, n2: number) => {
    return n1 + n2;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?