「TypeScript」typeof演算子のサンプル

書式
type クラス名 = {
メンバー変数名1:データの型;
メンバー変数名2:データの型;
};
const オブジェクト名:クラス名= {
変数名1:値1,
変数名2:値2
}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
type Student = {
username: string;
age: number;
};
const stu: Student = {
username: '山田太郎',
age: 32,
};
console.log("データの型: " + typeof 'tokyo');
console.log("データの型:" + typeof stu);
type Student = { username: string; age: number; }; const stu: Student = { username: '山田太郎', age: 32, }; console.log("データの型: " + typeof 'tokyo'); console.log("データの型:" + typeof stu);
type Student = {
  username: string;
  age: number;
};

const stu: Student = {
  username: '山田太郎',
  age: 32,
};

console.log("データの型: " + typeof 'tokyo'); 
console.log("データの型:" + typeof stu);

実行結果
C:\typescript>tsc
C:\typescript>ts-node arkgame.js
データの型: string
データの型:object

TypeScript

Posted by arkgame