Description
This GitHub issue contains feedback on the TS 4.1-beta release from the team
that is responsible for keeping Google's internal software working with the
latest version of TypeScript.
Executive summary
-
We do not expect to have significant difficulty in upgrading Google to TS
4.1. -
We found one change to the emitted JS that broke our
tsickle
tool's output
in some cases. We will fixtsickle
to match the new behavior. -
Some changes to our TypeScript code are required to make it compile with TS
4.1.-
Most of the new errors reported by TS 4.1-beta are clearly related to
announced changes. -
The remaining new TS error messages are few and appear to report
legitimate source code errors that were previously missed by TS 4.0. -
Detail sections below explain the changes to our code we expect to make
to unblock the upgrade.
-
Impact summary
Change description | Announced | Libraries affected |
---|---|---|
CommonJS exports initialization emit change | no | 0.71% |
resolve() parameter required |
yes | 0.11% |
miscellaneous TS errors | no | 0.02% |
abstract async disallowed |
yes | 0.01% |
any /unknown propagated in Falsy positions |
yes | 0.01% |
The Announced column indicates whether we were able to connect the observed
change with a section in the
TS4.1-beta announcement.
The following sections give more detailed explanations of the changes listed
above.
CommonJS exports initialization emit change
Our tsickle
tool depends on CommonJS mode output from tsc
, which it further
converts into the goog.module()
format used by closure-compiler
.
In TS 3.9 tsc
started emitting a statement to initialize exported symbols to
void 0
before the statements that give those symbols their intended values.
This seems to be for reasons having to do with CommonJS spec. (See
#38552 (comment))
exports.p1 = exports.p2 = ... = exports.pN = void 0;
During our upgrade to TS 3.9, we updated tsickle
to recognize and drop this
statement, because it violates closure-compiler
's input expectations.
In TS 4.1 the emit changes so that the initialization is broken into one or more
statements containing no more than 50 variable assignments.
exports.p1 = exports.p2 = ... = exports.p50 = void 0;
exports.p51 = exports.p52 = ... = exports.pN = void 0;
This resulted in compile time errors from closure-compiler
, because tsickle
only recognized and removed the first statement.
We will update tsickle
to recognize and drop all of these statements. We have
confirmed with a draft change that doing so fixes all cases.
resolve()
parameter required
This change was an
announced part of TS 4.1-beta.
We believe fixing the type errors that arise from this change will improve the
quality of our code.
Our team will likely unblock the TS upgrade by inserting a cast to any
for
each of these errors along with a TODO
comment containing the error message
and a request to the team owning the code to investigate and make a more correct
fix when they can.
miscellaneous TS errors
There are several different error messages in this category, but all appear to
be cases where TS 4.1-beta correctly identifies coding mistakes that were
previously missed.
Exactly how we resolve these error messages will be determined later, but we
will likely resolve most of them by inserting a cast to any
for the error
along with a TODO
comment containing the error message and a request to the
team owning the code to investigate and make a more correct fix when they can.
abstract async
disallowed
This change was an
announced part of TS 4.1-beta.
This seems like a reasonable change to the language to us.
We expect to fix these errors by dropping the async
and changing the current
return type from T
to Promise<T>
.
any
/unknown
propagated in Falsy positions
This change was an
announced part of TS 4.1-beta.
We believe fixing the type errors that arise from this change improves the
quality of our code.
Our team will likely fix these errors by inserting !!
before the non-boolean
expression that causes the error.