diff --git a/.changeset/config.json b/.changeset/config.json index 8dedd1f0d..1b20a6091 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,6 +1,6 @@ { "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", - "changelog": "@changesets/cli/changelog", + "changelog": ["@changesets/changelog-github", { "repo": "microsoft/TypeScript-Website" }], "commit": false, "fixed": [], "linked": [], diff --git a/package.json b/package.json index 96de8cb45..a12eae8c6 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "pnpm": ">=9" }, "devDependencies": { + "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.5", "@oss-docs/sync": "^1.1.4", "@types/express": "^4.17.6", diff --git a/packages/ata/CHANGELOG.md b/packages/ata/CHANGELOG.md index 62857f59e..012638547 100644 --- a/packages/ata/CHANGELOG.md +++ b/packages/ata/CHANGELOG.md @@ -1,5 +1,15 @@ # @typescript/ata +## 0.9.6 + +### Patch Changes + +- [#2977](https://github.com/microsoft/TypeScript-Website/pull/2977) [`7691811`](https://github.com/microsoft/TypeScript-Website/commit/7691811c180e3b352cf4e888387d1edfc10f5252) Thanks [@curran](https://github.com/curran)! - Widen typescript peer dependency range + +- [#3000](https://github.com/microsoft/TypeScript-Website/pull/3000) [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a) Thanks [@antfu](https://github.com/antfu)! - Handle `.d.cts` and `.d.mts` files + +- [#3002](https://github.com/microsoft/TypeScript-Website/pull/3002) [`fd776c0`](https://github.com/microsoft/TypeScript-Website/commit/fd776c05bb8fa9c897d18fa237af39ae8da03a7c) Thanks [@antfu](https://github.com/antfu)! - Fix return type of `setupTypeAcquisition` + ## 0.9.5 ### Patch Changes diff --git a/packages/ata/package.json b/packages/ata/package.json index ba6d3cafc..29092cee3 100644 --- a/packages/ata/package.json +++ b/packages/ata/package.json @@ -1,6 +1,6 @@ { "name": "@typescript/ata", - "version": "0.9.5", + "version": "0.9.6", "license": "MIT", "homepage": "https://github.com/microsoft/TypeScript-Website", "repository": { @@ -27,6 +27,6 @@ "jest": "^29.5.0" }, "peerDependencies": { - "typescript": "^4.4.4" + "typescript": ">=4.4.4" } } diff --git a/packages/ata/src/index.ts b/packages/ata/src/index.ts index 0f0070501..f52d3dcb0 100644 --- a/packages/ata/src/index.ts +++ b/packages/ata/src/index.ts @@ -71,7 +71,7 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => { const treesOnly = trees.filter(t => !("error" in t)) as NPMTreeMeta[] // These are the modules which we can grab directly - const hasDTS = treesOnly.filter(t => t.files.find(f => f.name.endsWith(".d.ts"))) + const hasDTS = treesOnly.filter(t => t.files.find(f => isDtsFile(f.name))) const dtsFilesFromNPM = hasDTS.map(t => treeToDTSFiles(t, `/node_modules/${t.moduleName}`)) // These are ones we need to look on DT for (which may not be there, who knows) @@ -142,7 +142,7 @@ function treeToDTSFiles(tree: NPMTreeMeta, vfsPrefix: string) { const dtsRefs: ATADownload[] = [] for (const file of tree.files) { - if (file.name.endsWith(".d.ts")) { + if (isDtsFile(file.name)) { dtsRefs.push({ moduleName: tree.moduleName, moduleVersion: tree.version, @@ -170,7 +170,7 @@ export const getReferencesForModule = (ts: typeof import("typescript"), code: st const references = meta.referencedFiles .concat(meta.importedFiles) .concat(meta.libReferenceDirectives) - .filter(f => !f.fileName.endsWith(".d.ts")) + .filter(f => !isDtsFile(f.fileName)) .filter(d => !libMap.has(d.fileName)) return references.map(r => { @@ -268,3 +268,7 @@ function getDTName(s: string) { } return s } + +function isDtsFile(file: string) { + return /\.d\.([^\.]+\.)?[cm]?ts$/i.test(file) +} diff --git a/packages/ata/src/userFacingTypes.d.ts b/packages/ata/src/userFacingTypes.d.ts index 8eec41430..4580d7a27 100644 --- a/packages/ata/src/userFacingTypes.d.ts +++ b/packages/ata/src/userFacingTypes.d.ts @@ -33,7 +33,7 @@ type ModuleMeta = { state: "loading" } * basically exported for tests and should be considered * implementation details by consumers. */ -export const setupTypeAcquisition: (config: ATABootstrapConfig) => (initialSourceFile: string) => void +export const setupTypeAcquisition: (config: ATABootstrapConfig) => (initialSourceFile: string) => Promise interface Logger { log: (...args: any[]) => void diff --git a/packages/documentation/copy/en/get-started/TS for Functional Programmers.md b/packages/documentation/copy/en/get-started/TS for Functional Programmers.md index 770e04cb4..9cf3038a5 100644 --- a/packages/documentation/copy/en/get-started/TS for Functional Programmers.md +++ b/packages/documentation/copy/en/get-started/TS for Functional Programmers.md @@ -76,8 +76,8 @@ TypeScript has corresponding primitive types for the built-in types: | -------------- | ------------------------------------------------------------------------------- | | `unknown` | the top type. | | `never` | the bottom type. | -| object literal | eg `{ property: Type }` | -| `void` | for functions with no documented return value | +| object literal | e.g. `{ property: Type }` | +| `void` | for functions with no documented return value | | `T[]` | mutable arrays, also written `Array` | | `[T, T]` | tuples, which are fixed-length but mutable | | `(t: T) => U` | functions | diff --git a/packages/documentation/copy/en/handbook-v2/Classes.md b/packages/documentation/copy/en/handbook-v2/Classes.md index 63227e728..03780e15c 100644 --- a/packages/documentation/copy/en/handbook-v2/Classes.md +++ b/packages/documentation/copy/en/handbook-v2/Classes.md @@ -150,11 +150,14 @@ class Point { ```ts twoslash class Point { - // Overloads - constructor(x: number, y: string); - constructor(s: string); - constructor(xs: any, y?: any) { - // TBD + x: number = 0; + y: number = 0; + + // Constructor overloads + constructor(x: number, y: number); + constructor(xy: string); + constructor(x: string | number, y: number = 0) { + // Code logic here } } ``` @@ -250,7 +253,6 @@ TypeScript has some special inference rules for accessors: - If `get` exists but no `set`, the property is automatically `readonly` - If the type of the setter parameter is not specified, it is inferred from the return type of the getter -- Getters and setters must have the same [Member Visibility](#member-visibility) Since [TypeScript 4.3](https://devblogs.microsoft.com/typescript/announcing-typescript-4-3/), it is possible to have accessors with different types for getting and setting. diff --git a/packages/documentation/copy/en/handbook-v2/Everyday Types.md b/packages/documentation/copy/en/handbook-v2/Everyday Types.md index 358adbf70..a132c026d 100644 --- a/packages/documentation/copy/en/handbook-v2/Everyday Types.md +++ b/packages/documentation/copy/en/handbook-v2/Everyday Types.md @@ -469,6 +469,7 @@ You'll learn more about these concepts in later chapters, so don't worry if you - Type aliases may not participate [in declaration merging, but interfaces can](/play?#code/PTAEEEDtQS0gXApgJwGYEMDGjSfdAIx2UQFoB7AB0UkQBMAoEUfO0Wgd1ADd0AbAK6IAzizp16ALgYM4SNFhwBZdAFtV-UAG8GoPaADmNAcMmhh8ZHAMMAvjLkoM2UCvWad+0ARL0A-GYWVpA29gyY5JAWLJAwGnxmbvGgALzauvpGkCZmAEQAjABMAMwALLkANBl6zABi6DB8okR4Jjg+iPSgABboovDk3jjo5pbW1d6+dGb5djLwAJ7UoABKiJTwjThpnpnGpqPBoTLMAJrkArj4kOTwYmycPOhW6AR8IrDQ8N04wmo4HHQCwYi2Waw2W1S6S8HX8gTGITsQA). - Interfaces may only be used to [declare the shapes of objects, not rename primitives](/play?#code/PTAEAkFMCdIcgM6gC4HcD2pIA8CGBbABwBtIl0AzUAKBFAFcEBLAOwHMUBPQs0XFgCahWyGBVwBjMrTDJMAshOhMARpD4tQ6FQCtIE5DWoixk9QEEWAeV37kARlABvaqDegAbrmL1IALlAEZGV2agBfampkbgtrWwMAJlAAXmdXdy8ff0Dg1jZwyLoAVWZ2Lh5QVHUJflAlSFxROsY5fFAWAmk6CnRoLGwmILzQQmV8JmQmDzI-SOiKgGV+CaYAL0gBBdyy1KCQ-Pn1AFFplgA5enw1PtSWS+vCsAAVAAtB4QQWOEMKBuYVUiVCYvYQsUTQcRSBDGMGmKSgAAa-VEgiQe2GLgKQA). - Interface names will [_always_ appear in their original form](/play?#code/PTAEGEHsFsAcEsA2BTATqNrLusgzngIYDm+oA7koqIYuYQJ56gCueyoAUCKAC4AWHAHaFcoSADMaQ0PCG80EwgGNkALk6c5C1EtWgAsqOi1QAb06groEbjWg8vVHOKcAvpokshy3vEgyyMr8kEbQJogAFND2YREAlOaW1soBeJAoAHSIkMTRmbbI8e6aPMiZxJmgACqCGKhY6ABGyDnkFFQ0dIzMbBwCwqIccabcYLyQoKjIEmh8kwN8DLAc5PzwwbLMyAAeK77IACYaQSEjUWY2Q-YAjABMAMwALA+gbsVjNXW8yxySoAADaAA0CCaZbPh1XYqXgOIY0ZgmcK0AA0nyaLFhhGY8F4AHJmEJILCWsgZId4NNfIgGFdcIcUTVfgBlZTOWC8T7kAJ42G4eT+GS42QyRaYbCgXAEEguTzeXyCjDBSAAQSE8Ai0Xsl0K9kcziExDeiQs1lAqSE6SyOTy0AKQ2KHk4p1V6s1OuuoHuzwArMagA) in error messages, but _only_ when they are used by name. +- Using interfaces with `extends` [can often be more performant for the compiler](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-interfaces-over-intersections) than type aliases with intersections For the most part, you can choose based on personal preference, and TypeScript will tell you if it needs something to be the other kind of declaration. If you would like a heuristic, use `interface` until you need to use features from `type`. diff --git a/packages/documentation/copy/en/handbook-v2/Object Types.md b/packages/documentation/copy/en/handbook-v2/Object Types.md index a0867b0ef..b266079ea 100644 --- a/packages/documentation/copy/en/handbook-v2/Object Types.md +++ b/packages/documentation/copy/en/handbook-v2/Object Types.md @@ -274,8 +274,8 @@ This index signature states that when a `StringArray` is indexed with a `number` Only some types are allowed for index signature properties: `string`, `number`, `symbol`, template string patterns, and union types consisting only of these.
- It is possible to support both types of indexers... -

It is possible to support both types of indexers, but the type returned from a numeric indexer must be a subtype of the type returned from the string indexer. This is because when indexing with a number, JavaScript will actually convert that to a string before indexing into an object. That means that indexing with 100 (a number) is the same thing as indexing with "100" (a string), so the two need to be consistent.

+ It is possible to support multiple types of indexers... +

It is possible to support multiple types of indexers. Note that when using both `number` and `string` indexers, the type returned from a numeric indexer must be a subtype of the type returned from the string indexer. This is because when indexing with a number, JavaScript will actually convert that to a string before indexing into an object. That means that indexing with 100 (a number) is the same thing as indexing with "100" (a string), so the two need to be consistent.

```ts twoslash // @errors: 2413 diff --git a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Generics.md b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Generics.md index 62564397a..b5884e825 100644 --- a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Generics.md +++ b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Generics.md @@ -152,7 +152,7 @@ let myIdentity: (arg: Type) => Type = identity; We could also have used a different name for the generic type parameter in the type, so long as the number of type variables and how the type variables are used line up. ```ts twoslash -function identity(arg: Input): Input { +function identity(arg: Type): Type { return arg; } diff --git a/packages/documentation/copy/en/javascript/JSDoc Reference.md b/packages/documentation/copy/en/javascript/JSDoc Reference.md index b6feaa9be..76bdfc182 100644 --- a/packages/documentation/copy/en/javascript/JSDoc Reference.md +++ b/packages/documentation/copy/en/javascript/JSDoc Reference.md @@ -827,6 +827,7 @@ The following tags have open issues to support them: - `@memberof` ([issue #7237](https://github.com/Microsoft/TypeScript/issues/7237)) - `@yields` ([issue #23857](https://github.com/Microsoft/TypeScript/issues/23857)) +- `@member` ([issue #56674](https://github.com/microsoft/TypeScript/issues/56674)) ### Legacy type synonyms @@ -852,4 +853,4 @@ So the compiler treats these types as synonyms based on usage in old JSDoc: The last four aliases are turned off when `noImplicitAny: true`: - `object` and `Object` are built-in types, although `Object` is rarely used. -- `array` and `promise` are not built-in, but might be declared somewhere in your program. \ No newline at end of file +- `array` and `promise` are not built-in, but might be declared somewhere in your program. diff --git a/packages/documentation/copy/en/modules-reference/Reference.md b/packages/documentation/copy/en/modules-reference/Reference.md index e8d349ba9..2ced1b6b3 100644 --- a/packages/documentation/copy/en/modules-reference/Reference.md +++ b/packages/documentation/copy/en/modules-reference/Reference.md @@ -231,10 +231,12 @@ The detected module format of input `.ts`/`.tsx`/`.mts`/`.cts` files determines The emit format of each file is determined by the [detected module format](#module-format-detection) of each file. ESM emit is similar to [`--module esnext`](#es2015-es2020-es2022-esnext), but has a special transformation for `import x = require("...")`, which is not allowed in `--module esnext`: ```ts +// @Filename: main.ts import x = require("mod"); ``` ```js +// @Filename: main.js import { createRequire as _createRequire } from "module"; const __require = _createRequire(import.meta.url); const x = __require("mod"); @@ -243,11 +245,13 @@ const x = __require("mod"); CommonJS emit is similar to [`--module commonjs`](#commonjs), but dynamic `import()` calls are not transformed. Emit here is shown with `esModuleInterop` enabled: ```ts +// @Filename: main.ts import fs from "fs"; // transformed const dynamic = import("mod"); // not transformed ``` ```js +// @Filename: main.js "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; @@ -322,6 +326,7 @@ export default "default export"; #### Examples ```ts +// @Filename: main.ts import x, { y, z } from "mod"; import * as mod from "mod"; const dynamic = import("mod"); @@ -332,6 +337,7 @@ export default "default export"; ``` ```js +// @Filename: main.js import x, { y, z } from "mod"; import * as mod from "mod"; const dynamic = import("mod"); @@ -355,6 +361,7 @@ export default "default export"; > Output is shown with `esModuleInterop: false`. ```ts +// @Filename: main.ts import x, { y, z } from "mod"; import * as mod from "mod"; const dynamic = import("mod"); @@ -365,6 +372,7 @@ export default "default export"; ``` ```js +// @Filename: main.js "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.e1 = void 0; @@ -378,6 +386,7 @@ exports.default = "default export"; ``` ```ts +// @Filename: main.ts import mod = require("mod"); console.log(mod); @@ -388,6 +397,7 @@ export = { ``` ```js +// @Filename: main.js "use strict"; const mod = require("mod"); console.log(mod); @@ -407,6 +417,7 @@ module.exports = { #### Examples ```ts +// @Filename: main.ts import x, { y, z } from "mod"; import * as mod from "mod"; const dynamic = import("mod"); @@ -417,6 +428,7 @@ export default "default export"; ``` ```js +// @Filename: main.js System.register(["mod"], function (exports_1, context_1) { "use strict"; var mod_1, mod, dynamic, e1; @@ -450,6 +462,7 @@ System.register(["mod"], function (exports_1, context_1) { #### Examples ```ts +// @Filename: main.ts import x, { y, z } from "mod"; import * as mod from "mod"; const dynamic = import("mod"); @@ -460,6 +473,7 @@ export default "default export"; ``` ```js +// @Filename: main.js define(["require", "exports", "mod", "mod"], function (require, exports, mod_1, mod) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -484,6 +498,7 @@ define(["require", "exports", "mod", "mod"], function (require, exports, mod_1, #### Examples ```ts +// @Filename: main.ts import x, { y, z } from "mod"; import * as mod from "mod"; const dynamic = import("mod"); @@ -494,6 +509,7 @@ export default "default export"; ``` ```js +// @Filename: main.js (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); @@ -985,7 +1001,7 @@ import foo = require("pkg/dist/foo"); // ✅ require, no extension needed #### package.json `"imports"` and self-name imports -When `moduleResolution` is set to `node16`, `nodenext`, or `bundler`, and `resolvePackageJsonImports` is not disabled, TypeScript will attempt to resolve import paths beginning with `#` through the the `"imports"` field of the nearest ancestor package.json of the importing file. Similarly, when [package.json `"exports"` lookups](#packagejson-exports) are enabled, TypeScript will attempt to resolve import paths beginning with the current package name—that is, the value in the `"name"` field of the nearest ancestor package.json of the importing file—through the `"exports"` field of that package.json. Both of these features allow files in a package to import other files in the same package, replacing a relative import path. +When `moduleResolution` is set to `node16`, `nodenext`, or `bundler`, and `resolvePackageJsonImports` is not disabled, TypeScript will attempt to resolve import paths beginning with `#` through the `"imports"` field of the nearest ancestor package.json of the importing file. Similarly, when [package.json `"exports"` lookups](#packagejson-exports) are enabled, TypeScript will attempt to resolve import paths beginning with the current package name—that is, the value in the `"name"` field of the nearest ancestor package.json of the importing file—through the `"exports"` field of that package.json. Both of these features allow files in a package to import other files in the same package, replacing a relative import path. TypeScript follows Node.js’s resolution algorithm for [`"imports"`](https://nodejs.org/api/packages.html#subpath-imports) and [self references](https://nodejs.org/api/packages.html#self-referencing-a-package-using-its-name) exactly up until a file path is resolved. At that point, TypeScript’s resolution algorithm forks based on whether the package.json containing the `"imports"` or `"exports"` being resolved belongs to a `node_modules` dependency or the local project being compiled (i.e., its directory contains the tsconfig.json file for the project that contains the importing file): diff --git a/packages/documentation/copy/en/reference/Utility Types.md b/packages/documentation/copy/en/reference/Utility Types.md index b7b98c4de..cdd36db38 100644 --- a/packages/documentation/copy/en/reference/Utility Types.md +++ b/packages/documentation/copy/en/reference/Utility Types.md @@ -140,13 +140,13 @@ Constructs an object type whose property keys are `Keys` and whose property valu ##### Example ```ts twoslash +type CatName = "miffy" | "boris" | "mordred"; + interface CatInfo { age: number; breed: string; } -type CatName = "miffy" | "boris" | "mordred"; - const cats: Record = { miffy: { age: 10, breed: "Persian" }, boris: { age: 5, breed: "Maine Coon" }, diff --git a/packages/documentation/copy/en/release-notes/TypeScript 2.8.md b/packages/documentation/copy/en/release-notes/TypeScript 2.8.md index 3c2721eb3..95800775e 100644 --- a/packages/documentation/copy/en/release-notes/TypeScript 2.8.md +++ b/packages/documentation/copy/en/release-notes/TypeScript 2.8.md @@ -328,7 +328,7 @@ type T7 = T4; // "a" | "b" ## Better handling for namespace patterns in `.js` files TypeScript 2.8 adds support for understanding more namespace patterns in `.js` files. -Empty object literals declarations on top level, just like functions and classes, are now recognized as as namespace declarations in JavaScript. +Empty object literals declarations on top level, just like functions and classes, are now recognized as namespace declarations in JavaScript. ```js var ns = {}; // recognized as a declaration for a namespace `ns` diff --git a/packages/documentation/copy/en/release-notes/TypeScript 4.0.md b/packages/documentation/copy/en/release-notes/TypeScript 4.0.md index 9edb7c08a..d98997e89 100644 --- a/packages/documentation/copy/en/release-notes/TypeScript 4.0.md +++ b/packages/documentation/copy/en/release-notes/TypeScript 4.0.md @@ -417,7 +417,7 @@ if (!obj.prop) { } ``` -[Try running the following example](https://www.typescriptlang.org/play?ts=Nightly#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) to see how that differs from _always_ performing the assignment. +[Try running the following example](https://www.typescriptlang.org/play?ts=next#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) to see how that differs from _always_ performing the assignment. ```ts twoslash const obj = { diff --git a/packages/documentation/copy/en/release-notes/TypeScript 4.9.md b/packages/documentation/copy/en/release-notes/TypeScript 4.9.md index 5033ae8a9..cdb3e351f 100644 --- a/packages/documentation/copy/en/release-notes/TypeScript 4.9.md +++ b/packages/documentation/copy/en/release-notes/TypeScript 4.9.md @@ -20,10 +20,7 @@ const palette = { // ^^^^ sacrebleu - we've made a typo! }; -// We want to be able to use array methods on 'red'... -const redComponent = palette.red.at(0); - -// or string methods on 'green'... +// We want to be able to use string methods on 'green'... const greenNormalized = palette.green.toUpperCase(); ``` @@ -42,8 +39,9 @@ const palette: Record = { // ~~~~ The typo is now correctly detected }; -// But we now have an undesirable error here - 'palette.red' "could" be a string. -const redComponent = palette.red.at(0); +// But we now have an undesirable error here - 'palette.green' "could" be of type RGB and +// property 'toUpperCase' does not exist on type 'string | RGB'. +const greenNormalized = palette.green.toUpperCase(); ``` The new `satisfies` operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression. @@ -61,8 +59,7 @@ const palette = { // ~~~~ The typo is now caught! } satisfies Record; -// Both of these methods are still accessible! -const redComponent = palette.red.at(0); +// toUpperCase() method is still accessible! const greenNormalized = palette.green.toUpperCase(); ``` diff --git a/packages/documentation/copy/en/release-notes/TypeScript 5.3.md b/packages/documentation/copy/en/release-notes/TypeScript 5.3.md index 163062460..7e93acc46 100644 --- a/packages/documentation/copy/en/release-notes/TypeScript 5.3.md +++ b/packages/documentation/copy/en/release-notes/TypeScript 5.3.md @@ -384,7 +384,7 @@ For more information, [see this pull request](https://github.com/microsoft/TypeS TypeScript itself ships two library files: `tsserverlibrary.js` and `typescript.js`. There are certain APIs available only in `tsserverlibrary.js` (like the `ProjectService` API), which may be useful to some importers. -Still, the two are distinct bundles with have a lot of overlap, duplicating code in the package. +Still, the two are distinct bundles with a lot of overlap, duplicating code in the package. What's more, it can be challenging to consistently use one over the other due to auto-imports or muscle memory. Accidentally loading both modules is far too easy, and code may not work properly on a different instance of the API. Even if it does work, loading a second bundle increases resource usage. @@ -421,4 +421,4 @@ For more information, [see the DOM updates for TypeScript 5.3](https://github.co TypeScript 5.3 now detects when the declaration referenced by a `super.` property access is a class field and issues an error. This prevents errors that might occur at runtime. -[See more on this change here](https://github.com/microsoft/TypeScript/pull/54056). \ No newline at end of file +[See more on this change here](https://github.com/microsoft/TypeScript/pull/54056). diff --git a/packages/playground-examples/copy/en/TypeScript/Meta-Types/Discriminate Types.ts b/packages/playground-examples/copy/en/TypeScript/Meta-Types/Discriminate Types.ts index 140af9cd1..7f6a58d40 100644 --- a/packages/playground-examples/copy/en/TypeScript/Meta-Types/Discriminate Types.ts +++ b/packages/playground-examples/copy/en/TypeScript/Meta-Types/Discriminate Types.ts @@ -63,4 +63,4 @@ const handleResponse = (response: APIResponses) => { // parts of the union are checked. There is a good pattern // for this using the never type in the handbook: -// https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions +// https://www.typescriptlang.org/docs/handbook/2/narrowing.html#the-never-type diff --git a/packages/playground-handbook/copy/en/TypeScript Versions.md b/packages/playground-handbook/copy/en/TypeScript Versions.md index ba36f151a..a9c370db7 100644 --- a/packages/playground-handbook/copy/en/TypeScript Versions.md +++ b/packages/playground-handbook/copy/en/TypeScript Versions.md @@ -4,8 +4,8 @@ The TypeScript Playground supports TypeScript versions all the way back to `3.3. The ability to switch the version of TypeScript makes it easy to figure out potential regressions and to be able to let people test out new language features without having to upgrade their projects to (potentially) an unstable version of TypeScript. You can access the list of production TypeScript versions via a dropdown in the editor's toolbar inside the Playground. If there's a current beta or rc, that will show at the top. -The dropdown shows the highest patch version for a TypeScript release, but that is not every version available. You can refer to these two JSON files for the full list of [release versions](https://typescript.azureedge.net/indexes/releases.json) and [pre-release versions](https://typescript.azureedge.net/indexes/pre-releases.json). +The dropdown shows the highest patch version for a TypeScript release, but that is not every version available. You can refer to these two JSON files for the full list of [release versions](https://playgroundcdn.typescriptlang.org/indexes/releases.json) and [pre-release versions](https://playgroundcdn.typescriptlang.org/indexes/pre-releases.json). Setting a TypeScript version will append `?ts=[version]` to your URL and reload. For example, setting the TypeScript version to 4.3.5 will add `?ts=4.3.5` to the URL, which is an OK segue to the overview of the [URL's structure](/play#handbook-10). -There's one special case where `?ts=Nightly` will find the latest version of the TypeScript which was built for the Playground and use that. +There's one special case where `?ts=next` will find the latest version of the TypeScript which was built for the Playground and use that. diff --git a/packages/playground-handbook/copy/en/URL Structure.md b/packages/playground-handbook/copy/en/URL Structure.md index 86eff8dae..c06d3d5a8 100644 --- a/packages/playground-handbook/copy/en/URL Structure.md +++ b/packages/playground-handbook/copy/en/URL Structure.md @@ -22,13 +22,12 @@ Or to trigger some action in the Playground UI by default: Then the query string tend to be about changing the state of the Playground setup from the default: -- `?ts=3.9.2` - Sets the TypeScript version, the list of supported versions is in these [two](https://typescript.azureedge.net/indexes/pre-releases.json) [json](https://typescript.azureedge.net/indexes/releases.json) files. +- `?ts=3.9.2` - Sets the TypeScript version, the list of supported versions is in these [two](https://playgroundcdn.typescriptlang.org/indexes/pre-releases.json) [json](https://playgroundcdn.typescriptlang.org/indexes/releases.json) files. There are two special cases for the `ts` option: - - `ts=Nightly` where it will switch to most recently the nightly version. - -- `ts=dev` where it uses your [local developer's build of TypeScript](https://github.com/microsoft/TypeScript/blob/main/scripts/createPlaygroundBuild.js) + - `ts=next`: Use the most recent [nightly build](https://www.typescriptlang.org/docs/handbook/nightly-builds.html). + - `ts=dev`: Use your [local developer's build of TypeScript](https://github.com/microsoft/TypeScript/blob/main/scripts/createPlaygroundBuild.js) - `?flag=value` - Any compiler flag referenced in can be set from a query - `?filetype=js|ts|dts` - Tells the Playground to set the editor's language diff --git a/packages/playground/README.md b/packages/playground/README.md index 22fe6050b..e061b994e 100644 --- a/packages/playground/README.md +++ b/packages/playground/README.md @@ -33,12 +33,12 @@ Or to trigger some action by default: Then queries tend to be about changing the state of the Playground setup from the default: -- `?ts=3.9.2` - Sets the TypeScript version, the list of supported versions is in these [two](https://typescript.azureedge.net/indexes/pre-releases.json) [json](https://typescript.azureedge.net/indexes/releases.json) files. +- `?ts=3.9.2` - Sets the TypeScript version, the list of supported versions is in these [two](https://playgroundcdn.typescriptlang.org/indexes/pre-releases.json) [json](https://playgroundcdn.typescriptlang.org/indexes/releases.json) files. There are two special cases for the `ts` option: - - `ts=Nightly` where it will switch to most recently the nightly version. - - `ts=dev` where it uses your [local developer's build of TypeScript](https://github.com/microsoft/TypeScript/blob/main/scripts/createPlaygroundBuild.js) + - `ts=next`: Use the most recent [nightly build](https://www.typescriptlang.org/docs/handbook/nightly-builds.html). + - `ts=dev`: Use your [local developer's build of TypeScript](https://github.com/microsoft/TypeScript/blob/main/scripts/createPlaygroundBuild.js) - `?flag=value` - Any compiler flag referenced in can be set from a query - `?filetype=js|ts|dts` - Tells the Playground to set the editor's type diff --git a/packages/sandbox/CHANGELOG.md b/packages/sandbox/CHANGELOG.md index bd1eee7e8..b3f1fa631 100644 --- a/packages/sandbox/CHANGELOG.md +++ b/packages/sandbox/CHANGELOG.md @@ -1,5 +1,22 @@ # @typescript/sandbox +## 0.1.5 + +### Patch Changes + +- [#3000](https://github.com/microsoft/TypeScript-Website/pull/3000) [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a) Thanks [@antfu](https://github.com/antfu)! - Handle `.d.cts` and `.d.mts` files + +- Updated dependencies [[`0ea84b5`](https://github.com/microsoft/TypeScript-Website/commit/0ea84b59ae291aba677fe77ca059c4112e45fb9b), [`7691811`](https://github.com/microsoft/TypeScript-Website/commit/7691811c180e3b352cf4e888387d1edfc10f5252), [`0ea84b5`](https://github.com/microsoft/TypeScript-Website/commit/0ea84b59ae291aba677fe77ca059c4112e45fb9b), [`6168ef4`](https://github.com/microsoft/TypeScript-Website/commit/6168ef49a4d08c0b5658732d23625bbcc6049109), [`9f8dea2`](https://github.com/microsoft/TypeScript-Website/commit/9f8dea2c19a3b6028148090f5e8cba8eea086ec3), [`26f3e56`](https://github.com/microsoft/TypeScript-Website/commit/26f3e566aa8fff235a8f6927ef2c33b28be4fe89), [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a), [`fd776c0`](https://github.com/microsoft/TypeScript-Website/commit/fd776c05bb8fa9c897d18fa237af39ae8da03a7c)]: + - @typescript/vfs@1.5.3 + - @typescript/ata@0.9.6 + +## 0.1.4 + +### Patch Changes + +- Updated dependencies [642ea11] + - @typescript/vfs@1.5.2 + ## 0.1.3 ### Patch Changes diff --git a/packages/sandbox/README.md b/packages/sandbox/README.md index 0d05d048c..bbc1c425f 100644 --- a/packages/sandbox/README.md +++ b/packages/sandbox/README.md @@ -41,11 +41,11 @@ the same runtime loader patterns for importing into your web page. This package // For the monaco version you can use unpkg or the TypeScript web infra CDN // You can see the available releases for TypeScript here: - // https://typescript.azureedge.net/indexes/releases.json + // https://playgroundcdn.typescriptlang.org/indexes/releases.json // require.config({ paths: { - vs: "https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs", + vs: "https://playgroundcdn.typescriptlang.org/cdn/4.0.5/monaco/min/vs", // vs: 'https://unpkg.com/@typescript-deploys/monaco-editor@4.0.5/min/vs', sandbox: "https://www.typescriptlang.org/js/sandbox", }, diff --git a/packages/sandbox/package.json b/packages/sandbox/package.json index c497b87d9..487decc87 100644 --- a/packages/sandbox/package.json +++ b/packages/sandbox/package.json @@ -1,6 +1,6 @@ { "name": "@typescript/sandbox", - "version": "0.1.3", + "version": "0.1.5", "license": "MIT", "author": "TypeScript team", "homepage": "https://github.com/microsoft/TypeScript-Website", diff --git a/packages/sandbox/script/downloadReleases.js b/packages/sandbox/script/downloadReleases.js index e53d4c3dc..b473a7d09 100644 --- a/packages/sandbox/script/downloadReleases.js +++ b/packages/sandbox/script/downloadReleases.js @@ -8,13 +8,13 @@ const { join } = require("path") const { format } = require("prettier") const go = async () => { - const response = await fetch("https://typescript.azureedge.net/indexes/releases.json") + const response = await fetch("https://playgroundcdn.typescriptlang.org/indexes/releases.json") const releases = await response.json() const versions = releases.versions.reverse() // Look through the prereleases to see if the beta and RC are included in the pre-releases // and add those to the list of versions. - const preReleaseResponse = await fetch("https://typescript.azureedge.net/indexes/pre-releases.json") + const preReleaseResponse = await fetch("https://playgroundcdn.typescriptlang.org/indexes/pre-releases.json") const preReleases = await preReleaseResponse.json() const latestStable = versions[0] diff --git a/packages/sandbox/src/index.ts b/packages/sandbox/src/index.ts index fbb647ba8..b60c9ad51 100644 --- a/packages/sandbox/src/index.ts +++ b/packages/sandbox/src/index.ts @@ -318,12 +318,15 @@ export const createTypeScriptSandbox = ( return (firstJS && firstJS.text) || "" } + const isDtsFile = (name: string) => /\.d\.([^\.]+\.)?[cm]?ts$/i.test(name) + /** Gets the DTS for the JS/TS of compiling your editor's code */ const getDTSForCode = async () => { const result = await getEmitResult(/*emitOnlyDtsFiles*/ undefined, /*forceDtsEmit*/ true) - return result.outputFiles.find((o: any) => o.name.endsWith(".d.ts"))?.text || "" + return result.outputFiles.find((o: any) => isDtsFile(o.name))?.text || "" } + const getWorkerProcess = async (): Promise => { const worker = await getWorker() // @ts-ignore diff --git a/packages/ts-twoslasher/CHANGELOG.md b/packages/ts-twoslasher/CHANGELOG.md index 0bebb6cc3..d2542d548 100644 --- a/packages/ts-twoslasher/CHANGELOG.md +++ b/packages/ts-twoslasher/CHANGELOG.md @@ -1,5 +1,21 @@ # @typescript/twoslash +## 3.2.7 + +### Patch Changes + +- [#3000](https://github.com/microsoft/TypeScript-Website/pull/3000) [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a) Thanks [@antfu](https://github.com/antfu)! - Handle `.d.cts` and `.d.mts` files + +- Updated dependencies [[`0ea84b5`](https://github.com/microsoft/TypeScript-Website/commit/0ea84b59ae291aba677fe77ca059c4112e45fb9b), [`0ea84b5`](https://github.com/microsoft/TypeScript-Website/commit/0ea84b59ae291aba677fe77ca059c4112e45fb9b), [`6168ef4`](https://github.com/microsoft/TypeScript-Website/commit/6168ef49a4d08c0b5658732d23625bbcc6049109), [`9f8dea2`](https://github.com/microsoft/TypeScript-Website/commit/9f8dea2c19a3b6028148090f5e8cba8eea086ec3), [`26f3e56`](https://github.com/microsoft/TypeScript-Website/commit/26f3e566aa8fff235a8f6927ef2c33b28be4fe89), [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a)]: + - @typescript/vfs@1.5.3 + +## 3.2.6 + +### Patch Changes + +- Updated dependencies [642ea11] + - @typescript/vfs@1.5.2 + ## 3.2.5 ### Patch Changes diff --git a/packages/ts-twoslasher/package.json b/packages/ts-twoslasher/package.json index 4f9229a3b..1f4bbda45 100755 --- a/packages/ts-twoslasher/package.json +++ b/packages/ts-twoslasher/package.json @@ -1,6 +1,6 @@ { "name": "@typescript/twoslash", - "version": "3.2.5", + "version": "3.2.7", "license": "MIT", "author": "TypeScript team", "homepage": "https://github.com/microsoft/TypeScript-Website", diff --git a/packages/ts-twoslasher/src/index.ts b/packages/ts-twoslasher/src/index.ts index c377237de..0864bf3de 100755 --- a/packages/ts-twoslasher/src/index.ts +++ b/packages/ts-twoslasher/src/index.ts @@ -742,7 +742,7 @@ export function twoslasher(code: string, extension: string, options: TwoSlashOpt // Get the file which created the file we want to show: const emitFilename = handbookOptions.showEmittedFile || defaultFileName const emitSourceFilename = - fsRoot + emitFilename.replace(".jsx", "").replace(".js", "").replace(".d.ts", "").replace(".map", "") + fsRoot + emitFilename.replace(".jsx", "").replace(".js", "").replace(/\.d\.([^\.]+\.)?[cm]?ts$/i, "").replace(".map", "") let emitSource = filenames.find(f => f === emitSourceFilename + ".ts" || f === emitSourceFilename + ".tsx") diff --git a/packages/typescript-vfs/CHANGELOG.md b/packages/typescript-vfs/CHANGELOG.md index 71aeddf34..b23be4020 100644 --- a/packages/typescript-vfs/CHANGELOG.md +++ b/packages/typescript-vfs/CHANGELOG.md @@ -1,5 +1,27 @@ # @typescript/vfs +## 1.5.3 + +### Patch Changes + +- [#3038](https://github.com/microsoft/TypeScript-Website/pull/3038) [`0ea84b5`](https://github.com/microsoft/TypeScript-Website/commit/0ea84b59ae291aba677fe77ca059c4112e45fb9b) Thanks [@xiaoxiyao](https://github.com/xiaoxiyao)! - Fix the exception when file content is empty + +- [#3038](https://github.com/microsoft/TypeScript-Website/pull/3038) [`0ea84b5`](https://github.com/microsoft/TypeScript-Website/commit/0ea84b59ae291aba677fe77ca059c4112e45fb9b) Thanks [@xiaoxiyao](https://github.com/xiaoxiyao)! - Fix `moduleDetection` compiler option is not working + +- [#3015](https://github.com/microsoft/TypeScript-Website/pull/3015) [`6168ef4`](https://github.com/microsoft/TypeScript-Website/commit/6168ef49a4d08c0b5658732d23625bbcc6049109) Thanks [@antfu](https://github.com/antfu)! - support non-hoisted `node_module` structure + +- [#3072](https://github.com/microsoft/TypeScript-Website/pull/3072) [`9f8dea2`](https://github.com/microsoft/TypeScript-Website/commit/9f8dea2c19a3b6028148090f5e8cba8eea086ec3) Thanks [@KiranJKurian](https://github.com/KiranJKurian)! - Fix missing typescript peer dependency + +- [#3140](https://github.com/microsoft/TypeScript-Website/pull/3140) [`26f3e56`](https://github.com/microsoft/TypeScript-Website/commit/26f3e566aa8fff235a8f6927ef2c33b28be4fe89) Thanks [@jakebailey](https://github.com/jakebailey)! - Don't depend on DOM types in createDefaultMapFromCDN + +- [#3000](https://github.com/microsoft/TypeScript-Website/pull/3000) [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a) Thanks [@antfu](https://github.com/antfu)! - Handle `.d.cts` and `.d.mts` files + +## 1.5.2 + +### Patch Changes + +- 642ea11: Move playground CDN to new, stable URL + ## 1.5.1 ### Patch Changes diff --git a/packages/typescript-vfs/package.json b/packages/typescript-vfs/package.json index 7801e6e2b..36054f5fb 100755 --- a/packages/typescript-vfs/package.json +++ b/packages/typescript-vfs/package.json @@ -1,6 +1,6 @@ { "name": "@typescript/vfs", - "version": "1.5.1", + "version": "1.5.3", "license": "MIT", "author": "TypeScript team", "homepage": "https://github.com/microsoft/TypeScript-Website", @@ -51,9 +51,11 @@ "jest": "^29.5.0", "jest-environment-jsdom": "^29.5.0", "jest-watch-typeahead": "^2.2.2", - "lz-string": "^1.5.0", "ts-jest": "^29.0.5", "tslib": "^2.6.2", "typescript": "*" + }, + "peerDependencies": { + "typescript": "*" } } diff --git a/packages/typescript-vfs/src/index.ts b/packages/typescript-vfs/src/index.ts index 1239a909d..8040f29ce 100755 --- a/packages/typescript-vfs/src/index.ts +++ b/packages/typescript-vfs/src/index.ts @@ -6,13 +6,24 @@ type CompilerHost = import("typescript").CompilerHost type SourceFile = import("typescript").SourceFile type TS = typeof import("typescript") +type FetchLike = (url: string) => Promise<{ json(): Promise; text(): Promise }> + +interface LocalStorageLike { + getItem(key: string): string | null + setItem(key: string, value: string): void + removeItem(key: string): void +} + +declare var localStorage: LocalStorageLike | undefined; +declare var fetch: FetchLike | undefined; + let hasLocalStorage = false try { hasLocalStorage = typeof localStorage !== `undefined` } catch (error) { } const hasProcess = typeof process !== `undefined` -const shouldDebug = (hasLocalStorage && localStorage.getItem("DEBUG")) || (hasProcess && process.env.DEBUG) +const shouldDebug = (hasLocalStorage && localStorage!.getItem("DEBUG")) || (hasProcess && process.env.DEBUG) const debugLog = shouldDebug ? console.log : (_message?: any, ..._optionalParams: any[]) => "" export interface VirtualTypeScriptEnvironment { @@ -241,8 +252,10 @@ export const createDefaultMapFromNodeModules = ( return fs.readFileSync(path.join(lib, name), "utf8") } + const isDtsFile = (file: string) => /\.d\.([^\.]+\.)?[cm]?ts$/i.test(file) + const libFiles = fs.readdirSync(tsLibDirectory || path.dirname(require.resolve("typescript"))) - const knownLibFiles = libFiles.filter(f => f.startsWith("lib.") && f.endsWith(".d.ts")) + const knownLibFiles = libFiles.filter(f => f.startsWith("lib.") && isDtsFile(f)) const fsMap = new Map() knownLibFiles.forEach(lib => { @@ -292,6 +305,11 @@ export const addAllFilesFromFolder = (map: Map, workingDir: stri export const addFilesForTypesIntoFolder = (map: Map) => addAllFilesFromFolder(map, "node_modules/@types") +export interface LZString { + compressToUTF16(input: string): string + decompressFromUTF16(compressed: string): string +} + /** * Create a virtual FS Map with the lib files from a particular TypeScript * version based on the target, Always includes dom ATM. @@ -309,14 +327,14 @@ export const createDefaultMapFromCDN = ( version: string, cache: boolean, ts: TS, - lzstring?: typeof import("lz-string"), - fetcher?: typeof fetch, - storer?: typeof localStorage + lzstring?: LZString, + fetcher?: FetchLike, + storer?: LocalStorageLike ) => { - const fetchlike = fetcher || fetch + const fetchlike = fetcher || fetch! const fsMap = new Map() const files = knownLibFilesForCompilerOptions(options, ts) - const prefix = `https://typescript.azureedge.net/cdn/${version}/typescript/lib/` + const prefix = `https://playgroundcdn.typescriptlang.org/cdn/${version}/typescript/lib/` function zip(str: string) { return lzstring ? lzstring.compressToUTF16(str) : str @@ -340,7 +358,7 @@ export const createDefaultMapFromCDN = ( // A localstorage and lzzip aware version of the lib files function cached() { - const storelike = storer || localStorage + const storelike = storer || localStorage! const keys = Object.keys(storelike) keys.forEach(key => { @@ -440,7 +458,7 @@ export function createSystem(files: Map): System { getDirectories: () => [], getExecutingFilePath: () => notImplemented("getExecutingFilePath"), readDirectory: audit("readDirectory", directory => (directory === "/" ? Array.from(files.keys()) : [])), - readFile: audit("readFile", fileName => files.get(fileName) || files.get(libize(fileName))), + readFile: audit("readFile", fileName => files.get(fileName) ?? files.get(libize(fileName))), resolvePath: path => path, newLine: "\n", useCaseSensitiveFileNames: true, @@ -527,6 +545,7 @@ export function createFSBackedSystem( writeFile: (fileName, contents) => { files.set(fileName, contents) }, + realpath: nodeSys.realpath, } } @@ -555,14 +574,14 @@ export function createVirtualCompilerHost(sys: System, compilerOptions: Compiler // getDefaultLibLocation: () => '/', getDirectories: () => [], getNewLine: () => sys.newLine, - getSourceFile: fileName => { + getSourceFile: (fileName, languageVersionOrOptions) => { return ( sourceFiles.get(fileName) || save( ts.createSourceFile( fileName, sys.readFile(fileName)!, - compilerOptions.target || defaultCompilerOptions(ts).target!, + languageVersionOrOptions ?? compilerOptions.target ?? defaultCompilerOptions(ts).target!, false ) ) diff --git a/packages/typescript-vfs/test/index.test.ts b/packages/typescript-vfs/test/index.test.ts index e52627204..8e2022af5 100644 --- a/packages/typescript-vfs/test/index.test.ts +++ b/packages/typescript-vfs/test/index.test.ts @@ -214,3 +214,34 @@ it("grabs lib dts files from node_modules", async () => { const fsMap = createDefaultMapFromNodeModules({}) expect(fsMap.get("/lib.es2015.collection.d.ts")).toBeDefined() }) + +it("empty file content", async () => { + const options = { target: ts.ScriptTarget.ES2020 } + const fsMap = createDefaultMapFromNodeModules(options, ts) + fsMap.set("index.ts", "") + const system = createSystem(fsMap) + const host = createVirtualCompilerHost(system, options, ts) + ts.createProgram({ + rootNames: ["index.ts"], + options, + host: host.compilerHost, + }) +}) + +it("moduleDetection options", async () => { + const options: ts.CompilerOptions = { + module: ts.ModuleKind.AMD, + moduleDetection: ts.ModuleDetectionKind.Force, + } + const fsMap = createDefaultMapFromNodeModules(options, ts) + fsMap.set("index.ts", "let foo = 'foo'") + const system = createSystem(fsMap) + const host = createVirtualCompilerHost(system, options, ts) + const program = ts.createProgram({ + rootNames: ["index.ts"], + options, + host: host.compilerHost, + }) + program.emit() + expect(fsMap.get("index.js")).toEqual(`define(["require", "exports"], function (require, exports) {\n "use strict";\n Object.defineProperty(exports, "__esModule", { value: true });\n var foo = 'foo';\n});\n`) +}) diff --git a/packages/typescript-vfs/tsconfig.json b/packages/typescript-vfs/tsconfig.json index 5bbc757d4..3c13716e7 100644 --- a/packages/typescript-vfs/tsconfig.json +++ b/packages/typescript-vfs/tsconfig.json @@ -5,7 +5,7 @@ "compilerOptions": { "target": "ES2015", "module": "esnext", - "lib": ["dom", "esnext"], + "lib": ["esnext"], "importHelpers": true, "declaration": true, "sourceMap": true, diff --git a/packages/typescriptlang-org/src/pages/dev/bug-workbench.tsx b/packages/typescriptlang-org/src/pages/dev/bug-workbench.tsx index 5572de494..63e89ee0b 100755 --- a/packages/typescriptlang-org/src/pages/dev/bug-workbench.tsx +++ b/packages/typescriptlang-org/src/pages/dev/bug-workbench.tsx @@ -53,9 +53,9 @@ const Play: React.FC = (props) => { let tsVersionParam = params.get("ts") // handle the nightly lookup - if (!tsVersionParam || tsVersionParam && tsVersionParam === "Nightly" || tsVersionParam === "next") { - // Avoids the CDN to doubly skip caching - const nightlyLookup = await fetch("https://tswebinfra.blob.core.windows.net/indexes/next.json", { cache: "no-cache" }) + if (!tsVersionParam || tsVersionParam === "Nightly" || tsVersionParam === "next") { + // The CDN is configured to have a short TTL on the indexes directory. + const nightlyLookup = await fetch("https://playgroundcdn.typescriptlang.org/indexes/next.json", { cache: "no-cache" }) const nightlyJSON = await nightlyLookup.json() tsVersionParam = nightlyJSON.version } @@ -66,7 +66,7 @@ const Play: React.FC = (props) => { const re: any = global.require re.config({ paths: { - vs: `https://typescript.azureedge.net/cdn/${tsVersionParam}/monaco/dev/vs`, + vs: `https://playgroundcdn.typescriptlang.org/cdn/${tsVersionParam}/monaco/dev/vs`, "typescript-sandbox": sandboxRoot, "typescript-playground": playgroundRoot, "unpkg": "https://unpkg.com/", diff --git a/packages/typescriptlang-org/src/pages/dev/sandbox.tsx b/packages/typescriptlang-org/src/pages/dev/sandbox.tsx index 9b778f55f..624002529 100644 --- a/packages/typescriptlang-org/src/pages/dev/sandbox.tsx +++ b/packages/typescriptlang-org/src/pages/dev/sandbox.tsx @@ -26,7 +26,7 @@ const Index: React.FC = props => { re.config({ paths: { - vs: "https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs", + vs: "https://playgroundcdn.typescriptlang.org/cdn/4.0.5/monaco/min/vs", sandbox: withPrefix("/js/sandbox"), }, ignoreDuplicateModules: ["vs/editor/editor.main"], @@ -238,11 +238,11 @@ export default async function () { // For the monaco version you can use unpkg or the TypeSCript web infra CDN // You can see the available releases for TypeScript here: - // https://typescript.azureedge.net/indexes/releases.json + // https://playgroundcdn.typescriptlang.org/indexes/releases.json // require.config({ paths: { - vs: 'https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs', + vs: 'https://playgroundcdn.typescriptlang.org/cdn/4.0.5/monaco/min/vs', // vs: 'https://unpkg.com/@typescript-deploys/monaco-editor@4.0.5/min/vs', sandbox: 'https://www.typescriptlang.org/js/sandbox', }, diff --git a/packages/typescriptlang-org/src/pages/dev/twoslash.tsx b/packages/typescriptlang-org/src/pages/dev/twoslash.tsx index d188b924f..d9f15055c 100755 --- a/packages/typescriptlang-org/src/pages/dev/twoslash.tsx +++ b/packages/typescriptlang-org/src/pages/dev/twoslash.tsx @@ -40,7 +40,7 @@ const Index: React.FC = props => { re.config({ paths: { - vs: "https://typescript.azureedge.net/cdn/4.0.5/monaco/min/vs", + vs: "https://playgroundcdn.typescriptlang.org/cdn/4.0.5/monaco/min/vs", sandbox: sandboxRoot, }, ignoreDuplicateModules: ["vs/editor/editor.main"], diff --git a/packages/typescriptlang-org/src/templates/documentation.tsx b/packages/typescriptlang-org/src/templates/documentation.tsx index 49ff71463..619878a55 100644 --- a/packages/typescriptlang-org/src/templates/documentation.tsx +++ b/packages/typescriptlang-org/src/templates/documentation.tsx @@ -195,18 +195,33 @@ type MarkdownHeadingTreeNode = { function headerListToTree(sidebarHeaders: GatsbyTypes.Maybe>[]) { const tree: MarkdownHeadingTreeNode[] = [] - let currentParent: MarkdownHeadingTreeNode | undefined - sidebarHeaders.forEach(heading => { - if (!currentParent || heading!.depth === 2) { - currentParent = { value: heading!.value!, depth: heading!.depth!, children: [] } - tree.push(currentParent) + const stack: { node: MarkdownHeadingTreeNode; depth: number }[] = [] + + sidebarHeaders.forEach(header => { + const value = header?.value!; + const depth = header?.depth!; + const newNode: MarkdownHeadingTreeNode = { + value, + depth + } + + while (stack.length > 0 && stack[stack.length - 1].depth >= depth) { + stack.pop() + } + + if (stack.length === 0) { + tree.push(newNode) } else { - currentParent.children?.push({ - value: heading!.value!, - depth: heading!.depth!, - }) + const topNode = stack[stack.length - 1].node; + if (!topNode.children) { + topNode.children = []; + } + topNode.children.push(newNode); } + + stack.push({ node: newNode, depth }) }) + return tree } diff --git a/packages/typescriptlang-org/src/templates/pages/css/index.scss b/packages/typescriptlang-org/src/templates/pages/css/index.scss index 6a7785a03..78b063446 100644 --- a/packages/typescriptlang-org/src/templates/pages/css/index.scss +++ b/packages/typescriptlang-org/src/templates/pages/css/index.scss @@ -484,6 +484,7 @@ $headline-foreground-bg: white; overflow-x: auto; position: relative; background-color: #235a97; + border-radius: 0px 0px calc(8px - 2px) calc(8px - 2px); pre { margin: 0; @@ -557,7 +558,7 @@ $headline-foreground-bg: white; background: $ts-main-blue-color; background-position-y: bottom -180px; height: 260px; - border: 1px solid white; + outline: 1px solid white; color: white; &.handbook { background-image: url(/images/index/get-started-handbook-blue.svg); @@ -578,26 +579,28 @@ $headline-foreground-bg: white; background-color: #156fb4; } &:hover { - border-width: 2px; + outline-width: 2px; box-shadow: 0px 4px 20px -2px rgba(0, 0, 0, 0.25); - max-width: 246px; } } &.tall { background: #ffffff; - border: 1px solid #000000; + outline: 1px solid #000000; color: black; height: 342px; margin-bottom: 2px; &:hover { - border-color: $ts-main-blue-color; - border-width: 2px; + outline-color: $ts-main-blue-color; + outline-width: 2px; + color: $ts-main-blue-color; box-shadow: 0px 4px 20px -2px rgba(0, 0, 0, 0.25); - max-width: 246px; - height: 344px; margin-bottom: 0px; + + svg path { + stroke: $ts-main-blue-color; + } } &:active { background-color: #eeeeee; @@ -617,7 +620,6 @@ $headline-foreground-bg: white; } &:active { - margin-top: 1px; box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.25); } diff --git a/packages/typescriptlang-org/src/templates/pages/docs/index.tsx b/packages/typescriptlang-org/src/templates/pages/docs/index.tsx index 876937378..65fab11b9 100644 --- a/packages/typescriptlang-org/src/templates/pages/docs/index.tsx +++ b/packages/typescriptlang-org/src/templates/pages/docs/index.tsx @@ -73,7 +73,7 @@ const Index: React.FC = (props) => { } else { return
  • - { path.endsWith("png") ? + { path.endsWith(".png") || path.endsWith(".zip") ? {item.title} : {item.title} } diff --git a/packages/typescriptlang-org/src/templates/play.scss b/packages/typescriptlang-org/src/templates/play.scss index bfba590c7..4e0d1a519 100644 --- a/packages/typescriptlang-org/src/templates/play.scss +++ b/packages/typescriptlang-org/src/templates/play.scss @@ -59,16 +59,16 @@ } &.dropdown { - ul, .dropdown-dialog { + $sticky-widget-z-index: 4; display: none; position: absolute; top: 100%; left: 0; - z-index: 1; + z-index: $sticky-widget-z-index + 1; float: left; } } @@ -1241,4 +1241,4 @@ input.good { .monaco-list { background-color: var(--background-color); -} \ No newline at end of file +} diff --git a/packages/typescriptlang-org/src/templates/play.tsx b/packages/typescriptlang-org/src/templates/play.tsx index f373f8641..a771c49c6 100644 --- a/packages/typescriptlang-org/src/templates/play.tsx +++ b/packages/typescriptlang-org/src/templates/play.tsx @@ -79,9 +79,9 @@ const Play: React.FC = (props) => { let tsVersionParam = params.get("ts") // handle the nightly lookup - if (tsVersionParam && tsVersionParam === "Nightly" || tsVersionParam === "next") { - // Avoids the CDN to doubly skip caching - const nightlyLookup = await fetch("https://tswebinfra.blob.core.windows.net/indexes/next.json", { cache: "no-cache" }) + if (tsVersionParam === "Nightly" || tsVersionParam === "next") { + // The CDN is configured to have a short TTL on the indexes directory. + const nightlyLookup = await fetch("https://playgroundcdn.typescriptlang.org/indexes/next.json", { cache: "no-cache" }) const nightlyJSON = await nightlyLookup.json() tsVersionParam = nightlyJSON.version } @@ -99,7 +99,7 @@ const Play: React.FC = (props) => { const useLocalCompiler = tsVersion === "dev" const devIsh = ["pr", "dev"] const version = devIsh.find(d => tsVersion.includes(d)) ? "dev" : "min" - const urlForMonaco = useLocalCompiler ? "http://localhost:5615/dev/vs" : `https://typescript.azureedge.net/cdn/${tsVersion}/monaco/${version}/vs` + const urlForMonaco = useLocalCompiler ? "http://localhost:5615/dev/vs" : `https://playgroundcdn.typescriptlang.org/cdn/${tsVersion}/monaco/${version}/vs` // Make a quick HEAD call for the main monaco editor for this version of TS, if it // bails then give a useful error message and bail. diff --git a/packages/typescriptlang-org/src/templates/tsconfig.scss b/packages/typescriptlang-org/src/templates/tsconfig.scss index bf40d91ea..9225c7196 100644 --- a/packages/typescriptlang-org/src/templates/tsconfig.scss +++ b/packages/typescriptlang-org/src/templates/tsconfig.scss @@ -33,12 +33,12 @@ } } } - &.button.open { + &.button.closed { svg { transform: rotate(270deg); } } - &.button.closed { + &.button.open { a { text-decoration: none; color: var(--text-color); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6ba41c92b..d1741d0a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,6 +31,9 @@ importers: .: devDependencies: + '@changesets/changelog-github': + specifier: ^0.5.0 + version: 0.5.0 '@changesets/cli': specifier: ^2.27.5 version: 2.27.5 @@ -324,9 +327,6 @@ importers: jest-watch-typeahead: specifier: ^2.2.2 version: 2.2.2(jest@29.7.0(@types/node@18.19.33)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@18.19.33)(typescript@5.4.5))) - lz-string: - specifier: ^1.5.0 - version: 1.5.0 ts-jest: specifier: ^29.0.5 version: 29.1.3(@babel/core@7.24.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.24.5))(jest@29.7.0(@types/node@18.19.33)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@18.19.33)(typescript@5.4.5)))(typescript@5.4.5) @@ -1230,6 +1230,9 @@ packages: '@changesets/changelog-git@0.2.0': resolution: {integrity: sha512-bHOx97iFI4OClIT35Lok3sJAwM31VbUM++gnMBV16fdbtBhgYu4dxsphBF/0AZZsyAHMrnM0yFcj5gZM1py6uQ==} + '@changesets/changelog-github@0.5.0': + resolution: {integrity: sha512-zoeq2LJJVcPJcIotHRJEEA2qCqX0AQIeFE+L21L8sRLPVqDhSXY8ZWAt2sohtBpFZkBwu+LUwMSKRr2lMy3LJA==} + '@changesets/cli@2.27.5': resolution: {integrity: sha512-UVppOvzCjjylBenFcwcZNG5IaZ8jsIaEVraV/pbXgukYNb0Oqa0d8UWb0LkYzA1Bf1HmUrOfccFcRLheRuA7pA==} hasBin: true @@ -1243,6 +1246,9 @@ packages: '@changesets/get-dependents-graph@2.1.0': resolution: {integrity: sha512-QOt6pQq9RVXKGHPVvyKimJDYJumx7p4DO5MO9AhRJYgAPgv0emhNqAqqysSVKHBm4sxKlGN4S1zXOIb5yCFuhQ==} + '@changesets/get-github-info@0.6.0': + resolution: {integrity: sha512-v/TSnFVXI8vzX9/w3DU2Ol+UlTZcu3m0kXTjTT4KlAdwSvwutcByYwyYn9hwerPWfPkT2JfpoX0KgvCEi8Q/SA==} + '@changesets/get-release-plan@4.0.2': resolution: {integrity: sha512-rOalz7nMuMV2vyeP7KBeAhqEB7FM2GFPO5RQSoOoUKKH9L6wW3QyPA2K+/rG9kBrWl2HckPVES73/AuwPvbH3w==} @@ -4186,6 +4192,9 @@ packages: resolution: {integrity: sha512-t/Ygsytq+R995EJ5PZlD4Cu56sWa8InXySaViRzw9apusqsOO2bQP+SbYzAhR0pFKoB+43lYy8rWban9JSuXnA==} engines: {node: '>= 0.4'} + dataloader@1.4.0: + resolution: {integrity: sha512-68s5jYdlvasItOJnCuI2Q9s4q98g0pCyL3HrcKJu8KNugUl8ahgmZYg38ysLTgQjjXX3H8CJLkAvWrclWfcalw==} + date-fns@2.30.0: resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==} engines: {node: '>=0.11'} @@ -11422,6 +11431,14 @@ snapshots: dependencies: '@changesets/types': 6.0.0 + '@changesets/changelog-github@0.5.0': + dependencies: + '@changesets/get-github-info': 0.6.0 + '@changesets/types': 6.0.0 + dotenv: 8.6.0 + transitivePeerDependencies: + - encoding + '@changesets/cli@2.27.5': dependencies: '@babel/runtime': 7.24.5 @@ -11480,6 +11497,13 @@ snapshots: fs-extra: 7.0.1 semver: 7.6.2 + '@changesets/get-github-info@0.6.0': + dependencies: + dataloader: 1.4.0 + node-fetch: 2.7.0 + transitivePeerDependencies: + - encoding + '@changesets/get-release-plan@4.0.2': dependencies: '@babel/runtime': 7.24.5 @@ -15337,6 +15361,8 @@ snapshots: es-errors: 1.3.0 is-data-view: 1.0.1 + dataloader@1.4.0: {} + date-fns@2.30.0: dependencies: '@babel/runtime': 7.24.5