Skip to content

Commit 570c756

Browse files
committed
Merge branch 'master' into any-constraint-as-upper-bound
2 parents 8e9c475 + 0ddcab3 commit 570c756

13 files changed

+850
-249
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Ken Howard <[email protected]>
121121
Kevin Lang <[email protected]>
122122
kimamula <[email protected]> # Kenji Imamula
123123
Kitson Kelly <[email protected]>
124+
Krishnadas Babu <[email protected]>
124125
Klaus Meinhardt <[email protected]>
125126
Kyle Kelley <[email protected]>
126127
Lorant Pinter <[email protected]>

CONTRIBUTING.md

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ In general, things we find useful when reviewing suggestions are:
4747

4848
# Instructions for Contributing Code
4949

50+
## Tips
51+
52+
### Faster clones
53+
54+
The TypeScript repository is relatively large. To save some time, you might want to clone it without the repo's full history using `git clone --depth=1`.
55+
56+
### Using local builds
57+
58+
Run `gulp build` to build a version of the compiler/language service that reflects changes you've made. You can then run `node <repo-root>/built/local/tsc.js` in place of `tsc` in your project. For example, to run `tsc --watch` from within the root of the repository on a file called `test.ts`, you can run `node ./built/local/tsc.js --watch test.ts`.
59+
5060
## Contributing bug fixes
5161

5262
TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved ("Milestone == Community") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort.

Gulpfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ gulp.task(
274274
// Generate Markdown spec
275275
const specMd = "doc/spec.md";
276276
gulp.task(specMd, /*help*/ false, [word2mdJs], () =>
277-
exec("cscript", ["//nologo", word2mdJs, path.resolve(specMd), path.resolve("doc/TypeScript Language Specification.docx")]));
277+
exec("cscript", ["//nologo", word2mdJs, path.resolve("doc/TypeScript Language Specification.docx"), path.resolve(specMd)]));
278278

279279
gulp.task(
280280
"generate-spec",
@@ -595,7 +595,7 @@ gulp.task(
595595
project.waitForWorkToStart().then(() => {
596596
source.cancel();
597597
});
598-
598+
599599
if (cmdLineOptions.tests || cmdLineOptions.failed) {
600600
await runConsoleTests(runJs, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ true, source.token);
601601
}

doc/spec.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ TypeScript is a trademark of Microsoft Corporation.
239239

240240
# <a name="1"/>1 Introduction
241241

242-
JavaScript applications such as web e-mail, maps, document editing, and collaboration tools are becoming an increasingly important part of the everyday computing. We designed TypeScript to meet the needs of the JavaScript programming teams that build and maintain large JavaScript programs. TypeScript helps programming teams to define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries. TypeScript also enables teams to reduce naming conflicts by organizing their code into dynamically-loadable modules. TypeScript's optional type system enables JavaScript programmers to use highly-productive development tools and practices: static checking, symbol-based navigation, statement completion, and code re-factoring.
242+
JavaScript applications such as web e-mail, maps, document editing, and collaboration tools are becoming an increasingly important part of the everyday computing. We designed TypeScript to meet the needs of the JavaScript programming teams that build and maintain large JavaScript programs. TypeScript helps programming teams to define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries. TypeScript also enables teams to reduce naming conflicts by organizing their code into dynamically-loadable modules. TypeScript's optional type system enables JavaScript programmers to use highly-productive development tools and practices: static checking, symbol-based navigation, statement completion, and code refactoring.
243243

244244
TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of ECMAScript 2015 (ES2015) syntax. Every JavaScript program is also a TypeScript program. The TypeScript compiler performs only file-local transformations on TypeScript programs and does not re-order variables declared in TypeScript. This leads to JavaScript output that closely matches the TypeScript input. TypeScript does not transform variable names, making tractable the direct debugging of emitted JavaScript. TypeScript optionally provides source maps, enabling source-level debugging. TypeScript tools typically emit JavaScript upon file save, preserving the test, edit, refresh cycle commonly used in JavaScript development.
245245

@@ -263,7 +263,7 @@ function f() {
263263
}
264264
```
265265

266-
To benefit from this inference, a programmer can use the TypeScript language service. For example, a code editor can incorporate the TypeScript language service and use the service to find the members of a string object as in the following screen shot.
266+
To benefit from this inference, a programmer can use the TypeScript language service. For example, a code editor can incorporate the TypeScript language service and use the service to find the members of a string object as in the following screenshot.
267267

268268
&emsp;&emsp;![](images/image1.png)
269269

@@ -411,7 +411,7 @@ We mentioned above that the '$' function behaves differently depending on the ty
411411
412412
This signature denotes that a function may be passed as the parameter of the '$' function. When a function is passed to '$', the jQuery library will invoke that function when a DOM document is ready. Because TypeScript supports overloading, tools can use TypeScript to show all available function signatures with their documentation tips and to give the correct documentation once a function has been called with a particular signature.
413413
414-
A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screen shot.
414+
A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screenshot.
415415
416416
&emsp;&emsp;![](images/image2.png)
417417
@@ -628,7 +628,7 @@ JavaScript implementations can use these explicit constants to generate efficien
628628

629629
An important goal of TypeScript is to provide accurate and straightforward types for existing JavaScript programming patterns. To that end, TypeScript includes generic types, discussed in the next section, and *overloading on string parameters*, the topic of this section.
630630

631-
JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method.
631+
JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screenshot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method.
632632

633633
&emsp;&emsp;![](images/image3.png)
634634

@@ -639,7 +639,7 @@ var span = document.createElement("span");
639639
span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property
640640
```
641641

642-
In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property.
642+
In the following screenshot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property.
643643

644644
&emsp;&emsp;![](images/image4.png)
645645

src/compiler/checker.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -4855,7 +4855,7 @@ namespace ts {
48554855

48564856
function getLiteralPropertyNameText(name: PropertyName) {
48574857
const type = getLiteralTypeFromPropertyName(name);
4858-
return type.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral) ? "" + (<LiteralType>type).value : undefined;
4858+
return type.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral) ? "" + (<StringLiteralType | NumberLiteralType>type).value : undefined;
48594859
}
48604860

48614861
/** Return the inferred type for a binding element */
@@ -6450,12 +6450,12 @@ namespace ts {
64506450
/**
64516451
* Gets the symbolic name for a late-bound member from its type.
64526452
*/
6453-
function getLateBoundNameFromType(type: LiteralType | UniqueESSymbolType): __String {
6453+
function getLateBoundNameFromType(type: StringLiteralType | NumberLiteralType | UniqueESSymbolType): __String {
64546454
if (type.flags & TypeFlags.UniqueESSymbol) {
64556455
return `__@${type.symbol.escapedName}@${getSymbolId(type.symbol)}` as __String;
64566456
}
64576457
if (type.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
6458-
return escapeLeadingUnderscores("" + (<LiteralType>type).value);
6458+
return escapeLeadingUnderscores("" + (<StringLiteralType | NumberLiteralType>type).value);
64596459
}
64606460
return Debug.fail();
64616461
}
@@ -6534,9 +6534,9 @@ namespace ts {
65346534
// If we have an existing early-bound member, combine its declarations so that we can
65356535
// report an error at each declaration.
65366536
const declarations = earlySymbol ? concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
6537-
const name = declarationNameToString(decl.name);
6538-
forEach(declarations, declaration => error(getNameOfDeclaration(declaration) || declaration, Diagnostics.Duplicate_declaration_0, name));
6539-
error(decl.name || decl, Diagnostics.Duplicate_declaration_0, name);
6537+
const name = !(type.flags & TypeFlags.UniqueESSymbol) && unescapeLeadingUnderscores(memberName) || declarationNameToString(decl.name);
6538+
forEach(declarations, declaration => error(getNameOfDeclaration(declaration) || declaration, Diagnostics.Property_0_was_also_declared_here, name));
6539+
error(decl.name || decl, Diagnostics.Duplicate_property_0, name);
65406540
lateSymbol = createSymbol(SymbolFlags.None, memberName, CheckFlags.Late);
65416541
}
65426542
lateSymbol.nameType = type;
@@ -9824,7 +9824,7 @@ namespace ts {
98249824
if (accessNode) {
98259825
const indexNode = getIndexNodeForAccessExpression(accessNode);
98269826
if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
9827-
error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (<LiteralType>indexType).value, typeToString(objectType));
9827+
error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, "" + (<StringLiteralType | NumberLiteralType>indexType).value, typeToString(objectType));
98289828
}
98299829
else if (indexType.flags & (TypeFlags.String | TypeFlags.Number)) {
98309830
error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType));
@@ -11769,11 +11769,11 @@ namespace ts {
1176911769
if (s & TypeFlags.StringLike && t & TypeFlags.String) return true;
1177011770
if (s & TypeFlags.StringLiteral && s & TypeFlags.EnumLiteral &&
1177111771
t & TypeFlags.StringLiteral && !(t & TypeFlags.EnumLiteral) &&
11772-
(<LiteralType>source).value === (<LiteralType>target).value) return true;
11772+
(<StringLiteralType>source).value === (<StringLiteralType>target).value) return true;
1177311773
if (s & TypeFlags.NumberLike && t & TypeFlags.Number) return true;
1177411774
if (s & TypeFlags.NumberLiteral && s & TypeFlags.EnumLiteral &&
1177511775
t & TypeFlags.NumberLiteral && !(t & TypeFlags.EnumLiteral) &&
11776-
(<LiteralType>source).value === (<LiteralType>target).value) return true;
11776+
(<NumberLiteralType>source).value === (<NumberLiteralType>target).value) return true;
1177711777
if (s & TypeFlags.BigIntLike && t & TypeFlags.BigInt) return true;
1177811778
if (s & TypeFlags.BooleanLike && t & TypeFlags.Boolean) return true;
1177911779
if (s & TypeFlags.ESSymbolLike && t & TypeFlags.ESSymbol) return true;
@@ -13697,8 +13697,8 @@ namespace ts {
1369713697
// no flags for all other types (including non-falsy literal types).
1369813698
function getFalsyFlags(type: Type): TypeFlags {
1369913699
return type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((<UnionType>type).types) :
13700-
type.flags & TypeFlags.StringLiteral ? (<LiteralType>type).value === "" ? TypeFlags.StringLiteral : 0 :
13701-
type.flags & TypeFlags.NumberLiteral ? (<LiteralType>type).value === 0 ? TypeFlags.NumberLiteral : 0 :
13700+
type.flags & TypeFlags.StringLiteral ? (<StringLiteralType>type).value === "" ? TypeFlags.StringLiteral : 0 :
13701+
type.flags & TypeFlags.NumberLiteral ? (<NumberLiteralType>type).value === 0 ? TypeFlags.NumberLiteral : 0 :
1370213702
type.flags & TypeFlags.BigIntLiteral ? isZeroBigInt(<BigIntLiteralType>type) ? TypeFlags.BigIntLiteral : 0 :
1370313703
type.flags & TypeFlags.BooleanLiteral ? (type === falseType || type === regularFalseType) ? TypeFlags.BooleanLiteral : 0 :
1370413704
type.flags & TypeFlags.PossiblyFalsy;
@@ -13721,8 +13721,8 @@ namespace ts {
1372113721
type === regularFalseType ||
1372213722
type === falseType ||
1372313723
type.flags & (TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null) ||
13724-
type.flags & TypeFlags.StringLiteral && (<LiteralType>type).value === "" ||
13725-
type.flags & TypeFlags.NumberLiteral && (<LiteralType>type).value === 0 ||
13724+
type.flags & TypeFlags.StringLiteral && (<StringLiteralType>type).value === "" ||
13725+
type.flags & TypeFlags.NumberLiteral && (<NumberLiteralType>type).value === 0 ||
1372613726
type.flags & TypeFlags.BigIntLiteral && isZeroBigInt(<BigIntLiteralType>type) ? type :
1372713727
neverType;
1372813728
}
@@ -15110,7 +15110,7 @@ namespace ts {
1511015110
return strictNullChecks ? TypeFacts.StringStrictFacts : TypeFacts.StringFacts;
1511115111
}
1511215112
if (flags & TypeFlags.StringLiteral) {
15113-
const isEmpty = (<LiteralType>type).value === "";
15113+
const isEmpty = (<StringLiteralType>type).value === "";
1511415114
return strictNullChecks ?
1511515115
isEmpty ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts :
1511615116
isEmpty ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts;
@@ -15119,7 +15119,7 @@ namespace ts {
1511915119
return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts;
1512015120
}
1512115121
if (flags & TypeFlags.NumberLiteral) {
15122-
const isZero = (<LiteralType>type).value === 0;
15122+
const isZero = (<NumberLiteralType>type).value === 0;
1512315123
return strictNullChecks ?
1512415124
isZero ? TypeFacts.ZeroNumberStrictFacts : TypeFacts.NonZeroNumberStrictFacts :
1512515125
isZero ? TypeFacts.ZeroNumberFacts : TypeFacts.NonZeroNumberFacts;

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@
24332433
"category": "Error",
24342434
"code": 2717
24352435
},
2436-
"Duplicate declaration '{0}'.": {
2436+
"Duplicate property '{0}'.": {
24372437
"category": "Error",
24382438
"code": 2718
24392439
},
@@ -2493,6 +2493,10 @@
24932493
"category": "Error",
24942494
"code": 2732
24952495
},
2496+
"Property '{0}' was also declared here.": {
2497+
"category": "Error",
2498+
"code": 2733
2499+
},
24962500
"It is highly likely that you are missing a semicolon.": {
24972501
"category": "Error",
24982502
"code": 2734

src/lib/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ The files within this directory are used to generate `lib.d.ts` and `lib.es6.d.t
44

55
## Generated files
66

7-
Any files ending in `.generated.d.ts` aren't mean to be edited by hand.
7+
Any files ending in `.generated.d.ts` aren't meant to be edited by hand.
88
If you need to make changes to such files, make a change to the input files for [**our library generator**](https://github.com/Microsoft/TSJS-lib-generator).

0 commit comments

Comments
 (0)