Microsoft�́A�����̐V�@�\�����I�[�v���\�[�X�v���O���~���O����̍ŐV�ŁuTypeScript 3.7�v�����J�����B�I�v�V���i���`�F�C�j���O�̎�����nullish coalescing���Z�q�̓����Ƃ��������P���������B
���̋L���͉������ł��B����o�^�i�����j����ƑS�Ă������������܂��B
�@Microsoft��2019�N11��5���i�č����ԁj�A�I�[�v���\�[�X�̃v���O���~���O����̍ŐV�ŁuTypeScript 3.7�v�����J�����B
�@TypeScript�́A�ÓI�^�t�����ł��錾��ŁAJavaScript�̃X�[�p�[�Z�b�g�BECMA�K�i�ɏ]�����ŐV��JavaScript�̋@�\���A�Â�Web�u���E�U����^�C����������悤�ɃR���p�C�����邱�Ƃ��ł���B
�@TypeScript 3.7�́ANuGet���g�����A���̃R�}���h���C���̂悤�ɁAnpm���g���ăC���X�g�[���ł���B
npm install typescript
�@TypeScript 3.7�́uVisual Studio 2019�v�uVisual Studio 2017�v�̑��A�uVisual Studio Code�v�ƁuSublime Text�v�ł����p�ł���BTypeScript 3.7�̎�ȓ����͎��̒ʂ�B
�@TypeScript�̃r���g�C���t�H�[�}�b�^�[�ɂ����ǂ��������BJavaScript�̎����Z�~�R�����}���iASI�j���[���ɂ���āA�s���̃Z�~�R�������I�v�V�����ƂȂ��Ă���ꏊ�ŁA�Z�~�R�����̑}���ƍ폜���������ł���悤�ɂȂ����B
�@���̐ݒ�́uVisual Studio Code Insider�v�ŗ��p�ł��A�uVisual Studio 16.4 Preview 2�v�ł��A�u�c�[���I�v�V�����v���j���[�ŗ��p�ł���B
�@�uinsert�v�i�}���j�܂��́uremove�v�i�폜�j�̒l��I�ԂƁATypeScript�T�[�r�X�Œ���鎩���C���|�[�g�⒊�o�����^�A���̐����R�[�h�̃t�H�[�}�b�g�ɂ��e������B�ݒ���f�t�H���g�l�uignore�v�i�����j�̂܂܂ɂ���ƁA���݂̃t�@�C���Ō��o���ꂽ�Z�~�R�����̌X���ɍ��킹�Đ����R�[�h�𐮌`����B
�@TypeScript��Web�T�C�g�ŏ㕔�̃^�u����A�N�Z�X�ł�������́uPlayground�v�i���p�T�C�g�j�ł́A�v���ȃG���[�C����_�[�N�^�n�C�R���g���X�g���[�h�A���̃p�b�P�[�W���C���|�[�g����ۂ̎����I�Ȍ^�擾�Ƃ������V�@�\�����p�ł���悤�ɂȂ����B
�@����ɁA�uWhat's new�v���j���[����A�C���^���N�e�B�u�ȃR�[�h�X�j�y�b�g���g����TypeScript 3.7�̐V�@�\�̉�����{���ł���B
�@�����āATypeScript��Web�T�C�g�̉E����Ɍ����t�B�[���h��p�ӂ��A�n���h�u�b�N����[�X�m�[�g�Ȃǂ�ΏۂɃL�[���[�h�������ł���悤�ɂȂ����B���̌����@�\�́A����API�T�[�r�X�uAlgolia�v���g���Ē���Ă���B
�@TypeScript 3.7�ł́AECMAScript�ōł��v�]�̍����@�\�̈�ł���I�v�V���i���`�F�C�j���O�����������B
�@�I�v�V���i���`�F�C�j���O�̊�{�I�ȓ����́A���s����null��undefined�����������ꍇ�A���̎��s���ɒ�~�ł���悤�ȃR�[�h���쐬�\�ɂ��邱�Ƃ��B���̂��߂ɃI�v�V�����v���p�e�B�A�N�Z�X�Ɍ����ĐV�����u?.�v���Z�q��lj������B
let x = foo?.bar.baz();
�@�Ⴆ�A���̃R�[�h�X�j�y�b�g�́A���̂悤�ȋL�q�Ɠ������ƂɂȂ�B
let x = (foo === null || foo === undefined) ?
undefined :
foo.bar.baz();
�@nullish coalescing���Z�q�́A�I�v�V���i���`�F�C�j���O�Ɩ��ڂɊW����ECMAScript�̋@�\���B���Z�q�Ƃ��āu??�v��p����B
�@���̋@�\�́Anull��undefined����������ۂɁA�f�t�H���g�l�Ɂg�t�H�[���o�b�N����h��@�̈���B
let x = foo ?? bar();
�@�Ⴆ�A���̃R�[�h�X�j�y�b�g�Ɠ����������������邽�߂ɁA����܂ł͎��̂悤�ɋL�q���Ă����B
let x = (foo !== null && foo !== undefined) ?
foo :
bar();
�@�\�����ʏ�Ԃ���������ƁA�G���[���X���[�ithrow�j�����������B�����������́g�A�T�[�V�����h���ƌĂ��B
�@TypeScript 3.7�ł́A�A�T�[�V�����������f��������g�A�T�[�V�����V�O�l�`���h�Ƃ����V�����l�����������B
�@�A�T�[�V�����V�O�l�`���̓�����Ƃ̈�Ƃ��āA�ǂ��łǂ̊����Ăяo����邩�����ڍׂɃG���R�[�h����K�v���������B���̂��Ƃ��Anever��Ԃ����̃T�|�[�g���g�傷�邫�������ɂȂ����Ƃ����B
�@����never��Ԃ��̂́A��O���X���[�������A��~�G���[�����������������A�v���O�������I���������̂����ꂩ�ɊY������B
�@TypeScript�ł͂���܂ŁA����undefined��Ԃ����\�����Ȃ����ƁA���邢�͑S�ẴR�[�h�p�X������ʓI�ɖ߂�Ȃ��������Ƃ��m�F����ɂ́A���̂悤�ɁA���̖����ɃV���^�b�N�X��̃V�O�i���ireturn�܂���throw�j���K�v�������B���̂悤�ɂ��ă��[�U�[�́A���s��������return����悤�ɂ��Ă����B
function dispatch(x: string | number): SomeType {
if (typeof x === "string") {
return doThingWithString(x);
}
else if (typeof x === "number") {
return doThingWithNumber(x);
}
return process.exit(1);
}
�@TypeScript 3.7�ł́A��������never��Ԃ������Ăяo�����ƁA�����̊�������t���[�O���t�ɉe�����邱�Ƃ�F�����A�Ώ�����悤�ɂȂ����B
function dispatch(x: string | number): SomeType {
if (typeof x === "string") {
return doThingWithString(x);
}
else if (typeof x === "number") {
return doThingWithNumber(x);
}
process.exit(1);
}
�@TypeScript�ł́A�u--declaration�v�t���O���g���āA�u.ts�v��u.tsx�v�t�@�C���̂悤�ȃ\�[�XTypeScript�t�@�C������A�u.d.ts�v�t�@�C���i�錾�t�@�C���j���ł���B.d.ts�t�@�C�����g�p����ƁA�I���W�i���̃\�[�X�R�[�h���ă`�F�b�N�A�r���h���邱�ƂȂ��A���̃v���W�F�N�g�ɑ��Č^�`�F�b�N���s�����Ƃ��ł���B
�@�c�O�Ȃ���A--declaration�ɂ́A����܂Ő������������BTypeScript��JavaScript�̓��̓t�@�C���������ł���u--allowJs�v�̂悤�Ȑݒ�ƂƂ��Ɏg���Ȃ������̂��B
�@TypeScript 3.7�ł́A����2�̋@�\��g�ݍ��킹�ė��p�ł���悤�ɂȂ����B--allowJs���g���ꍇ�ATypeScript�̓x�X�g�G�t�H�[�g��JavaScript�\�[�X�R�[�h�𗝉����A�����̕\����.d.ts�t�@�C���ɕۑ�����B�Ⴆ�A���̂悤�ȃR�[�h���������Ƃ��悤�B
/**
* @callback Job
* @returns {void}
*/
/** Queues work */
export class Worker {
constructor(maxDepth = 10) {
this.started = false;
this.depthLimit = maxDepth;
/**
* NOTE: queued jobs may add more items to queue
* @type {Job[]}
*/
this.queue = [];
}
/**
* Adds a work item to the queue
* @param {Job} work
*/
push(work) {
if (this.queue.length + 1 > this.depthLimit) throw new Error("Queue full!");
this.queue.push(work);
}
/**
* Starts the queue if it has not yet started
*/
start() {
if (this.started) return false;
this.started = true;
while (this.queue.length) {
/** @type {Job} */(this.queue.shift())();
}
return true;
}
}
�@���̃R�[�h�����̂悤��.d.ts�t�@�C���ɕϊ�����B
/**
* @callback Job
* @returns {void}
*/
/** Queues work */
export class Worker {
constructor(maxDepth?: number);
started: boolean;
depthLimit: number;
/**
* NOTE: queued jobs may add more items to queue
* @type {Job[]}
*/
queue: Job[];
/**
* Adds a work item to the queue
* @param {Job} work
*/
push(work: Job): void;
/**
* Starts the queue if it has not yet started
*/
start(): boolean;
}
export type Job = () => void;
�@�^�G�C���A�X�ɂ͏�ɁA�ċA�I�ȎQ�Ƃ��g�����ꍇ�ɐ������������B�^�G�C���A�X�́A�ǂ̂悤�Ɏg�p����ꍇ�ł��A���g���\���^��K����ւł��Ȃ���Ȃ�Ȃ����炾�B�����ꍇ�ɂ���Ă͎����s�\�ł���B���̂��߃R���p�C���́A���̂悤�ȓ���̍ċA�I�ȃG�C���A�X��r�����Ă����B
type Foo = Foo;
�@TypeScript 3.7�ł́A�^�G�C���A�X�́g�g�b�v���x���h�Ō^�����̉������摗�肳�ꂽ�B�Ⴆ�AJSON��\�����鎟�̂悤�ȃR�[�h���ɋ����悤�B
type Json =
| string
| number
| boolean
| null
| JsonObject
| JsonArray;
interface JsonObject {
[property: string]: Json;
}
interface JsonArray extends Array<Json> {}
�@TypeScript 3.7�ł̓w���p�[�C���^�t�F�[�X���g�킸�ɁA���̂悤�ɏ�����������悤�ɂȂ����B
type Json =
| string
| number
| boolean
| null
| { [property: string]: Json }
| Json[];
�@�܂��A����̐����ɘa�ɂ��A�^�v���Ō^�G�C���A�X���ċA�I�ɎQ�Ƃ��邱�Ƃ��\�ɂȂ����B����܂ł̓G���[���������̃R�[�h���A�L����TypeScript�R�[�h�ɂȂ�B
type VirtualNode =
| string
| [string, { [key: string]: any }, ...VirtualNode[]];
const myNode: VirtualNode =
["div", { id: "parent" },
["div", { id: "first-child" }, "I'm the first child"],
["div", { id: "second-child" }, "I'm the second child"]
];
�@Microsoft�́A�p�u���b�N�N���X�t�B�[���h�̕W�����������̑z��Ƃ͈قȂ�����ɐi�݂����Ȃ��ƂɑΉ����ATypeScript�֏��X�ɕύX�������Ă���B���̈�Ƃ��āA�V�����uuseDefineForClassFields�v�t���O������B���̃t���O�ɂ��ω��̂����A�ł��傫�Ȃ��͎̂���2���B
�@����ɂ��A�p�����g�p��������R�[�h�ɂ��܂��܂ȉe�����y�ԁB��1�ɁA�x�[�X�N���X����́uset�v�A�N�Z�T���g���K�[�̑ΏۂƂȂ炸�A���S�ɏ㏑�������B
�@��2�ɁA�N���X�t�B�[���h���g���āA�x�[�X�N���X����̃v���p�e�B����ʂɏ������邱�Ƃ��ł��Ȃ��B
�@���̂��Ƃ���A�v���p�e�B�ƃA�N�Z�T��g�ݍ��킹��ƁA��肪�N���邱�Ƃ��\�z�ł���B����ɁA�C�j�V�����C�U�[���Ȃ��v���p�e�B�̍Đ錾���A���ɂȂ���B
�@TypeScript 3.7�́A�A�N�Z�T�Ɋւ���������o���邽�߁A�u.d.ts�v�t�@�C���́uget/set�v�A�N�Z�T���G�~�b�g�ɂ���B����ɂ����TypeScript���A�㏑�����ꂽ�A�N�Z�T���`�F�b�N�ł���B
�@�N���X�t�B�[���h�̕ύX�ʼne������R�[�h�́A�t�B�[���h�C�j�V�����C�U�[���R���X�g���N�^�{�̂̊��蓖�Ăɕϊ����邱�ƂŁA��������ł���B
class Base {
set data(value: string) {
console.log("data changed to " + value);
}
}
class Derived extends Base {
constructor() {
this.data = 10;
}
}
�@��قǏЉ����2�̖����y�����邽�߁A�����I�ȃC�j�V�����C�U�[��lj�������A�v���p�e�B�ɂ�emit���Ȃ����Ƃ�����declare�C���q��lj������肷�邱�Ƃ��ł���B
interface Animal { animalStuff: any }
interface Dog extends Animal { dogStuff: any }
class AnimalHouse {
resident: Animal;
constructor(animal: Animal) {
this.resident = animal;
}
}
class DogHouse extends AnimalHouse {
declare resident: Dog;
// ^^^^^^^
// 'resident' now has a 'declare' modifier,
// and won't produce any output code.
constructor(dog: Dog) {
super(dog);
}
}
�@Microsoft�ɂ��ƁA���݁AECMASscript 5�iES5�j�ȍ~���^�[�Q�b�g�Ƃ���ꍇ�́AuseDefineForClassFields�݂̂����p�ł���BES3�ɂ�Object.defineProperty�����݂��Ȃ����炾�B
�@TypeScript�̃v���W�F�N�g�Q�Ƃ��g���ƁA�R�[�h�x�[�X�����ăR���p�C����e�Ղɍ������ł���B�������ˑ��W��ݒ肵�Ă��Ȃ�������A�R�[�h���Â������肷��Ɠ��삵�Ȃ��B
�@TypeScript 3.7�ł́A�ˑ��W�̂���v���W�F�N�g���J���ꍇ�A�����n�������I�Ƀ\�[�X��.ts�^.tsx�t�@�C�����g�p����B����ɂ��A�Z�}���e�B�b�N���삪�ŐV�ɂȂ��Ă��āA������Ƌ@�\���Ă���A�v���W�F�N�g�Q�Ƃ��g�p����v���W�F�N�g�ł����Ă��A�ҏW�G�N�X�y���G���X�����シ��B
�@���̂悤�ȋ������K�v�Ȃ��ꍇ�́A�R���p�C���I�v�V�����udisableSourceOfProjectReferenceRedirect�v�Ŗ����ɂł���B
�@���̌Ăяo����Y���̂́A�v���O���}�[�ɂƂ��Ē��������Ƃł͂Ȃ����A�댯���B���Ɉ������Ȃ�������A�v���p�e�B�Ǝv����悤�Ȗ��O���t���Ă����肷��ꍇ�ɖY��₷���B
�@�Ⴆ�A���̃R�[�h�́A�uisAdministrator�v���Ăяo���̂�Y��Ă���A�Ǘ��҈ȊO�̃��[�U�[�ł����Ă��\����ҏW�ł��Ă��܂��B
interface User {
isAdministrator(): boolean;
notify(): void;
doNotDisturb?(): boolean;
}
// later...
// Broken code, do not use!
function doAdminThing(user: User) {
// oops!
if (user.isAdministrator) {
sudo();
editTheConfiguration();
}
else {
throw new AccessDeniedError("User is not an admin");
}
}
�@TypeScript 3.7�ł́A���̂悤�ȕ�������肵�āA���̂悤�ɁA���̂���ӏ���`����B
function doAdminThing(user: User) {
if (user.isAdministrator) {
// ~~~~~~~~~~~~~~~~~~~~
// error! This condition will always return true since the function is always defined.
// Did you mean to call it instead?t
�@����̃`�F�b�N�@�\�͂���܂ł�TypeScript�̋����Ƃ��Ȃ�قȂ�B���̂��߁A���Ɂu�ێ�I�v�ȓ��������悤�ɂ����B�G���[�肷��̂�if���������B�܂�A�I�v�V�����v���p�e�B��strictNullChecks���I�t�̏ꍇ��A��ق�if�̖{�̓��Ŋ����Ăяo����Ă���ꍇ�ɂ́A���̗�̂悤�ɃG���[�ɂ͂Ȃ�Ȃ��B
interface User {
isAdministrator(): boolean;
notify(): void;
doNotDisturb?(): boolean;
}
function issueNotification(user: User) {
if (user.doNotDisturb) {
// OK, property is optional
}
if (user.notify) {
// OK, called the function
user.notify();
}
}
�@TypeScript�ł́A�����P���ȃR�[�h�������G���[���b�Z�[�W��\�������Ă��܂��ꍇ������B�Ⴆ�A���̂悤�ȃR�[�h���L�q�����Ƃ��悤�B
type SomeVeryBigType = { a: { b: { c: { d: { e: { f(): string } } } } } }
type AnotherVeryBigType = { a: { b: { c: { d: { e: { f(): number } } } } } }
declare let x: SomeVeryBigType;
declare let y: AnotherVeryBigType;
y = x;
�@TypeScript�̏]���o�[�W�����ł́A���̂悤�ȃG���[���b�Z�[�W��\�����Ă����B
Type 'SomeVeryBigType' is not assignable to type 'AnotherVeryBigType'.
Types of property 'a' are incompatible.
Type '{ b: { c: { d: { e: { f(): string; }; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: { f(): number; }; }; }; }; }'.
Types of property 'b' are incompatible.
Type '{ c: { d: { e: { f(): string; }; }; }; }' is not assignable to type '{ c: { d: { e: { f(): number; }; }; }; }'.
Types of property 'c' are incompatible.
Type '{ d: { e: { f(): string; }; }; }' is not assignable to type '{ d: { e: { f(): number; }; }; }'.
Types of property 'd' are incompatible.
Type '{ e: { f(): string; }; }' is not assignable to type '{ e: { f(): number; }; }'.
Types of property 'e' are incompatible.
Type '{ f(): string; }' is not assignable to type '{ f(): number; }'.
Types of property 'f' are incompatible.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
�@���̃G���[���b�Z�[�W�͐��������A�����悤�ȃe�L�X�g�����炸��ƕ��сA���[�U�[�ɂƂ��Ă͔ς킵���A�d�v�ȏ��������ɂ����B
�@������TypeScript 3.7�ł́A���̂悤�ɊȌ��ɃG���[���b�Z�[�W��\������悤�ɂ����B
Type 'SomeVeryBigType' is not assignable to type 'AnotherVeryBigType'.
The types returned by 'a.b.c.d.e.f()' are incompatible between these types.
Type 'string' is not assignable to type 'number'.
�@TypeScript 3.7�ł́ATypeScript�t�@�C���̐擪�Ɂu// @ts-nocheck�v�R�����g��lj����邱�ƂŁA�Z�}���e�B�b�N�`�F�b�N���ɂł���悤�ɂȂ����B
�@���̃R�����g�͂���܂ŁAcheckJs���g���ꍇ��JavaScript�\�[�X�t�@�C���ł̂ݗp�����Ă������A�S�Ẵ��[�U�[���ȒP�Ɉڍs�ł���悤�ɁATypeScript�t�@�C���ł��V���ɃT�|�[�g�����B
Microsoft�A�v���O���~���O����uTypeScript 3.7�v�̃��ł����J
Microsoft�A�v���O���~���O����uTypeScript 3.6�v�����J
Python��Java��ǂ������ASlashData�̊J���Ҏ�������Copyright © ITmedia, Inc. All Rights Reserved.
��IT eBook