Pro TypeScript: Application-Scale JavaScript Development 2nd Edition Steve Fenton All Chapters Instant Download
Pro TypeScript: Application-Scale JavaScript Development 2nd Edition Steve Fenton All Chapters Instant Download
com
https://textbookfull.com/product/pro-typescript-application-
scale-javascript-development-2nd-edition-steve-fenton/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/pro-typescript-application-scale-
javascript-development-second-edition-fenton/
textboxfull.com
https://textbookfull.com/product/essential-typescript-4-from-beginner-
to-pro-2nd-edition-adam-freeman/
textboxfull.com
https://textbookfull.com/product/essential-typescript-from-beginner-
to-pro-1st-edition-adam-freeman/
textboxfull.com
https://textbookfull.com/product/essential-typescript-4-from-beginner-
to-pro-second-edition-adam-freeman/
textboxfull.com
Angular Development with Typescript Second Edition Yakov
Fain
https://textbookfull.com/product/angular-development-with-typescript-
second-edition-yakov-fain/
textboxfull.com
https://textbookfull.com/product/protein-downstream-processing-design-
development-and-application-of-high-2nd-edition/
textboxfull.com
https://textbookfull.com/product/pro-jquery-in-oracle-application-
express-wesley-scott/
textboxfull.com
Pro TypeScript
Application-Scale JavaScript Development
—
Second Edition
—
Steve Fenton
Pro TypeScript
Application-Scale JavaScript
Development
Second Edition
Steve Fenton
Pro TypeScript: Application-Scale JavaScript Development
Steve Fenton
Basingstoke, United Kingdom
ISBN-13 (pbk): 978-1-4842-3248-4 ISBN-13 (electronic): 978-1-4842-3249-1
https://doi.org/10.1007/978-1-4842-3249-1
Library of Congress Control Number: 2017961729
Copyright © 2018 by Steve Fenton
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction
on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation,
computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this
legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically
for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work.
Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the
Publisher's location, in its current version, and permission for use must always be obtained from Springer. Permissions
for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution
under the respective Copyright Law.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion
and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified
as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither
the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be
made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Cover image designed by Freepik
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Gwenan Spearing
Development Editor: Laura Berendson
Technical Reviewer: Rich O’Kelly, Martin Milsom, Dan Horrocks-Burgess, Jamie Wright
Coordinating Editor: Nancy Chen
Copy Editor: Karen Jameson
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web
page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on
GitHub via the book's product page, located at www.apress.com/9781484232484. For more detailed information,
please visit http://www.apress.com/source-code.
Printed on acid-free paper
For Rebecca, Lily, Deborah, Victoria, and Mum
Contents
■
■Chapter 1: TypeScript Language Features������������������������������������������������������������� 1
JavaScript Is Valid TypeScript������������������������������������������������������������������������������������������� 2
Variables��������������������������������������������������������������������������������������������������������������������������� 4
Constants������������������������������������������������������������������������������������������������������������������������� 6
Types�������������������������������������������������������������������������������������������������������������������������������� 6
Type Annotations������������������������������������������������������������������������������������������������������������������������������������ 7
Primitive Types��������������������������������������������������������������������������������������������������������������������������������������� 9
Object and Dynamic Types�������������������������������������������������������������������������������������������������������������������� 10
Enumerations��������������������������������������������������������������������������������������������������������������������������������������� 10
Union Types������������������������������������������������������������������������������������������������������������������������������������������ 13
Literal Types������������������������������������������������������������������������������������������������������������������������������������������ 14
Intersection Types��������������������������������������������������������������������������������������������������������������������������������� 15
Arrays��������������������������������������������������������������������������������������������������������������������������������������������������� 15
Tuple Types������������������������������������������������������������������������������������������������������������������������������������������� 17
Dictionary Types����������������������������������������������������������������������������������������������������������������������������������� 18
Mapped Types��������������������������������������������������������������������������������������������������������������������������������������� 19
Type Assertions������������������������������������������������������������������������������������������������������������������������������������� 20
Type Guards������������������������������������������������������������������������������������������������������������������������������������������ 21
Discriminated Unions��������������������������������������������������������������������������������������������������������������������������� 23
v
■ Contents
Operators������������������������������������������������������������������������������������������������������������������������ 24
Increment and Decrement�������������������������������������������������������������������������������������������������������������������� 24
Binary Operators����������������������������������������������������������������������������������������������������������������������������������� 25
Bitwise Operators��������������������������������������������������������������������������������������������������������������������������������� 26
Logical Operators��������������������������������������������������������������������������������������������������������������������������������� 26
Type Operators�������������������������������������������������������������������������������������������������������������������������������������� 30
Destructuring���������������������������������������������������������������������������������������������������������������������������������������� 30
Spread Operator����������������������������������������������������������������������������������������������������������������������������������� 34
Functions������������������������������������������������������������������������������������������������������������������������ 35
Optional Parameters����������������������������������������������������������������������������������������������������������������������������� 36
Default Parameters������������������������������������������������������������������������������������������������������������������������������� 37
Rest Parameters����������������������������������������������������������������������������������������������������������������������������������� 38
Overloads���������������������������������������������������������������������������������������������������������������������������������������������� 38
Specialized Overload Signatures���������������������������������������������������������������������������������������������������������� 39
Arrow Functions����������������������������������������������������������������������������������������������������������������������������������� 41
Function Currying��������������������������������������������������������������������������������������������������������������������������������� 42
Interfaces����������������������������������������������������������������������������������������������������������������������� 44
Classes��������������������������������������������������������������������������������������������������������������������������� 47
Constructors����������������������������������������������������������������������������������������������������������������������������������������� 47
Access Modifiers���������������������������������������������������������������������������������������������������������������������������������� 49
Properties and Methods����������������������������������������������������������������������������������������������������������������������� 49
Class Heritage�������������������������������������������������������������������������������������������������������������������������������������� 51
Abstract Classes����������������������������������������������������������������������������������������������������������������������������������� 53
Scope���������������������������������������������������������������������������������������������������������������������������������������������������� 54
Type Information����������������������������������������������������������������������������������������������������������������������������������� 56
Generics������������������������������������������������������������������������������������������������������������������������� 58
Generic Functions��������������������������������������������������������������������������������������������������������������������������������� 58
Generic Interfaces�������������������������������������������������������������������������������������������������������������������������������� 59
Generic Classes������������������������������������������������������������������������������������������������������������������������������������ 60
Type Constraints����������������������������������������������������������������������������������������������������������������������������������� 61
vi
■ Contents
TypeScript Futures��������������������������������������������������������������������������������������������������������� 61
Summary������������������������������������������������������������������������������������������������������������������������ 62
Key Points���������������������������������������������������������������������������������������������������������������������� 62
■
■Chapter 2: Code Organization������������������������������������������������������������������������������ 63
Namespaces������������������������������������������������������������������������������������������������������������������� 64
Modules�������������������������������������������������������������������������������������������������������������������������� 68
Module Re-Exporting���������������������������������������������������������������������������������������������������������������������������� 70
Default Exports������������������������������������������������������������������������������������������������������������������������������������� 70
Exports Object�������������������������������������������������������������������������������������������������������������������������������������� 71
Module Loading������������������������������������������������������������������������������������������������������������������������������������ 71
Summary������������������������������������������������������������������������������������������������������������������������ 81
Key Points���������������������������������������������������������������������������������������������������������������������� 82
■
■Chapter 3: The Type System�������������������������������������������������������������������������������� 83
Type Systems����������������������������������������������������������������������������������������������������������������� 83
Optional Static Types������������������������������������������������������������������������������������������������������ 84
Structural Typing������������������������������������������������������������������������������������������������������������ 86
Type Erasure������������������������������������������������������������������������������������������������������������������� 88
Type Inference���������������������������������������������������������������������������������������������������������������� 89
Best Common Type������������������������������������������������������������������������������������������������������������������������������� 90
Contextual Types����������������������������������������������������������������������������������������������������������������������������������� 91
Widened Types�������������������������������������������������������������������������������������������������������������������������������������� 91
When to Annotate��������������������������������������������������������������������������������������������������������������������������������� 91
Duplicate Identifiers������������������������������������������������������������������������������������������������������� 92
Type Checking���������������������������������������������������������������������������������������������������������������� 93
vii
■ Contents
Ambient Declarations����������������������������������������������������������������������������������������������������� 95
Declaration Files����������������������������������������������������������������������������������������������������������������������������������� 96
Definitely Typed������������������������������������������������������������������������������������������������������������������������������������ 97
Summary������������������������������������������������������������������������������������������������������������������������ 97
Key Points���������������������������������������������������������������������������������������������������������������������� 97
■
■Chapter 4: Object Orientation in TypeScript�������������������������������������������������������� 99
Object Orientation in TypeScript����������������������������������������������������������������������������������� 100
Open Recursion���������������������������������������������������������������������������������������������������������������������������������� 100
Encapsulation������������������������������������������������������������������������������������������������������������������������������������� 102
Delegation������������������������������������������������������������������������������������������������������������������������������������������ 104
Polymorphism������������������������������������������������������������������������������������������������������������������������������������� 106
Mixins��������������������������������������������������������������������������������������������������������������������������� 121
TypeScript Mixins������������������������������������������������������������������������������������������������������������������������������� 121
When to Use Mixins���������������������������������������������������������������������������������������������������������������������������� 123
Restrictions����������������������������������������������������������������������������������������������������������������������������������������� 123
Real Mixins����������������������������������������������������������������������������������������������������������������������������������������� 125
Summary���������������������������������������������������������������������������������������������������������������������� 126
Key Points�������������������������������������������������������������������������������������������������������������������� 127
viii
■ Contents
■
■Chapter 5: Understanding the Runtime������������������������������������������������������������� 129
Runtime Features��������������������������������������������������������������������������������������������������������� 129
Scope��������������������������������������������������������������������������������������������������������������������������� 131
Callbacks�������������������������������������������������������������������������������������������������������������������������������������������� 134
Passing Functions as Arguments������������������������������������������������������������������������������������������������������� 137
Promises��������������������������������������������������������������������������������������������������������������������������������������������� 138
Events��������������������������������������������������������������������������������������������������������������������������� 147
TypeScript’s Custom-Event Mechanism��������������������������������������������������������������������������������������������� 149
Event Phases�������������������������������������������������������������������������������������������������������������������������������������� 151
Summary���������������������������������������������������������������������������������������������������������������������� 156
Key Points�������������������������������������������������������������������������������������������������������������������� 157
■
■Chapter 6: Running TypeScript in a Browser����������������������������������������������������� 159
The Anatomy of a Web Browser����������������������������������������������������������������������������������� 159
Reflows and Frames Per Second�������������������������������������������������������������������������������������������������������� 160
The Interesting Components��������������������������������������������������������������������������������������������������������������� 162
Network������������������������������������������������������������������������������������������������������������������������ 170
AJAX��������������������������������������������������������������������������������������������������������������������������������������������������� 170
WebSockets���������������������������������������������������������������������������������������������������������������������������������������� 173
Real-Time Communications��������������������������������������������������������������������������������������������������������������� 173
ix
■ Contents
Storage������������������������������������������������������������������������������������������������������������������������� 174
Session Storage���������������������������������������������������������������������������������������������������������������������������������� 174
Local Storage�������������������������������������������������������������������������������������������������������������������������������������� 175
Storage Restrictions��������������������������������������������������������������������������������������������������������������������������� 176
IndexedDB������������������������������������������������������������������������������������������������������������������������������������������ 176
Storage Roundup�������������������������������������������������������������������������������������������������������������������������������� 183
Geolocation������������������������������������������������������������������������������������������������������������������ 183
Sensors������������������������������������������������������������������������������������������������������������������������ 185
Battery Status������������������������������������������������������������������������������������������������������������������������������������� 185
Proximity Sensor�������������������������������������������������������������������������������������������������������������������������������� 187
Light Sensor��������������������������������������������������������������������������������������������������������������������������������������� 188
Motion and Orientation����������������������������������������������������������������������������������������������������������������������� 188
Other Device Sensors������������������������������������������������������������������������������������������������������������������������� 189
Sensor Roundup��������������������������������������������������������������������������������������������������������������������������������� 189
Web Workers���������������������������������������������������������������������������������������������������������������� 190
Packaging Your Program���������������������������������������������������������������������������������������������� 192
Summary���������������������������������������������������������������������������������������������������������������������� 192
Key Points�������������������������������������������������������������������������������������������������������������������� 192
■
■Chapter 7: Running TypeScript on a Server������������������������������������������������������� 195
Install Node������������������������������������������������������������������������������������������������������������������ 195
Creating a New Project������������������������������������������������������������������������������������������������� 196
NPM������������������������������������������������������������������������������������������������������������������������������ 196
Simple Node Program�������������������������������������������������������������������������������������������������� 199
Request Information����������������������������������������������������������������������������������������������������� 200
Using Express to Write Applications����������������������������������������������������������������������������� 201
Simple Express Program�������������������������������������������������������������������������������������������������������������������� 202
Multiple Routes����������������������������������������������������������������������������������������������������������������������������������� 203
Handling Errors����������������������������������������������������������������������������������������������������������������������������������� 203
Express Book Project�������������������������������������������������������������������������������������������������������������������������� 205
Summary���������������������������������������������������������������������������������������������������������������������� 216
Key Points�������������������������������������������������������������������������������������������������������������������� 216
x
■ Contents
■
■Chapter 8: Exceptions, Memory, and Performance�������������������������������������������� 217
Exceptions�������������������������������������������������������������������������������������������������������������������� 217
Throwing Exceptions�������������������������������������������������������������������������������������������������������������������������� 218
Exception Handling����������������������������������������������������������������������������������������������������������������������������� 219
Memory������������������������������������������������������������������������������������������������������������������������ 224
Releasing Resources�������������������������������������������������������������������������������������������������������������������������� 224
Garbage Collection����������������������������������������������������������������������������������������������������������������������������� 225
Performance����������������������������������������������������������������������������������������������������������������� 228
Summary���������������������������������������������������������������������������������������������������������������������� 232
Key Points�������������������������������������������������������������������������������������������������������������������� 232
■
■Chapter 9: Using JavaScript Libraries��������������������������������������������������������������� 233
Creating Type Definitions���������������������������������������������������������������������������������������������� 234
Creating a TypeScript Application with Knockout������������������������������������������������������������������������������� 235
Silencing the Compiler����������������������������������������������������������������������������������������������������������������������� 237
Iteratively Improving Type Definitions������������������������������������������������������������������������������������������������� 238
Summary���������������������������������������������������������������������������������������������������������������������� 255
Key Points�������������������������������������������������������������������������������������������������������������������� 256
xi
■ Contents
■
■Appendix 1: JavaScript Quick Reference���������������������������������������������������������� 257
Variables����������������������������������������������������������������������������������������������������������������������� 257
Functions���������������������������������������������������������������������������������������������������������������������� 258
Conditional Statements������������������������������������������������������������������������������������������������ 259
Loops���������������������������������������������������������������������������������������������������������������������������� 260
Strings�������������������������������������������������������������������������������������������������������������������������� 261
Promises���������������������������������������������������������������������������������������������������������������������� 262
Summary���������������������������������������������������������������������������������������������������������������������� 263
■
■Appendix 2: TypeScript Compiler���������������������������������������������������������������������� 265
Getting Help������������������������������������������������������������������������������������������������������������������ 265
Sample File������������������������������������������������������������������������������������������������������������������ 265
Common Flags������������������������������������������������������������������������������������������������������������� 266
Module Kind���������������������������������������������������������������������������������������������������������������������������������������� 266
ECMAScript Target Version����������������������������������������������������������������������������������������������������������������� 268
Generate Declarations������������������������������������������������������������������������������������������������������������������������ 269
Remove Comments����������������������������������������������������������������������������������������������������������������������������� 269
Combined Output�������������������������������������������������������������������������������������������������������������������������������� 269
xii
■ Contents
■
■Appendix 3: Bitwise Flags��������������������������������������������������������������������������������� 273
Bit Flags Explained������������������������������������������������������������������������������������������������������� 274
Bitwise Operations������������������������������������������������������������������������������������������������������� 274
■
■Appendix 4: Coding Katas��������������������������������������������������������������������������������� 277
Performing a Kata�������������������������������������������������������������������������������������������������������� 278
Example: The Fizz Buzz Kata���������������������������������������������������������������������������������������� 279
Common Coding Kata Rules����������������������������������������������������������������������������������������� 279
Summary���������������������������������������������������������������������������������������������������������������������� 280
Index��������������������������������������������������������������������������������������������������������������������� 281
xiii
About the Author
xv
Acknowledgments
A book is enjoyable when you work with the right people, and those people are Gwenan Spearing at Apress
and my smart technical reviewers Rich O’Kelly, Martin Milsom, Dan Horrocks-Burgess, and Jamie Wright.
I am incredibly grateful to Nancy Chen for being so patient with my sporadic writing habits, last-minute
changes, and vague estimates.
This second edition would not have been possible without the contributions of all the smart people that
helped create the first book; Mark Jones, Mark Rendle, Basarat Ali Syed, Christine Ricketts, Boris Yankov,
Diullei Gomes, Masahiro Wakame, Jason Jarrett, Bart van der Schoor, John Reilly, Igor Oleinikov, Luke
Hoban, Jonathan Turner, and of course - Ryan Cavanaugh.
I am also grateful to all of my amazing colleagues, past and present, who inspire me to keep learning
and growing.
xvii
Introduction
Atwood’s Law: any application that can be written in JavaScript will eventually be written
in JavaScript.
—Jeff Atwood
TypeScript is a language created and maintained by Microsoft, and released under an open-source Apache
2.0 License (2004). The language is focused on making the development of JavaScript programs scale to
many thousands of lines of code. In fact, Microsoft has written both the Azure Management Portal (1.2
million lines of code) and the Visual Studio Code editor (300,000 lines of code) in TypeScript. The language
attacks the large-scale JavaScript programming problem by offering better design-time tooling, compile-
time checking, and dynamic module loading at runtime.
As you might expect from a language created by Microsoft, there is excellent support for TypeScript
within Visual Studio, but plenty of other development tools have also added support for the language,
including VS Code, WebStorm, Eclipse, Sublime Text, Vi, Atom, IntelliJ, and Emacs among others. The
widespread support from these tools as well as the permissive open-source license makes TypeScript a
viable option outside of the traditional Microsoft ecosystem.
The TypeScript language is a typed superset of JavaScript, which is compiled to plain JavaScript in
the flavor of your choosing. This makes programs written in TypeScript highly portable as they can run
on almost any machine — in web browsers, on web servers, and even in native applications on operating
systems that expose a JavaScript API, such as WinJS.
The language features found in TypeScript can be divided into three categories based on their
relationship to JavaScript (see Figure 1). The first two sets are related to versions of the ECMA-262
ECMAScript Language Specification, which is the official specification for JavaScript. The ECMAScript 5
specification forms the basis of TypeScript and supplies the largest number of features in the language.
Subsequent versions of the ECMAScript specification are rolled into TypeScript releases, often as early
previews that feature down-level compilation to older versions of the specication. The third and final set of
language features includes items that are not planned to become part of the ECMAScript standard, such as
generics and type annotations. All the additional features of TypeScript can be output to a number of widely
supported versions of JavaScript.
TypeScript has several native frameworks, including Angular, Ionic, RxJs 5, and Dojo 2. Additionally,
because TypeScript is such a close relative of JavaScript, you can consume the myriad of existing libraries
and frameworks written in JavaScript; Aurelia, Backbone, Bootstrap, Durandal, jQuery, Knockout,
Modernizr, PhoneGap, Prototype, Raphael, React, Underscore, Vue, and many more are all usable in
TypeScript programs. Correspondingly, once your TypeScript program has been compiled it can be
consumed from any JavaScript program too.
TypeScript's similarity to JavaScript is beneficial if you already have experience with JavaScript or other
C-like languages. The similarity also aids the debugging process as the generated JavaScript correlates
closely to the original TypeScript code. Source maps can also be generated to aid debugging, with browser
developer tools displaying your TypeScript code during in-browser debugging.
xix
■ Introduction
If you still need to be convinced about using TypeScript or need help convincing others, I summarize
the benefits of the language as well as the problems it can solve in the following sections. I also include an
introduction to the components of TypeScript and some of the alternatives. If you would rather get started
with the language straight away, you can skip straight to Chapter 1.
Structure
This book is organized into ten chapters and four appendices.
Chapter 1: TypeScript Language Features: describes the language features in
detail, from simple type annotations to important structural elements, with
stand-alone examples of how to use each one.
Chapter 2: Code Organization: clarifies how code can be organized, loaded, and
packaged with a view to growing your program to millions of lines of code.
Chapter 3: The Type System: explains the details of working within TypeScript's
structural type system and describes the details on type erasure, type inference,
and ambient declarations.
xx
■ Introduction
xxi
■ Introduction
The language consists of the new syntax, keywords, and type annotations. As a programmer, the
language will be the component you will become most familiar with. Understanding how to supply type
information is an important foundation for the other components because the compiler and language
service are most effective when they understand the complex structures you use within your program.
The compiler performs the type erasure and code transformations that convert your TypeScript code
into JavaScript. It will emit warnings and errors if it detects problems and can perform additional tasks such
as combining the output into a single file, generating source maps, and more.
The language service provides type information that can be used by development tools to supply
autocompletion, type hinting, refactoring options, and other creative features based on the type information
that has been gathered from your program.
Compile or Transpile?
The term transpiling has been around since the last century, but there is some confusion about its meaning.
In particular, there has been some confusion between the terms compilation and transpilation. Compilation
describes the process of taking source code written in one language and converting it into another language.
Transpilation is a specific kind of compilation and describes the process of taking source code written in one
language and transforming it into another language with a similar level of abstraction. So, you might compile
a high-level language into an assembly language, but you would transpile TypeScript to JavaScript as they
are similarly abstracted.
Other common examples of transpilation include C++ to C, CoffeeScript to JavaScript, Dart to
JavaScript, and PHP to C++.
xxii
■ Introduction
Despite its popularity, it hasn't received much respect from developers — possibly because it contains
many snares and traps that can entangle a large program much like the tar pit pulling the mammoth to
its death, as described by Fred Brooks (1975). If you are a professional programmer working with large
applications written in JavaScript, you will almost certainly have rubbed up against problems once your
program chalked up a few thousand lines. You may have experienced naming conflicts, substandard
programming tools, complex modularization, unfamiliar prototypal inheritance that makes it hard to reuse
common design patterns easily, and difficulty keeping a readable and maintainable code base. TypeScript
solves problems such as these.
Because JavaScript has a C-like syntax, it looks familiar to most programmers. This is one of JavaScript's
key strengths, but it is also the cause of many surprises, especially in the following areas:
• Prototypal inheritance
• Equality and type juggling
• Management of modules
• Scope
• Lack of types
Typescript solves or eases these problems in several ways. Each of these topics is discussed in this
introduction.
Prototypal Inheritance
Prototype-based programming is a style of object-oriented programming that is mainly found in interpreted
dynamic languages. It was first used in a language called Self, created by David Ungar and Randall Smith in
1986, but it has been used in a selection of languages since then. Of these prototypal languages, JavaScript
is by far the most widely known, although this has done little to bring prototypal inheritance into the
mainstream. Despite its validity, prototype-based programming is somewhat esoteric; class-based object
orientation is far more commonplace and will be familiar to most programmers.
TypeScript solves this problem by adding classes, namespaces, modules, and interfaces. This allows
programmers to transfer their existing knowledge of objects and code structure from other languages,
including implementing interfaces, inheritance, and code organization. Classes and modules are an early
preview of JavaScript proposals and because TypeScript can compile to earlier versions of JavaScript, it
allows you to use these features independent of support for the newer ECMAScript specifications. All these
features are described in detail in Chapter 1.
xxiii
■ Introduction
// result is 20
const result = strTen * 2;
TypeScript gracefully solves this problem by introducing type checking, which can provide warnings
at design and compile time to pick up potential unintended juggling. Even in cases where it allows implicit
type coercion, the result will be assigned the correct type. This prevents dangerous assumptions from going
undetected. This feature is covered in detail in Chapter 3.
The introduction of types in TypeScript does not preclude the use of dynamic types. You can choose
when to use types, and when to go without them. TypeScript does not force you to do anything, it is just
there to help.
Management of Modules
If you have worked with JavaScript, it is likely that you will have come across a dependency problem. Some
of the common problems include the following:
• Forgetting to add a script tag to a web page
• Adding scripts to a web page in the wrong order
• Finding out you have added scripts that aren't used
There is also a series of issues you may have come across if you are using tools to combine your scripts
into a single file to reduce network requests or if you minify your scripts to lower bandwidth usage.
• Combining scripts into a single script in the wrong order
• Finding out that your chosen minification tool doesn't understand single-line
comments
• Trying to debug combined and minified scripts
You may have already solved some of these issues using module loading, as the pattern is gaining
traction in the JavaScript community. However, TypeScript makes module loaders the default way of
working and allows your modules to be compiled to suit the most prevalent module loading styles without
requiring changes to your code. The details of module loading in web browsers are covered in Chapter 6 and
on the server in Chapter 7.
Scope
In most modern C-like languages, the curly braces create a new context for scope. A variable declared inside a
set of curly braces cannot be seen outside of that block. JavaScript has bucked this trend traditionally by being
functionally scoped, which means blocks defined by curly braces have no effect on scope. Instead, variables are
scoped to the function they are declared in, or the global scope if they are not declared within a function. There
can be further complications caused by the accidental omission of the var keyword within a function, thus
promoting the variable into the global scope. More complications are caused by variable hoisting, resulting in
all variables within a function behaving as if they were declared at the top of the function.
xxiv
■ Introduction
The introduction of the const and let variable declarations have gone some way to solving this
problem, and if you are starting from a clean sheet you can avoid the older var variable declaration
altogether.
Despite some tricky surprises with scope, JavaScript does provide a powerful mechanism that wraps
the current lexical scope around a function declaration to keep values to hand when the function is later
executed. These closures are one of the most powerful features in JavaScript.
TypeScript eases scope problems by warning you about implicit global variables, provided you avoid
adding variables to the global scope. This safety net is demonstrated in Listing 2.
Lack of Types
The problem with JavaScript isn't that it has no types, because each variable does have a type; it is just that
the type can be changed by each assignment. A variable may start off as a string, but an assignment can
change it to a number, an object, or even a function. The real problem here is that the development tools
cannot be improved beyond a reasonable guess about the type of a variable. If the development tools don’t
know the types, the autocompletion and type hinting is often too general to be useful.
By formalizing type information, TypeScript allows development tools to supply specific contextual
help that otherwise would not be possible.
TypeScript is not a crutch any more than JSLint is a crutch. It doesn’t hide JavaScript (as
CoffeeScript tends to do).
—Ward Bell
TypeScript remains largely faithful to JavaScript. The TypeScript specification adds many language features,
but it doesn't attempt to change the ultimate style and behavior of the JavaScript language. It is just as
important for TypeScript programmers to embrace the idiosyncrasies of the runtime as it is for JavaScript
programmers. The aim of the TypeScript language is to make large-scale JavaScript programs manageable
and maintainable. No attempt has been made to twist JavaScript development into the style of C#, Java,
Ruby, Python, or any other language (although it has taken inspiration from many languages).
Prerequisites
To benefit from the features of TypeScript, you'll need access to an integrated development environment that
supports the syntax and compiler. The examples in this book were written using Visual Studio 2017, but you
can use VS Code, WebStorm/PHPStorm, Eclipse, Sublime Text, Vi, Emacs, or any other development tools
that support the language; you can even try many of the simpler examples on the TypeScript Playground
provided by Microsoft. I often use the TypeScript Playground when answering questions on the language.
xxv
■ Introduction
From the Visual Studio 2013 Spring Update (Update 2), TypeScript is a first-class language in Visual
Studio. Prior to this, an additional extension needed to be installed. Although the examples in this book are
shown in Visual Studio, you can use any of the development tools that were listed above. In particular, Visual
Studio Code is a free cross-platform editor with native TypeScript support - so you can write your TypeScript
code on any machine you have on hand, regardless of the operating system.
It is also worth downloading and installing Node (which is required to follow many of the examples) as
it will allow you to access the Node Package Manager and the thousands of modules and utilities available
through it. For example, you can use task runners such as Grunt and Gulp to watch your TypeScript files and
compile them automatically each time you change them if your development tools don't do this for you.
Node is free and can be downloaded for multiple platforms from the official Node website.
https://nodejs.org/
To avoid being greatly sidetracked, I have avoided using any task runners to perform additional
operations outside of Visual Studio, but once you have mastered TypeScript you will almost certainly want
to add a task runner, such as Gulp or Grunt, to your development workflow. I have referenced some web
dependencies from the node_modules folder in the examples in this book; but on a real-world project I
would use a task runner to lift and shift the website dependencies into a different folder that I would be
happy to deploy to a web server. The node_modules folder often contains a great deal of files that I would not
deploy to a web server.
TypeScript Alternatives
TypeScript is not the only alternative to writing to plain JavaScript.
The strongest TypeScript alternative is Babel, a compiler that exposes the latest ECMAScript features
with plugins for down-level compilation and polyfills to make your program work in current browsers. The
aim of the Babel project is to make the latest features available much sooner than they otherwise would be,
but Babel doesn't introduce compile-time type checking. Babel also features in many TypeScript workflows,
where Babel is executed after the TypeScript compiler, rather than using TypeScript to perform the down-
level compilation. You can read about Babel on the official website:
https://babeljs.io/
For a number of years, CoffeeScript was a popular alternative with a terse syntax that compiles to
sensible JavaScript code. CoffeeScript doesn't offer many of the additional features that TypeScript offers,
such as static type checking. It is also a very different language to JavaScript, which means you need to
translate snippets of code you find online into CoffeeScript to use them. In 2017, however, CoffeeScript
reached the top three "most dreaded languages" in the Stack Overflow developer survey (next to VBA, and
Visual Basic 6). In the same survey, TypeScript landed in the top three most loved languages. You can find
out more about CoffeeScript on the official website:
http://coffeescript.org/
Another alternative is Google's Dart language. Dart has much in common with TypeScript. It is class-
based, object oriented, and offers optional types that can be checked by a static checker. Dart was originally
conceived as a replacement for JavaScript, and was only intended to be compiled to JavaScript to provide
wide support in the short term while native support for Dart was added to browsers.
It seems unlikely at this stage that Dart will get the kind of browser support that JavaScript has won,
so the compile-to-JavaScript mechanism will likely remain core to Dart's future in the web browser. The
decision by Google to adopt TypeScript for the Angular project may be indicative of their commitment to
Dart, although it is still described as a long-term project. You can read about Dart on the official website for
the language:
https://www.dartlang.org/
xxvi
■ Introduction
There are also converters that will compile from most languages to JavaScript, including C#, Ruby, Java,
and Haskell. These may appeal to programmers who are uncomfortable stepping outside of their primary
programming language.
It is also worth bearing in mind that for small applications and web page widgets, you can defer the
decision and write the code in plain JavaScript. With TypeScript in particular, there is no penalty for starting
in JavaScript as you can simply paste your JavaScript code into a TypeScript file later on to make the switch.
Equally, there is little penalty for writing small programs in TypeScript, especially if you already have a
workflow in place to generate combined or minified files each time you save your application.
Summary
TypeScript is an application-scale programming language that provides early access to proposed new
JavaScript features and powerful additional features like static type checking. You can write TypeScript
programs to run in web browsers or on servers and you can reuse code between browser and server
applications.
TypeScript solves many problems in JavaScript, but it respects the patterns and implementation of the
underlying JavaScript language, for example, the ability to have dynamic types.
You can use many integrated development environments with TypeScript, with several providing first-
class support including type checking and autocompletion that will improve your productivity and help
eliminate mistakes at design time.
Key Points
• TypeScript is a language, a compiler, and a language service.
• You can paste existing JavaScript into your TypeScript program.
• Compiling from TypeScript to JavaScript is known specifically as transpiling.
• TypeScript is not the only alternative way of writing JavaScript, but it has gained
incredible traction in its first five years.
xxvii
CHAPTER 1
What if we could strengthen JavaScript with the things that are missing for large scale
application development, like static typing, classes [and] modules... that’s what TypeScript
is about.
—Anders Hejlsberg
TypeScript is a superset of JavaScript. That means that the TypeScript language includes the entire JavaScript
language plus a collection of useful additional features. This contrasts with the various subsets of JavaScript
and the various linting tools that seek to reduce the available features to create a smaller language with
fewer surprises. This chapter will introduce you to the extra language features, starting with simple type
annotations and progressing to more advanced features and structural elements of TypeScript. This chapter
doesn’t cover every feature included in the ECMAScript language specification, so if you need a refresher on
JavaScript, take a look at Appendix 1.
One important thing to remember is that all the standard control structures found in JavaScript are
immediately available within a TypeScript program. This includes the following:
• Control flows
• Data types
• Operators
• Subroutines
The basic building blocks of your program will come from JavaScript, including if statements, switch
statements, loops, arithmetic, logical tests, and functions. This is one of the key strengths of TypeScript — it
is based on a language (and a family of languages) that is already familiar to a vast and varied collection
of programmers. JavaScript is thoroughly documented not only in the ECMA-262 specification, but also in
books, on developer network portals, forums, and question-and-answer websites. When features are added
to JavaScript, they will also appear in TypeScript.
The TypeScript compiler is typically updated with new JavaScript features early in their specification.
Most of the features are available before browsers support them. In many cases, you can use the features in
your TypeScript program as the compiler will convert them into code that targets the older versions of the
ECMAScript standard.
Each of the language features discussed in this chapter has short, self-contained code examples that put
the feature in context. For the purposes of introducing and explaining features, the examples are short and
to the point; this allows the chapter to be read end to end. However, this also means you can refer back to the
chapter as a reference later on. Once you have read this chapter, you should know everything you will need
to understand the more complex examples described throughout the rest of the book.
■■Caution The only exceptions to the “all JavaScript is valid TypeScript” rule are the with statement and
vendor-specific extensions, until they are formally added to the ECMAScript specification. You could technically
still use the with statement, but all statements within the block would be unchecked.
The JavaScript with statement in Listing 1-1 shows two examples of the same routine. Although the
first calls Math.PI explicitly, the second uses a with statement, which adds the properties and functions of
Math to the current scope. Statements nested inside the with statement can omit the Math prefix and call
properties and functions directly, for example, the PI property or the floor function.
At the end of the with statement, the original lexical scope is restored, so subsequent calls outside of the
with block must use the Math prefix.
// Using with
const radius2 = 4;
with (Math) {
const area2 = PI * radius2 * radius2;
}
2
Chapter 1 ■ TypeScript Language Features
The with statement was not allowed in strict mode in ECMAScript 5 and later versions of ECMAScript
use strict mode by default for classes and modules. TypeScript treats with statements as an error and will
treat all types within the with statement as dynamic types. This is due to the following:
• The fact it is disallowed in strict mode.
• The general opinion that the with statement is dangerous.
• The practical issues of determining the identifiers that are in scope at compile time.
So, with these minor exceptions to the rule in mind, you can place any valid JavaScript into a TypeScript
file and it will be valid TypeScript. As an example, here is the area calculation script transferred to a
TypeScript file.
■■Note The ECMAScript 6 specification, also known as “ES6 Harmony,” represented a substantial change to
the JavaScript language. The specification has been divided into annual chunks, released as ECMAScript 2015,
ECMAScript 2016, and so on.
In Listing 1-2, the statements are just plain JavaScript, but in TypeScript the variables radius and area
will both benefit from type inference. Because radius is initialized with the value 4, it can be inferred that
the type of radius is number. With just a slight increase in effort, the result of multiplying Math.PI, which is
known to be a number, with the radius variable that has been inferred to be a number, it is possible to infer
the type of area is also a number.
With type inference at work, assignments can be checked for type safety. Figure 1-1 shows how an
unsafe assignment is detected when a string is assigned to the radius variable. There is a more detailed
explanation of type inference in Chapter 3. For now, rest assured that type inference is a good thing, and it
will save you a lot of effort.
3
Chapter 1 ■ TypeScript Language Features
Variables
TypeScript variables must follow the JavaScript naming rules. The identifier used to name a variable must
satisfy the following conditions.
The first character must be one of the following:
• an uppercase letter
• a lowercase letter
• an underscore
• a dollar sign
• a Unicode character from categories—Uppercase letter (Lu), Lowercase letter (Ll),
Title case letter (Lt), Modifier letter (Lm), Other letter (Lo), or Letter number (Nl)
Subsequent characters follow the same rule and additionally allow the following:
• numeric digits
• a Unicode character from categories—Non-spacing mark (Mn), Spacing combining
mark (Mc), Decimal digit number (Nd), or Connector punctuation (Pc)
• the Unicode characters U+200C (Zero Width Non-Joiner) and U+200D
(Zero Width Joiner)
You can test a variable identifier for conformance to the naming rules using the JavaScript variable
name validator by Mathias Bynens.
http://mothereff.in/js-variables
■■Note The availability of some of the more exotic characters can allow some interesting identifiers.
You should consider whether this kind of variable name causes more problems than it solves. For example,
this is valid JavaScript: const = 'Dignified';
Variables declared with const or let are block scoped, whereas variables declared with the older var
keyword are function scoped. If you omit these keywords, you are implicitly (and perhaps accidentally)
declaring the variable in the global scope. It is advisable to reduce the number of variables you add to the
global scope, as they are at risk of name collisions. You can avoid the global scope by declaring variables
local to their use, such as within functions, modules, namespaces, classes, or a simple set of curly braces if
you are using the block-scoped keywords.
When you limit the scope of a variable, it means it cannot be manipulated from outside of the scope of
which it was created. The scope follows a nesting rule that allows a variable to be used in the current scope,
and in inner nested scopes – but not outside. In other words, you can use variables declared in the current
scope and variables from wider scopes. See Listing 1-3.
4
Chapter 1 ■ TypeScript Language Features
{
let blockScope = 2;
{
let nestedBlockScope = 3;
TypeScript catches scope violations and will warn you when you attempt to access a variable that is
declared in a narrower scope. You can help the compiler to help you by avoiding a valid, but often accidental
coding style of reusing a name in a different scope. In Listing 1-4, the logging statements work correctly, with
both firstName variables being preserved separately. This means the original variable is not overwritten by
the nested variable with the same name.
{
let firstName = 'Tudor';
// Output:
// Name 1: Tudor
// Name 2: Chris
If in place of the let keyword the var keyword had been used, both logging statements would show the
name “Tudor,” as shown in Listing 1-5. Despite both variables appearing to be a separate declaration, only
one variable named firstName exists, and it is overwritten by the nested scope.
5
Exploring the Variety of Random
Documents with Different Content
with a festive glamour; nor ever did the owl stir from its station on the
fountain.
“Listen, Mr. Dunn! When you had made your escape, my husband
revealed the true state of his mind by drawing a revolver. He was mad. I did
not know what to do. I screamed, and on the second butler’s rushing into the
room without knocking on the door the poor fellow was hurled from the
house. But in the meanwhile I had managed to grab hold of the revolver.
What could I do, Mr. Dunn? I ask you, what could I do?”
“Holy smoke!” said Mr. Dunn. “I don’t know. But——”
“The madman advanced on me. His face livid, his eyes mad, and his
hands arranged before him in such a way as to leave one no room to doubt
that his immediate intention was to strangle me. I threatened to fire. Can
you, can anyone, blame me? Was I wrong, may one not defend one’s life?”
“Holy smoke!” said Mr. Dunn. “Certainly. But——”
“My threat to fire did not discommode his mad approach. I kept on
making it. But did he stop?”
“Did he?” gasped Mr. Dunn.
“Mr. Dunn, he did not. I fired.”
“You didn’t!” said Mr. Dunn.
“I did,” said my lady.
“But holy smoke!” cried Mr. Dunn. “You killed him!”
“No,” she whispered sadly. “I missed. Mr. Dunn, he killed me.”
And it was at that moment, even as the phantom of the unfortunate lady
faded before his eyes and Mr. Dunn let out an appalling yell, that the owl on
the fountain hooted thrice with marvellous dolour and fled, to be lost almost
on the instant among the lofty shadows of the Regent’s Palace Hotel.
Amateurs of history and students of privilege should note that additional
point is lent to this already interesting chronicle by the fact that the late Lord
Vest was the first Australian marquess to be hanged by the neck in the year
of grace 1924. A vast concourse attended outside the prison gates on the
morning of the execution, some of whom were photographed by pressmen in
the act of gnashing their teeth, which is to be explained by the fact that they
had brought their breakfast with them in the form of sandwiches. The
executioners were Lovelace, Lovibond and Lazarus. The drop given was
sixteen feet. The criminal died unrepentant, thus denying his soul the grace
of salvation and directing it with terrible velocity and unerring aim to the
fires of eternal damnation, where he will no doubt continue to burn
miserably as a warning for all time to gentlemen who will not dance with
their wives.
VIII: THE GENTLEMAN FROM AMERICA
II
The gentleman from America, alone in the haunted room, lost none of his
composure. Indeed, if anything disturbed him at all, it was that, irritated by
Quillier’s manner at a dinner-party a few nights before, and knowing
Quillier to be a bankrupt wastrel, he had allowed himself to be dared into
this silly adventure and had thus deprived himself for one night of the
amenities of his suite at Claridge’s Hotel. Five hundred pounds more or less
did not matter very much to Mr. Puce: although, to be sure, it was some
consolation to know that five hundred pounds more or less must matter quite
a deal to Sir Cyril Quillier, for all his swank. Mr. Puce, like a good
American, following the gospel according to Mr. Sinclair Lewis, always
stressed the titles of any of his acquaintance.
Now, he contented himself with a very cursory examination of the dim,
large room: he rapped, in an amateurish way, on the oak panels here and
there for any sign of any “secret passage junk,” but succeeded only in soiling
his knuckles: and it was only when, fully clothed, he had thrown himself on
the great bed that it occurred to him that five hundred pounds sterling was
quite a pretty sum to have staked about a damfool haunted room.
The conclusion that naturally leapt to one’s mind, thought Mr. Puce, was
that the room must have something the matter with it: else would a hawk like
Quillier have bet money on its qualities of terror? Mr. Puce had, indeed,
suggested, when first the bet was put forward, that five hundred pounds was
perhaps an unnecessary sum to stake on so idiotic a fancy; but Quillier had
said in a very tired way that he never bet less than five hundred on anything,
but that if Mr. Puce preferred to bet with poppycock and chickenfood, he,
Quillier, would be pleased to introduce him to some very jolly children of
his acquaintance.
Such thoughts persuaded Mr. Puce to rise and examine more carefully the
walls and appointments of the room. But as the furniture was limited to the
barest necessities, and as the oak-panelled walls appeared in the faint light to
be much the same as any other walls, the gentleman from America swore
vaguely and again reclined on the bed. It was a very comfortable bed.
He had made up his mind, however, that he would not sleep. He would
watch out, thought Mr. Puce, for any sign of this old ghost, and he would
listen with the ears of a coyote, thought Mr. Puce, for any hint of those
rapping noises, rude winds, musty odours, clanking of chains and the like,
with which, so Mr. Puce had always understood, the family ghosts of
Britishers invariably heralded their foul appearance.
Mr. Puce, you can see, did not believe in ghosts. He could not but think,
however, that some low trick might be played on him, since on the honour of
Sir Cyril Quillier, peer though he was—for Mr. Puce, like a good American,
could never get the cold dope on all this fancy title stuff—he had not the
smallest reliance. But as to the supernatural, Mr. Puce’s attitude was always
a wholesome scepticism—and a rather aggressive scepticism at that, as
Quillier had remarked with amusement when he had spoken of the ghost in,
as he had put it, the house of Kerr-Anderson’s aunt. Quillier had said:
“There are two sorts of men on whom ghosts have an effect: those who
are silly enough to believe in them, and those who are silly enough not to
believe in them.”
Mr. Puce had been annoyed at that. He detested clever back-chat. “I’ll tell
the world,” Mr. Puce had said, “that a plain American has to go to a drug-
store after a conversation with you.”
Mr. Puce, lying on the great bed, whose hangings depressed him,
examined his automatic and found it good. He had every intention of
standing no nonsense, and an automatic nine-shooter is, as Mr. Puce
remembered having read somewhere, an Argument. Indeed, Mr. Puce was
full of those dour witticisms about the effect of a “gun” on everyday life
which go to make the less pretentious “movies” so entertaining; although, to
be sure, he did not know more than a very little about guns. Travellers have
remarked, however, that the exciting traditions behind a hundred-per-cent
American nationality have given birth in even the most gentle citizens of that
great republic to a feeling of familiarity with “guns,” as such homely phrases
as “slick with the steel mit,” “doggone son of a gun,” and the like, go to
prove.
Mr. Puce placed the sleek little automatic on a small table by the bed, on
which stood the candle and, as he realised for the first time, a book. One
glance at the paper jacket of the book was enough to convince the gentleman
from America that its presence there must be due to one of Quillier’s tired
ideas. It showed a woman of striking, if conventional, beauty fighting for her
life with a shape which might or might not be the wraith of a bloodhound but
was certainly something quite outside a lovely woman’s daily experience.
Mr. Puce laughed. The book was called: Tales of Terror for Tiny Tots, by Ivor
Pelham Marlay.
The gentleman from America was a healthy man, and needed his sleep;
and it was therefore with relief that he turned to Mr. Marlay’s absurd-looking
book as a means of keeping himself awake. The tale at which the book came
open was called The Phantom Foot-steps; and Mr. Puce prepared himself to
be entertained, for he was not of those who read for instruction. He read:
The Phantom Foot-steps
The tale of “The Phantom Foot-steps” is still whispered with awe and
loathing among the people of that decayed but genteel district of London
known to those who live in it as Belgravia and to others as Pimlico.
Julia and Geraldine Biggot-Baggot were twin sisters who lived with their
father, a widower, in a town in Lancashire called Wigan, or it may have been
called Bolton. The tale finds Julia and Geraldine in their nineteenth year, and
it also finds them in a very bad temper, for they were yearning for a more
spacious life than can be found in Wigan, or it might be Bolton. This
yearning their neighbours found all the more inexplicable since the parents
of the girls were of Lancashire stock, their mother having been a Biggot
from Wigan and their father a Baggot from Bolton.
The reader can imagine with what excess of gaiety Julia and Geraldine
heard one day from their father that he had inherited a considerable property
from a distant relation; and the reader can go on imagining the exaltation of
the girls when they heard that the property included a mansion in Belgravia,
since that for which they had always yearned most was to enjoy, from a
central situation, the glittering life of the metropolis.
Their father preceded them from Wigan, or was it Bolton? He was a man
of a tidy disposition, and wished to see that everything in the Belgravia
house was ready against his daughters’ arrival. When Julia and Geraldine did
arrive, however, they were admitted by a genial old person of repellent
aspect and disagreeable odour, who informed them that she was doing a bit
of charing about the house but would be gone by the evening. Their father,
she added, had gone into the country to engage servants, but would be back
the next day; and he had instructed her to tell Julia and Geraldine not to be
nervous of sleeping alone in a strange house, that there was nothing to be
afraid of, and that he would, anyhow, be with them first thing in the
morning.
Now Julia and Geraldine, though twins, were of vastly different
temperaments; for whereas Julia was a girl of gay and indomitable spirit who
knew not fear, Geraldine suffered from agonies of timidity and knew nothing
else. When, for instance, night fell and found them alone in the house, Julia
could scarcely contain her delight at the adventure; while it was with
difficulty that Geraldine could support the tremors that shook her girlish
frame.
Imagine, then, how differently they were affected when, as they lay in
bed in their room towards the top of the house, they distinctly heard from far
below a noise, as of someone moving. Julia sat up in bed, intent, unafraid,
curious. Geraldine swooned.
“It’s only a cat,” Julia whispered. “I’m going down to see.”
“Don’t!” sighed Geraldine. “For pity’s sake don’t leave me, Julia!”
“Oh, don’t be so childish!” snapped Julia. “Whenever there’s the chance
of the least bit of fun you get shivers down your spine. But as you are so
frightened I will lock the door from the outside and take the key with me, so
that no one can get in when I am not looking. Oh, I hope it’s a burglar! I’ll
give him the fright of his life, see if I don’t.”
And the indomitable girl went, feeling her way to the door in darkness,
for to have switched on the light would have been to warn the intruder, if
there was one, that the house was inhabited: whereas it was the plucky girl’s
conceit to turn the tables on the burglar, if there was one, by suddenly
appearing to him as an avenging phantom: for having done not a little
district-visiting in Wigan or, possibly, Bolton, no one knew better than Julia
of the depths of base superstition among the vulgar.
A little calmed by her sister’s nonchalance, Geraldine lay still as a mouse
in the darkness, with her pretty head beneath the bedclothes. From without
came not a sound, and the very stillness of the house had impelled Geraldine
to a new access of terror had she not concentrated on the works of Mr.
Rudyard Kipling, which tell of the grit of the English people.
Then, as though to test the grit of the English people in the most
abominable way, came a dull noise from below. Geraldine restrained a
scream, lay breathless in the darkness. The dull noise, however, was not
repeated, and presently Geraldine grew a little calmer, thinking that maybe
her sister had dropped a slipper or something of the sort. But the reader can
imagine into what terror the poor girl had been plunged had she been a
student of the detective novels of the day, for then she must instantly have
recognised the dull noise as a dull thud, and can a dull thud mean but one
thing?
It was as she was praying a prayer to Our Lady that her ears grew aware
of footsteps ascending the stairs. Her first feeling was one of infinite relief.
Of course Julia had been right, and there had been nothing downstairs but a
cat or, perhaps, a dog. And now Julia was returning, and in a second they
would have a good laugh together. Indeed, it was all Geraldine could do to
restrain herself from jumping out of bed to meet her sister, when she was
assailed by a terrible doubt; and on the instant her mind grew so charged
with fear that she could no longer hold back her sobs. Suppose it was not
Julia ascending! Suppose——“Oh, God!” sobbed Geraldine.
Transfixed with terror, yet hopeful of the best, the poor girl could not
even command herself to reinsert her head beneath the sheets. And always
the ascending steps came nearer. As they approached the door, she thought
she would die of uncertainty. But as the key was fitted into the lock she drew
a deep breath of relief—to be at once shaken by the most acute agony of
doubt, so that she had given anything in the world to be back again in Wigan
or, even better, Bolton.
“Julia!” she sobbed. “Julia!”
For the door had opened, the footsteps were in the room, and Geraldine
thought she recognised her sister’s maidenly tread. But why did Julia not
speak, why this intolerable silence? Geraldine, peer as hard as she might,
could make out nothing in the darkness. The footsteps seemed to fumble in
their direction, but came always nearer to the bed, in which poor Geraldine
lay more dead than alive. Oh, why did Julia not speak, just to reassure her?
“Julia!” sobbed Geraldine. “Julia!”
The footsteps seemed to fumble about the floor with an indecision
maddening to Geraldine’s distraught nerves. But at last they came beside the
bed—and there they stood! In the awful silence Geraldine could hear her
heart beating like a hammer on a bell.
“Oh!” the poor girl screamed. “What is it, Julia? Why don’t you speak?”
But never a sound nor a word gave back the livid silence, never a sigh nor
a breath, though Julia must be standing within a yard of the bed.
“Oh, she is only trying to frighten me, the beast!” poor Geraldine
thought; and, unable for another second to bear the cruel silence, she timidly
stretched out a hand to touch her sister—when, to her infinite relief, her
fingers touched the white rabbit fur with which Julia’s dressing-gown was
delicately trimmed.
“You beast, Julia!” she sobbed and laughed. Never a word, however,
came from the still shape. Geraldine, impatient of the continuation of a joke
which seemed to her in the worst of taste, raised her hand from the fur, that
she might touch her sister’s face; but her fingers had risen no further than
Julia’s throat when they touched something wet and warm, and with a
scream of indescribable terror Geraldine fainted away.
When Mr. Biggot-Baggot admitted himself into the house early the next
morning, his eyes were assailed by a dreadful sight. At the foot of the stairs
was a pool of blood, from which, in a loathsome trail, drops of blood wound
up the stairway.
Mr. Biggot-Baggot, fearful lest something out-of-the-way had happened
to his beloved daughters, rushed frantically up the stairs. The trail of blood
led to his daughters’ room; and there, in the doorway, the poor gentleman
stood appalled, so foul was the sight that met his eyes. His beloved
Geraldine lay on the bed, her hair snow-white, her lips raving with the shrill
fancies of a maniac. While on the floor beside the bed lay stretched, in a
pool of blood, his beloved Julia, her head half-severed from her trunk.
The tragic story unfolded only when the police arrived. It then became
clear that Julia, her head half-severed from her body, and therefore a corpse,
had yet, with indomitable purpose, come upstairs to warn her timid sister
against the homicidal lunatic who, just escaped from an Asylum nearby, had
penetrated into the house. However, the police consoled the distracted father
not a little by pointing out that the escape of the homicidal lunatic from the
Asylum had done some good, insomuch as there would now be room in an
Asylum near her home for Geraldine.
III
When the gentleman from America had read the last line of The Phantom
Foot-steps he closed the book with a slam and, in his bitter impatience with
the impossible work, was making to hurl it across the room when,
unfortunately, his circling arm overturned the candle. The candle, of course,
went out.
“Aw, hell!” said Mr. Puce bitterly, and he thought: “Another good mark to
Sir Cyril Quillier! Won’t I Sir him one some day! For only a lousy guy with
a face like a drummer’s overdraft would have bought a damfool book like
that.”
The tale of The Phantom Foot-steps had annoyed him very much; but
what annoyed him even more was the candle’s extinction, for the gentleman
from America knew himself too well to bet a nickel on his chances of
remaining awake in a dark room.
He did, however, manage to keep awake for some time merely by
concentrating on wicked words: on Quillier’s face, and how its tired,
mocking expression would change for the better were his, Puce’s, foot to be
firmly pressed down on its surface: and on Julia and Geraldine. For the
luckless twins, by the almost criminal idiocy with which they were
presented, kept walking about Mr. Puce’s mind; and as he began to nod to
the demands of a healthy and tired body he could not resist wondering if
their home town had been Wigan or Bolton and if Julia’s head had been
severed from ear to ear or only half-way....
When he awoke, it was the stillness of the room that impressed his
sharply awakened senses. The room was very still.
“Who’s there!” snapped Mr. Puce. Then, really awake, laughed at
himself. “Say, what would plucky little Julia have done?” he thought,
chuckling. “Why, got up and looked!”
But the gentleman from America discovered in himself a reluctance to
move from the bed. He was very comfortable on the bed. Besides, he had no
light and could see nothing if he did move. Besides, he had heard nothing at
all, not the faintest noise. He had merely awoken rather more sharply than
usual....
Suddenly, he sat up on the bed, his back against the oak head. Something
had moved in the room. He was certain something had moved. Somewhere
by the foot of the bed.
“Aw, drop that!” laughed Mr. Puce.
His eyes peering into the darkness, Mr. Puce stretched his right hand to
the table on which stood the automatic. The gesture reminded him of
Geraldine’s when she had touched the white rabbit fur—Aw, Geraldine
nothing! Those idiotic twins kept chasing about a man’s mind. The
gentleman from America grasped the automatic firmly in his hand. His hand
felt as though it had been born grasping an automatic.
“I want to tell you,” said Mr. Puce into the darkness, “that someone is
now going to have something coming to him, her or it.”
It was quite delicious, the feeling that he was not frightened. He had
always known he was a helluva fellow. But he had never been quite certain.
Now he was certain. He was regular.
But, if anything had moved, it moved no more. Maybe, though, nothing
had moved at all, ever. Maybe it was only his half-awakened senses that had
played him a trick. He was rather sorry, if that was so. He was just beginning
to enjoy the evening.
The room was very still. The gentleman from America could only hear
himself breathing.
Something moved again, distinctly.
“What the hell!” snapped Mr. Puce.
He levelled the automatic towards the foot of the bed.
“I will now,” said Mr. Puce grimly, “shoot.”
The room was very still. The gentleman from America wished, forcibly,
that he had a light. It was no good leaving the bed without a light. He’d only
fall over the infernal thing, whatever it was. What would plucky little Julia
have done? Aw, Julia nothing! He strained his ears to catch another
movement, but he could only hear himself breathing—in short, sharp gasps!
The gentleman from America pulled himself together.
“Say, listen!” he snapped into the darkness. “I am going to count ten. I am
then going to shoot. In the meanwhile you can make up your mind whether
or not you are going to stay right here to watch the explosion. One. Two.
Three. Four....”
Then Mr. Puce interrupted himself. He had to. It was so funny. He
laughed. He heard himself laugh, and again it was quite delicious, the feeling
that he was not frightened. And wouldn’t they laugh, the boys at the Booster
Club back home, when he sprung this yarn on them! He could hear them.
Oh, Boy! Say, listen, trying to scare him, Howard Cornelius Puce, with a
ghost like that! Aw, it was like shooting craps with a guy that couldn’t count.
Poor old Quillier! Never bet less than five hundred on anything, didn’t he,
the poor boob! Well, there wasn’t a ghost made, with or without a head on
him, that could put the wind up Howard Puce. No, sir!
For, as his eyes had grown accustomed to the darkness, and helped by the
mockery of light that the clouded, moonless night just managed to thrust
through the distant window, the gentleman from America had been able to
make out a form at the foot of the bed. He could only see its upper half, and
that appeared to end above the throat. The phantom had no head. Whereas
Julia’s head had been only half-severed from—Aw, what the hell!
“A family like the Kerr-Andersons,” began Mr. Puce, chuckling—but
suddenly found, to his astonishment, that he was shouting at the top of his
voice: anyhow, it sounded so. However, he began again, much lower, but
still chuckling:
“Say, listen, Mr. Ghost, a family like the Kerr-Andersons might have
afforded a head and a suit of clothes for their family ghost. Sir, you are one
big bum phantom!” Again, unaccountably, Mr. Puce found himself shouting
at the top of his voice. “I am going on counting,” he added grimly.
And, his automatic levelled at the thing’s heart, the gentleman from
America went on counting. His voice was steady.
“Five ... six....”
He sat crouched at the head of the bed, his eyes never off the thing’s
breast. Phantom nothing! He didn’t believe in that no-head bunk. What the
hell! He thought of getting a little nearer the foot of the bed and catching the
thing a whack on that invisible head of his, but decided to stay where he
was.
“Seven ... eight....”
He hadn’t seen the hands before. Gee, some hands! And arms! Holy
Moses, he’d got long arms to him, he had....
“Nine!” said the gentleman from America.
Christopher and Columbus, but this would make some tale back home!
Yes, sir! Not a bad idea of Quillier’s, that, though! Those arms. Long as old
glory ... long as the bed! Not bad for Sir Cyril Quillier, that idea....
“Ten, you swine!” yelled the gentleman from America and fired.
Someone laughed. Mr. Puce quite distinctly heard himself laughing, and
that made him laugh again. Fur goodness’ sake, what a shot! Missed from
that distance!
His eyes, as he made to take aim again, were bothered by the drops of
sweat from his forehead. “Aw, what the hell!” said Mr. Puce, and fired again.
The silence after the second shot was like a black cloud on the darkness.
Mr. Puce thought out the wickedest word he knew, and said it. Well, he
wasn’t going to miss again. No, sir! His hand was steady as iron, too. Iron
was his second name. And again the gentleman from America found it quite
delicious, the feeling that he was not frightened. Attaboy! The drops of sweat
from his forehead bothered him, though. Aw, what the hell, that was only
excitement.
He raised his arm for the third shot. Jupiter and Jane, but he’d learn that
ghost to stop ghosting! He was certainly sorry for that ghost. He wished,
though, that he could concentrate more on the actual body of the headless
thing. There it was, darn it, at the foot of the bed, staring at him—well, it
would have been staring at him if it had a head. Aw, of course it had a head!
It was only Quillier with his lousy face in a black wrap. Sir Cyril Quillier’d
get one piece of lead in him this time, though. His own fault, the bastard.
“Say, listen, Quillier,” said the gentleman from America, “I want to tell
you that unless you quit you are a corpse. Now I mean it, sure as my name is
Howard Cornelius Puce. I have been shooting to miss so far. Yes, sir. But I
am now annoyed. You get me, kid?”
If only, though, he could concentrate more on the body of the thing. His
eyes kept wandering to the hands and arms. Gee, but they sure were long,
those arms! As long as the bed, no less. Just long enough for the hands to get
at him from the foot of the bed. And that’s what they were at, what’s more!
Coming nearer. What the hell! They were moving, those doggone arms,
nearer and nearer....
Mr. Puce fired again.
That was no miss. He knew that was no miss. Right through the heart,
that little boy must have gone. In that darkness he couldn’t see more than
just the shape of the thing. Aw, Goddammit! But it was still now. The arms
were still. They weren’t moving any more. The gentleman from America
chuckled. That one had shown him that it’s a wise little crack of a ghost that
stops ghosting. Yes, sir! It certainly would fall in a moment, dead as
Argentine mutton.
Mr. Puce then swore. Those arms were moving again. The hands weren’t
a yard from him now. What the hell! They were for his throat, Goddammit.
“You swine!” sobbed the gentleman from America, and fired again. But
he wouldn’t wait this time. No, sir! He’d let that ghost have a ton of lead.
Mr. Puce fired again. Those hands weren’t half-a-yard from his throat now.
No good shooting at the hands, though. Thing was to get the thing through
the heart. Mr. Puce fired the sixth bullet. Right into the thing’s chest. The
sweat bothered his eyes. “Aw, hell!” said Mr. Puce. He wished the bed was a
bit longer. He couldn’t get back any more. Those arms.... Holy Moses; long
as hell, weren’t they! Mr. Puce fired the seventh, eighth ... ninth. Right into
the thing. The revolver fell from Mr. Puce’s shaking fingers. Mr. Puce heard
himself screaming.
IV
Towards noon on a summer’s day several years later two men were sitting
before an inn some miles from the ancient town of Lincoln. Drawn up in the
shade of a towering ash was a large grey touring-car, covered with dust. On
the worn table stood two tankards of ale. The travellers rested in silence and
content, smoking.
The road by which the inn stood was really no more than a lane, and the
peace of the motorists was not disturbed by the traffic of a main road.
Indeed, the only human being visible was a distant speck on the dust,
coming towards them. He seemed, however, to be making a good pace, for
he soon drew near.
“If,” said the elder of the two men, in a low tired voice, “if we take the
short cut through Carmion Wood, we will be at Malmanor for lunch.”
“Then you’ll go short-cutting alone,” said the other firmly. “I’ve heard
enough tales about Carmion Wood to last me a lifetime without my adding
one more to them. And as for spooks, one is enough for this child in one
lifetime, thanks very much.”
The two men, for lack of any other distraction, watched the pedestrian
draw near. He turned out to be a giant of a man; and had, apparently, no
intention of resting at the inn. The very air of the tall pedestrian was a
challenge to the lazy content of the sunlit noon. He was walking at a great
pace, his felt hat swinging from his hand. A giant he was: his hair greying:
his massive face set with assurance.
“By all that’s holy!” gasped the elder of the two observers. A little lean
gentleman that was, with a lined face which had been handsome in a striking
way but for the haggard marks of the dissipations of a man of the world. He
had only one arm, and that added a curiously flippant air of devilry to his
little, lean, sardonic person.
“Puce!” yelled the other, a young man with a chubby, good-humoured
face. “Puce, you silly old ass! Come here at once!”
The giant swung round at the good-natured cry, stared at the two smiling
men. Then the massive face broke into the old, genial smile by which his
friends had always known and loved the gentleman from America, and he
came towards them with hand outstretched.
“Well, boys!” laughed Mr. Puce. “This is one big surprise. But it’s good
to see you again, I’ll say that.”
“The years have rolled on, Puce, the years have rolled on,” sighed
Quillier in his tired way, but warmly enough he shook the gentleman from
America with his one hand.
“They certainly have!” said Mr. Puce, mopping his brow and smiling
down on the two. “And by the look of that arm, Quillier, I’ll say you’re no
stranger to war.”
“Sit down, old Puce, and have a drink,” laughed Kerr-Anderson. Always
gay, was Kerr-Anderson.
But the gentleman from America seemed, as he stood there, uncertain. He
glanced down the way he had come. Quillier, watching him, saw that he was
fagged out. Eleven years had made a great difference to Mr. Puce. He looked
old, worn, a wreck of the hearty giant who was once Howard Cornelius
Puce.
“Come, sit down, Puce,” he said kindly, and quite briskly, for him. “Do
you realise, man, that it’s eleven years since that idiotic night? What are you
doing? Taking a walking-tour?”
Mr. Puce sat down on the stained bench beside them. His massive
presence, his massive smile, seemed to fill the whole air about the two men.
“Walking-tour? That is so, more or less,” smiled Mr. Puce; and, with a
flash of his old humour: “I want to tell you boys that I am the daughter of the
King of Egypt, but I am dressed as a man because I am travelling incognito.
Eleven years is it, since we met? A whale of a time, eleven years!”
“Why, there’s been quite a war since then,” chuckled Kerr-Anderson.
“But still that night seems like last night. I am glad to see you again, old
Puce! But, by Heaven, we owe you one for giving us the scare of our lives!
Don’t we, Quillier?”
“That’s right, Puce,” smiled Quillier. “We owe you one all right. But I am
heartily glad that it was only a shock you had, and that you were quite
yourself after all. And so here we are gathered together again by blind
chance, eleven years older, eleven years wiser. Have a drink, Puce?”
The gentleman from America was looking from one to the other of the
two. The smile on the massive face seemed one of utter bewilderment.
Quillier was shocked at the ravages of a mere eleven years on the man’s
face.
“I gave you two a scare!” echoed Mr. Puce. “Aw, put it to music, boys!
What the hell! How the blazes did I give you two a scare?”
Kerr-Anderson was quite delighted to explain. The scare of eleven years
ago was part of the fun of to-day. Many a time he had told the tale to while
away the boredom of Flanders and Mesopotamia, and had often wanted to
let old Puce in on it to enjoy the joke on Quillier and himself but had never
had the chance to get hold of him.
They had thought, that night, that Puce was dead. Quillier, naked from the
waist up, had rushed down to Kerr-Anderson, waiting in the dark porch, and
had told him that Puce had kicked the bucket. Quillier had sworn like
nothing on earth as he dashed on his clothes. Awkward, Puce’s corpse, for
Quillier and Kerr-Anderson. Quillier, thank Heaven, had had the sense not to
leave the empty revolver on the bed. They shoved back all the ghost
properties into a bag. And as, of course, the house wasn’t Kerr-Anderson’s
aunt’s house at all, but Johnny Paramour’s, who was away, they couldn’t so
easily be traced. Still, awkward for them, very. They cleared the country that
night. Quillier swearing all the way about the weak hearts of giants. And it
wasn’t until the Orient Express had pitched them out at Vienna that they saw
in the Continental Daily Mail that an American of the name of Puce had
been found by the caretaker in the bedroom of a house in Grosvenor Square,
suffering from shock and nervous breakdown. Poor old Puce! Good old
Puce! But he’d had the laugh on them all right....
And heartily enough the gentleman from America appeared to enjoy the
joke on Quillier and Kerr-Anderson.
“That’s good!” he laughed. “That’s very good!”
“Of course,” said Quillier in his tired, deprecating way, “we took the
stake, this boy and I. For if you hadn’t collapsed you would certainly have
run out of that room like a Mussulman from a ham-sandwich.”
“That’s all right,” laughed Mr. Puce. “But what I want to know, Quillier,
is how you got me so scared?”
Kerr-Anderson says now that Puce was looking at Quillier quite amiably.
Full in the face, and very close to him, but quite amiably. Quillier smiled, in
his deprecating way.
“Oh, an old trick, Puce! A black rag over the head, a couple of yards of
stuffed cloth for arms....”
“Aw, steady!” said Mr. Puce. But quite amiably. “Say, listen, I shot at
you! Nine times. How about that?”
“Dear, oh, dear!” laughed Kerr-Anderson. But that was the last time he
laughed that day.
“My dear Puce,” said Quillier gently, slightly waving his one arm. “That
is the oldest trick of all. I was in a panic all the time that you would think of
it and chuck the gun at my head. Those bullets in your automatic were
blanks.”
Kerr-Anderson isn’t at all sure what exactly happened then. All he
remembers is that Puce’s huge face had suddenly gone crimson, which made
his hair stand out shockingly white; and that Puce had Quillier’s fragile
throat between his hands; and that Puce was roaring and spitting into
Quillier’s blackening face.
“Say, listen, you Quillier! You’d scare me like that, would you! You’d
scare me with a chicken’s trick like that, would you! And you’d strangle me,
eh? You swine, you Sir Cyril Quillier you, right here’s where the strangling
comes in, and it’s me that’s going to do it——”
Kerr-Anderson hit out and yelled. Quillier was helpless with his one arm,
the giant’s grip on his throat. The woman who kept the inn had hysterics.
Puce roared blasphemies. Quillier was doubled back over the small table,
Puce on top of him, tightening his death-hold. Kerr-Anderson hit, kicked,
bit, yelled.
Suddenly there were shouts from all around.
“For God’s sake, quick!” sobbed Kerr-Anderson. “He’s almost killed
him.”
“Aw, what the hell!” roared Puce.
The men in dark uniforms had all they could do to drag him away from
that little, lean, blackened, unconscious thing. Then they manacled Puce.
Puce looked sheepish, and grinned at Kerr-Anderson.
Two of the six men in dark uniforms helped to revive Quillier.
“Drinks,” gasped Kerr-Anderson to the woman who kept the inn.
“Say, give me one,” begged the gentleman from America. Huge, helpless,
manacled, he stood sheepishly among his uniformed captors. Kerr-Anderson
stared at them. Quillier was reviving.
“Gets like that,” said the head warder indifferently. “Gave us the slip this
morning. Certain death for someone. Homicidal maniac, that’s ’im. And he’s
the devil to hold. Been like that eleven years. Got a shock, I fancy. Keeps on
talking about a sister of his called Julia who was murdered and how he’ll be
revenged for it....”
Kerr-Anderson had turned away. Quillier sobbed: “God have mercy on
us!” The gentleman from America suddenly roared with laughter.
“Can’t be helped,” said the head warder. “Sorry you were put to trouble,
sir. Good-day, gentlemen. Glad it was no worse.”
IX: TO LAMOIR
A LAS, it is a pity I know so little of trees and flowers, and how I shall
tell this tale without their help I cannot imagine, for it is a tale that
demands a profound knowledge of still, gentle things. But I daresay it
will get itself written somehow, and saying that leads us to quite another
question, for serious men will have it that that is the pity of nearly all the
writing of our time, it just gets itself written somehow.
Now it is difficult not to think a little of my own life in telling of Hugh
and Lamoir, for they helped me when I was very young, for a long time
they were my only friends in London, and ever since they have remained
the dearest. But it was only the other day that Hugh told me about the tree. I
suppose he must have had a sort of idea of what might happen and wanted
to tell someone about it while he could. But it’s odd that I had known him
all those years, him and Lamoir, and he had never so much as mentioned
the tree—when out he suddenly comes with it!
Of course there will be those to say that he hadn’t concealed anything
worth concealing, that it’s an impossible story anyhow, and who could
believe it? But I do believe it decidedly, for how could Hugh have made it
up? Hugh wasn’t an imaginative man, not a bit. That, in point of fact, is
what the story is about. Of course, he had a passion for fine things, a
passion for touching fine things, but your collector or your connoisseur isn’t
generally anything of an imaginative man. Lamoir, now, she was quite
different, and she might easily have thought of the garden and the tree and
the whole business, but so far as I can make out Hugh and Lamoir never
once breathed a word to each other about it.
I have never been able to think of Lamoir quite steadily, I liked her too
much. I know a writer is supposed to be impersonal, but that can’t be
helped. She knew the very hearts of trees and flowers, Lamoir did, and she
was always so still and quiet, like a flower herself, that you never knew
what she was thinking of. And that is more or less how the trouble between
them began, so Hugh told me the other day. He never knew what she was
thinking of, but he hoped for the best, and then one day he found that she
had been thinking away from him all the time. That is what Hugh said. But
I feel that the truth of it was that he never thought Lamoir was thinking of
anything at all, except maybe about what a good husband he was, and then
one day he got a shock. Many men seem to be like that, they have happy
natures, for when their wives are quiet and thoughtful they never dream that
those thoughts might be out of accord with their own, and when they do at
last realise that something has been wrong all the time they are surprised
and hurt and want to know why they were not told sooner. As though, you
know, some things can be told sooner, as though some things can be told
until it is too late!
Now Hugh and Lamoir were a difficult pair to know, together or singly.
Hugh wasn’t at all your democratic sort, there was nothing at all easy-going
about him. I remember once seeing him in a crowded room and thinking he
was like an island of nerves in an ocean of grins. Lamoir said he was proud.
He simply didn’t seem to concern himself at all with other people’s
opinions; it was as though he just hadn’t the time to go about dealing in the
slack forms of geniality which pass for manners in this century. That is
Hugh’s phrase, not mine. Lamoir left him about nine years ago.
They say that people made a great fuss over Lamoir when she first came
from India, because she was so lovely. That must have been about twenty-
five years ago, and about nine years ago she packed up a lot of trunks and
went to Algeria. People were very surprised at that, for Lamoir was beloved
of everyone, and she seemed to be liking her life in England—as much,
anyhow, as anyone ever does seem to like his or her life in England, for
there seems to be a feeling in people that one shouldn’t like living in
England. I like it very much myself, but then I am not English. People said
vaguely that she was going away because her heart was weak—quite all
right, but weak, and that she must have quiet. She never came back.
I went to see her in Algeria two winters ago. I wanted very much just to
see how she was in that solitary new life. Naturally I didn’t tell Hugh the
main reason why I was going to Algeria, and I think he had an idea I was
going there to try to write a book about it, one of those marvellous books
about sheiks and sand and suburban Englishwomen with love flaming in
their eyes to such a degree that none of their friends at home would ever
recognise them. As Hugh never used to speak of his wife one had nothing to
go on as to what his feelings about her were, and so, of course, one said
nothing about her either.
Just the same, that is how I found Lamoir. She had the grace of silence,
of reflection, to a rare degree. Some people found her frightfully dull, but
then imagine what “some people” are, it can be said that their disapproval is
a distinction that no fairly admirable person should ever be without. The
house she was living in had been the palace of the last of the Admirals of
the Dey’s fleet, Lamoir said, and one could well believe it. There were
dungeons below, deep, dark, crooked, with chains and iron clamps on the
walls where the poor devils of Christian slaves used to be kept, and on the
morning Lamoir was showing me round there was a vampire-bat hanging
asleep from the black broken walls. From the dungeons there was a secret
passage, Lamoir said, down to the bay two miles away at the foot of the
hill, and through this passage the old Admiral scoundrel had tried to escape
when the French stormed the town about eighty years ago—or maybe it was
more or less than eighty years ago; I don’t know when it was, and Lamoir
didn’t know either.
One morning we were walking about on the pink tiles of the flat, uneven
roof, not talking much, while below the sea slept. Lamoir asked after Hugh,
just how he was, and I said he was quite well. “Lonely,” I added.
We sat on the parapet of the roof, looking down the hill at the white
untidy town. There was an American liner in the bay, like a smudge. At last
Lamoir said: “Yes, he was always lonely. Lonely and proud. Hugh is very
proud. Don’t you think so?”
I said: “And you, Lamoir, aren’t you proud, too?”
You see, I knew nothing of the difficulty between Hugh and Lamoir. All
I knew was that two dear friends of mine had parted from each other nine
years before. Lamoir was looking towards the sea, she was smiling. Then
she shook her head suddenly. Her hair was quite grey, and short, and curly
—you can see how attractive Lamoir was, an autumnal flower.
“Oh, no!” she said. “I’m not proud, not a bit. And I don’t like proud
people.”
“I do!” I said.
She said gravely: “You do, of course. But you are young, and it’s quite
right that you should like proud people and should try to be proud yourself,
though I should think your sense of humour would bother you a little while
you were trying. I think young people should be proud, because if they are
not they will put up with makeshifts and get dirty; but elderly people and
old people should not be proud, because it prevents them from
understanding anything.”
“But elderly people,” I said, “don’t they get dirty too, if they’re not
proud?”
She laughed at me, and all she said was: “I was talking about nice
elderly people.” And there the conversation ended, just nowhere. I think it
very silly in a man to go generalising about women, but if I were to start
generalising I might say that most abstract conversations between men end
nowhere, but you have a feeling that at least something interesting has
passed, while with a woman an abstract conversation ends nowhere and you
have a feeling that she has only been talking about whatever it was just out
of politeness.
I remember that what struck me most about Lamoir at that time was how
happy she was, happy and feeling safe in her happiness. That puzzled me
then, for I knew she loved Hugh.
II
I would see a good deal of Hugh, sometimes going to stay with him at
Langton Weaver, and often, in London, dining with him at his house in
Charles Street, just he and I alone. It was very pleasant to know of a quiet
house in which I might now and then pass an evening talking, as one always
did with Hugh if one talked at all, of books and tapestries and fine things. I
never knew a man who had such a passion for the touch of fine things as
Hugh, and seeing him thoughtfully holding a little old ivory figure in his
hand one might almost think his skin was in love with it.
But a few weeks ago, the last time I was ever to dine with my friend, it
instantly struck me that he was in quite a different mood. And presently he
told me about the garden and the tree. He didn’t preface it with anything in
particular, he was thoughtfully twisting the stem of his port-glass when he
said: “Nearly nine years since I have seen Lamoir——”
I said vaguely: “Yes....” Never once, you see, in all those nine years, had
he so much as mentioned the name of Lamoir, and so I felt rather stunned at
first.
Hugh went on thoughtfully, not particularly to me: “And the first time I
saw her I was nine years old. She must have been seven.”
I said: “But I always understood that Lamoir passed her childhood in
India and never came to England until she was twenty or so! I’d no idea you
too were in India when you were little.”
“I wasn’t,” he said, and he smiled, I think out of shyness just because he
was talking about himself. “I wasn’t. That’s why, you see, it was so funny
——”
I was trying to imagine Lamoir seven years old. It was easy, of course, as
it always is easy with people one likes. Her curly grey hair would be golden
then, and maybe her grey eyes would be more blue than grey, and they
would look enormous in a tiny face. And she would be walking, very still,
making no noise at all, with two thin brown sticks for legs and two blue
pools for eyes, very thoughtful indeed, and all this would be happening in a
garden of red and yellow flowers with a long low white house nearby. That
was how Hugh first saw Lamoir, in a garden, and nearby a long low white
house with a broad flight of steps up to the open doorway and tall, shining
windows.
Dazzling white the house seemed to him, Hugh said, but that must have
been because there was a very brilliant sun that afternoon. There was no
noise, except just summer noises, and although he didn’t remember actually
seeing any birds there must have been a lot of birds about, because he heard
them. And simply masses of flowers there were in that garden, red and
yellow flowers, and over a grey wall somewhere there was hung a thick
curtain of flowers that may have been blue roses. And they may very well
have been blue roses, Hugh said. And bang in the middle of all those
flowers was Lamoir, staring at him as he came into the garden. Hugh was so
surprised, he said, that he didn’t know what to say or do.
He hadn’t, you see, intended coming into that garden at all. He hadn’t, a
moment before, known anything at all about that garden or whose garden it
was or even that there was a garden there at all. That is the funny part about
the whole thing, the way it just sprung out at him, garden, Lamoir, blue
roses and all, out of the summer afternoon. But there it was, and there
Lamoir was, staring at Hugh. Not that she looked a bit surprised, Hugh said,
although she was such a kid. She just stuck her finger into her mouth and
came towards him.
Hugh’s father’s place, Langton Weaver, lay on the slope of a low hill not
far from Hungerford, looking over the plain towards where the old red
Elizabethan pile of Littlecott lies embowered in trees. Hugh, that bright
afternoon, was kicking his heels about in the lane outside his father’s gates,
which was of course against all rules. But Hugh was lonely that afternoon,
he never had any brothers or sisters, and he was wondering what he would
do next, and he was hoping that someone would come along to do
something with—when, bang, there he was in that garden and a little kid
advancing on him with a finger stuck in her mouth. It was very odd, Hugh
said.
“Hullo!” she said. All eyes, that’s what she was.
“Hullo!” Hugh said. She was only a kid, after all. Hugh was nine.
“You’re a boy,” she said.
“Of course I’m a boy,” Hugh said, and he was going to add “just as
you’re a girl,” but a fellow couldn’t stand there arguing all day with a slip
of a thing like that. Then he suddenly remembered he didn’t know where he
was.
“I say,” he said, “I don’t know how I got here. What’s this place?”
She twisted her finger out of her mouth and stared at the wet thing. Hugh
remembered that it shone in the sun. And her hair shone in the sun, too.
Hugh said her hair shone even when they were in the shade. But of course
he didn’t attach any importance to that kind of thing.
“I say, where am I?” Hugh asked again. He must have sounded pathetic,
in spite of himself.
“You’re here,” she said. “What’s your name?”
“Hugh,” he said. “But, I say, where’s here? I’ve never seen that house
before. My father’s got the biggest house round here, Langton Weaver. My
father’s Lord of the Manor, and when he’s dead I’m Lord of the Manor.”
“Oo!” she said, staring.
Hugh said he felt frightfully let down. Any other kid would have exalted
the merits of her own house, but she just swallowed everything and stared
at you. Hugh said he felt as though he had been boasting.
“Our house doesn’t look so jolly clean as this,” he said. “Rather live
here, any day.”
And he suddenly realised he was speaking the truth. That was the
amazing part of it, Hugh said: suddenly to feel that he would much rather
live here than in his father’s house. With this kid. And from that moment,
somehow, he forgot every particle of his surprise at being in that garden.
“What’s your name?” he asked.
“Not got a name,” the kid said. “No name.” All legs and eyes, that’s
what she was.
“But you must have a name!” Hugh cried. “Everyone’s got names, even
dogs and cats. We’ve got seven dogs and they’re all called after every day
in the week except one because you can’t call a dog Sunday, father says.”
“No name,” she said breathlessly. “I’m me.”
“But look here, how do they call you when they want you?” He thought
he’d got her there all right, Hugh said.
She giggled. “I just come,” she giggled. “I don’t need to be called. Oo!
Just come when I’m wanted. Did you want me? You did, didn’t you?”
He stared at her, he was so dumbfounded. Jiminy, hadn’t he wanted her!
Anyhow, hadn’t he wanted something to happen. But how had this kid
known that?
“Look here, no rotting!” he warned her.
“Not rotting,” she said, sucking her finger. “What’s rotting?”
“But what’s this place?” he asked almost frantically. “Hasn’t it got a
name either?”
“Oo, yes! Playmate Place.”
“It’s not!” Hugh cried. “Not Playmate Place! You’re rotting now.”
Hugh says she took her finger out of her mouth, stamped her foot and
screamed at one and the same time. “It is called Playmate Place and
Playmate Place and Playmate Place! So there!”
“Oh, all right!” Hugh said, and he didn’t let on any further about his
opinion of a house called Playmate Place. Hugh says a boy of nine would
rather die than live in a house called Playmate Place. It sounded so soft. But
she was only a kid, after all, and she couldn’t know anything.
“I’m going to run now,” the kid said, standing on one leg and staring at
the other.
That was too much, Hugh said. She was going to run! As though she
could run! “Beat you blindfolded,” he just said.
“Oo, you try!” she giggled, and she turned, and she flew. She just flew,
Hugh said. All brown legs and golden hair. He hadn’t a chance. But he must
have been quite a nice boy really, Hugh said, because he began laughing at
himself. He beat this kid!
She stopped, miles away, just under a tree. Hugh panted on. And they
must have run some distance, for the house and the blue roses were no
longer visible. Hugh couldn’t remember any of the particulars of where they
were now. There was a sense of flowers, he said, clean flowers, a lot of
flowers. And that tree, under which Lamoir was waiting for him. Of course
he didn’t know she was Lamoir then. That tree seemed to him a big tree.
Hugh said that when you touched it it smelt like a sort of echo of all the
good smells you had ever smelt.
But he hadn’t come quite up to her when she turned and, before you
could say “knife,” shinned up that tree!
“I say!” cried Hugh.
“Can’t catch me!” panted a little voice from among the leaves.
“Can if I want to,” said Hugh, looking up. All he could see between the
leaves was something white.
“Like you to want to,” piped the something white, and Hugh fell in love
for the first and last time in his life.
When he caught up with her, on a branch high up, she said “Oo!” and
gave him a damp kiss on his cheek. She didn’t giggle or anything, she was
as serious as a man playing cricket. Hugh felt rather ashamed.
“Look here,” he said, to say something, “what’s this tree called? Never
seen a tree like this before.”
“It’s a lovely tree,” she said, staring. “It’s called Playmate Tree, of
course.”
“That’s a soft word, playmate,” Hugh rashly said.
She stared at him with those big grey eyes, Hugh said, so that he began
to feel weak, just weak with meanness. And then she said “Yow!” and wept.
Well! She wept. Hugh didn’t know what to do, stuck up there on a branch of
a tree and this kid crying fit to break her kid’s heart. He kept muttering, “I
say, I’m sorry,” and things like that, and then he found she was somehow in
his arms, and he kissing her and kissing her hair. Her hair smelt like the
tree, Hugh said, so it must have been a funny sort of tree.
“Kiss the tree now,” the small voice said. “You’ve hurt it.”
“Oh, I say!” said Hugh, but he did as he was told, and then they climbed
down the magic tree in silence, he trying to help her and almost breaking
his neck. They walked slowly back, hand in hand, towards where the house
was, through the sweet lush grass. There was music somewhere, Hugh said.
Or maybe there wasn’t and he only thought there was. And Hugh said that
he was happier at that moment than he had ever been since in his whole life.
“Mustn’t laugh at words like playmate,” said the wise kid. “You’ll get
hurt if you do.”
“I say, I’d like to see you again,” Hugh said shyly, and he found himself
walking on the dusty lane towards Nasyngton! He was almost in
Nasyngton, he could see, down the slope, the thick old bridge over the
Kennet. He must have walked two miles or more while he thought he was
in that garden. Playmate Place. He stopped to wipe his face, wondering
passionately. He was simply streaming with perspiration. But what had
happened to that old garden, that’s what puzzled him. And that kid! That
jolly little kid. He rubbed his cheek, but he couldn’t be certain if there still
was a damp patch where she had kissed him. Anyhow, it would have dried
by then, and, anyhow again, he’d got so hot since.
When he got home Hugh told Hugh’s father the outline of his adventure,
and Hugh’s father told Hugh he had broken rules by being outside the gates
at all and that he must have been dreaming, but Hugh said passionately that
he was sorry he had broken rules but he hadn’t been anything like
dreaming, and Hugh’s father told Hugh not to be an ass, and two years later
Hugh’s father died.
Hugh did not see the garden of the white house again. Playmate Place.
Hugh, as he grew up, blushed to think of Playmate Place. He had blushed at
the time, and later on he blushed at the very thought of it. He wouldn’t have
dared let any of his friends at school even dream of his ever having
swallowed such a soft yarn as the Playmate Place one. But, despite himself,
the face of the kid whose name was to be Lamoir stayed with him, and her
silver voice, and her enormous eyes. And now and then in his dreams, Hugh
said, he would seem to hear the faint echo of an “Oo!”
III
It was almost twenty years to a day after the adventure of Playmate Place
that Hugh met Lamoir at a party at Mace, Guy de Travest’s place. Miss
Cavell her name was. He recognised her, he said, at once, at very first sight.
She had been seven then and she was twenty-seven now, but he knew her
on sight. And when she spoke, he was quite certain. Of course she didn’t
suck her finger and say “Oo!” any longer, but without a doubt Lamoir
Cavell was the grown-up of the kid of Playmate Place. And he actually
found himself wondering, as he talked to her that first time at Mace, if she
recognised him—and then he almost laughed aloud at his childishness, for
of course the whole thing had been a boy’s dream. But it was very odd, his
dreaming about someone he was actually to meet twenty years later. And
once he fancied, as he turned to her suddenly, that she was looking at him a
little strangely, in a puzzled sort of way maybe, with that small slanting
smile of hers as though she was smiling at something she just hadn’t said.
Oh, Lamoir must have been very beautiful then!
She was born in India, where old man Cavell was something in the Civil
Service, and she had lived in India until recently, when her father died.
Hugh, that first time, asked her if she had ever been in England as a child,
and she said, staring at him in a way that seemed so familiar to him that his
heart gave a throb: “Only in dreams.” But he didn’t tell her about the
Playmate Place then. Then was the time to tell her, then or never. He never
told her.
They walked in enchantment, those two, for the next few days. Guy de
Travest has told me since that the whole house-party went about on tiptoe,
so as not to disturb Hugh and Lamoir in their exquisite contemplation of
their triumph over the law of life, which is of course unknowable, but must
be pretty depressing, seeing what life is.
They were married in the little village church at Mace, and Hilary
Townshend was Hugh’s best man, and Hilary has told me since that he
almost wept to see them going away—knowing as he did so certainly,
Hilary said, that Hugh and Lamoir had taken the one step in life which will
wake any couple up from any dream.
Hugh continually pulled at the stiff grey affair on his upper lip as he told
me of his marriage. “It’s Playmate Place,” he said, “that is important in the
story: much more important than my married life. Lamoir and I never quite
reached Playmate Place in actual life. We were in sight of it sometimes—
when I let Lamoir have her head. But I only see that now, I didn’t realise it
then.”
He said that about the importance of Playmate Place quite seriously.
And, you know, I took it quite as seriously. A dream or vision or whatever it
was, that has lasted fresh in a man’s mind from the age of nine to the age of
forty-nine is, after all, a thing to be taken seriously. I haven’t, as a rule,
much patience with dreams; and there’s a deal too much talk of dreams in
the novels of the day, for it’s so easy to write “dream”; but Hugh’s, as they
say, rather “got” me.
He never spoke about it to Lamoir. “I began to, several times,” he said,
“but somehow I never went on. You see, there was such a difference
between our life together and the way we had been together in that garden. I
mean, such a tremendous difference in spirit. She was the same, but I—
well, I was the same, too, but only that ‘same’ which had jeered at the word
‘playmate.’ It’s difficult to explain. I knew, you see, as I said things that
might hurt her, that I was in the wrong—and I didn’t want to say them,
either—but somehow it was in me to say them and so I said them. It’s
somehow the impulses you can’t put into words that are the strongest.”
The marriage of Hugh and Lamoir appeared to have gone much the same
way as most marriages. At first they were very happy, and they were quite
certain that they were going to be even happier. Then they thought that
perhaps they were not so happy as they had been, and then they were quite
certain that they were not so happy as they had been. Hugh said it was more
or less like that.
Hugh, at the time, had thought privately that this was because Lamoir
did not take very much interest in his collections of fine things. Not that he
wasn’t quite contented with his marriage. Good Lord, contented! I wonder
what Lamoir thought about that. Contented! But she never confided, that
quiet Lamoir.
It was a great unhappiness to her, Hugh said, that there were no children.
A very great unhappiness. He hadn’t, he admitted, minded so much,
because year by year he was growing more absorbed in his collections.
Throughout his married life he would go off searching Europe for pieces.
Italy, Greece, Spain. At first he used to take Lamoir with him, but later on
she would stay at home. She preferred that, Hugh said. She wouldn’t stay in
the London house, but at Langton Weaver, the house which was larger but
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com