From e923d815896e5e4481ca10039a137d362f1625b3 Mon Sep 17 00:00:00 2001 From: Okiki Ojo Date: Fri, 28 Jul 2023 10:18:15 +0000 Subject: [PATCH] chore: ... --- .well-known/ai-plugin-prod.json | 18 + .well-known/ai-plugin.json | 4 +- .well-known/openapi-prod.yaml | 2065 +++++++++++++++++++++++++++++++ .well-known/openapi.yaml | 307 +++-- README.md | 7 +- deps.ts | 12 +- mod.ts | 249 ++-- 7 files changed, 2344 insertions(+), 318 deletions(-) create mode 100644 .well-known/ai-plugin-prod.json create mode 100644 .well-known/openapi-prod.yaml diff --git a/.well-known/ai-plugin-prod.json b/.well-known/ai-plugin-prod.json new file mode 100644 index 0000000..628945c --- /dev/null +++ b/.well-known/ai-plugin-prod.json @@ -0,0 +1,18 @@ +{ + "schema_version": "v1", + "name_for_human": "TypeScript Twoslash API", + "name_for_model": "typescript_twoslash_api", + "description_for_human": "Lint, auto-complete, error check, and type check ts, jsx/tsx, and js files.", + "description_for_model": "Processes TypeScript and JavaScript code using twoslash comments, feeds it to an API for linting, autocompletion, error/type checks, tooltips, and more for TS, JSX/TSX, JS files.", + "auth": { + "type": "none" + }, + "api": { + "type": "openapi", + "url": "https://ts-check.deno.dev/.well-known/openapi.yaml", + "is_user_authenticated": false + }, + "logo_url": "https://ts-check.deno.dev/.well-known/logo.png", + "contact_email": "hey@okikio.dev", + "legal_info_url": "https://okikio.dev/privacy" +} \ No newline at end of file diff --git a/.well-known/ai-plugin.json b/.well-known/ai-plugin.json index f7ff050..2646e44 100644 --- a/.well-known/ai-plugin.json +++ b/.well-known/ai-plugin.json @@ -9,10 +9,10 @@ }, "api": { "type": "openapi", - "url": "https://ts-check.deno.dev/.well-known/openapi.yaml", + "url": "https://ts-check.okikio.dev/.well-known/openapi.yaml", "is_user_authenticated": false }, - "logo_url": "https://ts-check.deno.dev/.well-known/logo.png", + "logo_url": "https://ts-check.okikio.dev/.well-known/logo.png", "contact_email": "hey@okikio.dev", "legal_info_url": "https://okikio.dev/privacy" } \ No newline at end of file diff --git a/.well-known/openapi-prod.yaml b/.well-known/openapi-prod.yaml new file mode 100644 index 0000000..7f061c9 --- /dev/null +++ b/.well-known/openapi-prod.yaml @@ -0,0 +1,2065 @@ +openapi: 3.1.0 +info: + title: TypeScript Twoslash API + description: A REST API for transforming TypeScript code using twoslash. + version: '1.0' + license: + name: MIT + url: https://github.com/okikio/ai-typescript-check/blob/main/LICENSE + contact: + name: Okiki Ojo + email: hey@okikio.dev + url: https://okikio.dev + termsOfService: https://okikio.dev/terms +servers: + - url: https://ts-check.okikio.dev/ + description: Main server +externalDocs: + description: Shiki Twoslash's documentation, is not quite the same as the full TypeScript Twoslash docs but it should cover all the basics required + url: https://shikijs.github.io/twoslash/ +paths: + /twoslash: + post: + operationId: postToTypescriptTwoslash + summary: Run TypeScript Twoslash on a given code + description: | + This endpoint accepts TwoSlashOptions as JSON/FormData and returns TwoSlashReturn JSON. + Used for transforming TypeScript and Javascript code with twoslash options. + Supports ts, js, tsx, jsx. + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/TwoSlashOptions' + multipart/form-data: + schema: + $ref: '#/components/schemas/TwoSlashOptions' + responses: + '200': + description: Successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/TwoSlashReturn' + '400': + description: Errors were thrown in the sample, but not included in an errors tag + content: + text/plain: + schema: + $ref: '#/components/schemas/TwoslashError' + get: + operationId: getTypescriptTwoslash + summary: Run TypeScript Twoslash on a given code + description: | + This endpoint accepts TwoSlashOptions as JSON/FormData and returns TwoSlashReturn JSON. + Used for transforming TypeScript and Javascript code with twoslash options. + Supports ts, js, tsx, jsx. + parameters: + - name: options + in: query + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/TwoSlashOptions' + - name: option + in: query + content: + application/json: + schema: + $ref: '#/components/schemas/TwoSlashOptions' + - name: code + in: query + content: + text/plain: + schema: + $ref: '#/components/schemas/TwoSlashOptions/properties/code' + - name: extension + in: query + content: + text/plain: + schema: + $ref: '#/components/schemas/TwoSlashOptions/properties/extension' + - name: ext + in: query + content: + text/plain: + schema: + $ref: '#/components/schemas/TwoSlashOptions/properties/extension' + responses: + '200': + description: Successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/TwoSlashReturn' + '400': + description: Errors were thrown in the sample, but not included in an errors tag + content: + text/plain: + schema: + $ref: '#/components/schemas/TwoslashError' +components: + schemas: + TwoSlashOptions: + type: object + properties: + code: + type: string + description: | + The TypeScript, JavaScript, TSX, or JSX code to run twoslash over. Twoslash comments can be used for various features like: + - Compiler flag comments: `// @noImplicitAny: false`, `// @target: ES2015`, etc. + - Error comments: `// @noErrors`, `// @errors` Lint the code for syntax errors and best practices. + - Emitted file comments: `// @showEmit`, `// @showEmittedFile: index.d.ts` + - Static semantic info comments: `// @noStaticSemanticInfo` + - Emit comments: `// @emit` + - Error validation comments: `// @noErrorValidation` + - Filename comments: `// @filename` + - Script Target comments: `// @target` + - Declaration comments: `// @declaration: true` + - Cut comments: `// ---cut---` to cut out unnecessary code before the comment. `// ---cut-after---` to cut out unnecessary code after the comment. + - Type queries: `// ^?` to query types of variables, objects, functions, arrays, maps, symbols, parameters and/or values. Check type information for the line of code above the comment. + - Auto-Completions: `// ^|` Auto-complete code suggestions. + - Highlighting: `// ^^^ Description` for highlighting the section of code above the comment. Remember to add a space after the `^^^` to avoid syntax errors. + - Import files: `// @filename: import_files.ts` for importing files + - Full Compile Options List: + - `// @module: esnext`, `// @jsx: preserve`, `// @lib: esnext`, `// @strict: true`, `// @noImplicitAny: false`, `// @target: ES2022`, `// @declaration: true`, + - `// @noUnusedLocals: true`, `// @noUnusedParameters: true`, `// @noImplicitReturns: true`, `// @noFallthroughCasesInSwitch: true`, `// @allowUnreachableCode: false`, + - `// @allowUnusedLabels: false`, `// @noImplicitOverride: true`, `// @exactOptionalPropertyTypes: true`, `// @noPropertyAccessFromIndexSignature: true`, + - `// @noUncheckedIndexedAccess: true`, `// @noImplicitThis: true`, `// @strictBindCallApply: true`, `// @strictFunctionTypes: true`, `// @strictNullChecks: true`, + - `// @strictPropertyInitialization: true`, `// @useUnknownInCatchVariables: true`, `// @allowArbitraryExtensions: true`, `// @allowImportingTsExtensions: true`, + - `// @alwaysStrict: true`, `// @noEmit: true`, `// @noEmitOnError: true`, `// @preserveConstEnums: true`, `// @removeComments: true`, `// @skipLibCheck: true`, + - `// @sourceMap: true`, `// @inlineSourceMap: true`, `// @inlineSources: true`, `// @emitDeclarationOnly: true`, `// @declarationMap: true`, `// @declarationDir: ./`, + - `// @listEmittedFiles: true`, `// @listFiles: true`, `// @pretty: true`, `// @downlevelIteration: true`, `// @isolatedModules: true`, `// @importHelpers: true`, + - `// @experimentalDecorators: true`, `// @emitDecoratorMetadata: true`, `// @importsNotUsedAsValues: true`, `// @noEmitHelpers: true`, `// @noImplicitUseStrict: true`, + - `// @noLib: true`, `// @noResolve: true`, `// @noStrictGenericChecks: true`, `// @noUncheckedIndexedAccess: true`, `// @noUnusedLocals: true`, `// @noUnusedParameters: true`, + - `// @strictBindCallApply: true`, `// @strictFunctionTypes: true`, `// @strictNullChecks: true`, `// @strictPropertyInitialization: true`, `// @useUnknownInCatchVariables: true`, + - `// @allowJs: true`, `// @checkJs: true`, `// @jsx: preserve`, `// @jsxFactory: React`, `// @jsxFragmentFactory: React`, `// @jsxImportSource: React`, + - `// @allowUnreachableCode`: Do not report errors on unreachable code. + - `// @allowUnusedLabels`: Do not report errors on unused labels. + - `// @alwaysStrict`: Parse in strict mode and emit "use strict" for each source file. + - `// @exactOptionalPropertyTypes`: Differentiate between optional property and undefined property in the type system. + - `// @noFallthroughCasesInSwitch`: Report errors for fallthrough cases in switch statements. + - `// @noImplicitAny`: Raise error on expressions and declarations with an implied 'any' type. + - `// @noImplicitOverride`: Ensure overriding members in derived classes are marked with an 'override' modifier. + - `// @noImplicitReturns`: Report error when not all code paths in function return a value. + - `// @noImplicitThis`: Raise error on 'this' expressions with an implied 'any' type. + - `// @noPropertyAccessFromIndexSignature`: Require undeclared properties from index signatures to be accessed with an index. + - `// @noUncheckedIndexedAccess`: Add a 'undefined' type to elements accessed via an index signature. + - `// @noUnusedLocals`: Report errors on unused locals. + - `// @noUnusedParameters`: Report errors on unused parameters. + - `// @strict`: Enable all strict type checking options. + - `// @strictBindCallApply`: Enable stricter checking of bind, call, and apply. + - `// @strictFunctionTypes`: Enable stricter checking of function types. + - `// @strictNullChecks`: Enable strict null checks. + - `// @strictPropertyInitialization`: Enable strict checking of property initialization. + - `// @useUnknownInCatchVariables`: Type catch clause variables as 'unknown' instead of 'any'. + - `// @allowArbitraryExtensions`: Allow arbitrary file extensions to be included in the program. + - `// @allowImportingTsExtensions`: Allow '.ts' and '.tsx' extensions to be imported. + - `// @allowUmdGlobalAccess`: Allow accessing UMD globals from modules. + - `// @baseUrl`: Base directory to resolve non-relative module names. + - `// @customConditions`: List of custom conditions to apply to module resolution. + - `// @module`: Specify module code generation. + - `// @moduleResolution`: Specify module resolution strategy. + - `// @moduleSuffixes`: List of file extensions to consider when resolving modules. + - `// @noResolve`: Do not add triple-slash references or module import targets to the list of compiled files. + - `// @paths`: A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. + - `// @resolveJsonModule`: Include modules imported with '.json' extension. + - `// @resolvePackageJsonExports`: Resolve the 'exports' field in 'package.json'. + - `// @resolvePackageJsonImports`: Resolve the 'imports' field in 'package.json'. + - `// @rootDir`: Specifies the root directory of input files. + - `// @rootDirs`: List of root folders whose combined content represents the structure of the project at runtime. + - `// @typeRoots`: List of folders to include type definitions from. + - `// @types`: Type declaration files to be included in compilation. + - `// @declaration`: Generates corresponding '.d.ts' file. + - `// @declarationDir`: Output directory for generated declaration files. + - `// @declarationMap`: Generates a sourcemap for each corresponding '.d.ts' file. + - `// @downlevelIteration`: Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. + - `// @emitBOM`: Specifies whether to emit a byte order mark (BOM) in emitted files. The byte order mark (BOM) is a Unicode character that serves as an indicator for the encoding of a text file. By default, TypeScript emits files without a BOM. Enabling `emitBOM` instructs TypeScript to include the BOM character at the beginning of emitted files, which can be useful for compatibility with certain tools and environments. + examples: + - | + // @module: esnext + // @target: ES2022 + // @errors: 1003 2304 7006 2339 + // @declaration: true + // @emit + // @filename: maths.ts + /** + * Gets the length of a string + * @param value a string + */ + function fnx2(s: string) { + console.log(s.substr(3)) + } + export function absolute(num: number) { + if (num < 0) return num * -1; + return num; + } + + import {SpringEasing} from "spring-easing" + SpringEasing + // ^? + + /** + * Gets the length of a string + * @param value a string + */ + function fnx(s: string) { + console.log(s.substr(3)) + } + + export const slash = [] as string[] + fnx("42") + //^? + // ^^^^^ + + function greet(person: string, date: Date) { + console.log(\`Hello \${person}, today is \${date.toDateString()}!\`) + } + + greet("Maddison", new Date()) + // ^^^^^ A Quick explanation + console.g + // ^| + + // @filename: index.ts + import {absolute} from "./maths" + const value = absolute(-1) + // ^? + // ^^^^^^^^^^ + const value2 = absolute(-2) + // ^? + // ^^^^^^^^ + + function fn(s) { + console.log(s.substr(3)) + } + extension: + type: string + description: The extension of the code file. Can be 'typescript', 'javascript', 'json', 'jsn', 'ts', 'js', 'tsx', or 'jsx'. + examples: + - "ts" + defaultOptions: + $ref: '#/components/schemas/ExampleOptions' + defaultCompilerOptions: + $ref: '#/components/schemas/CompilerOptions' + fsMap: + type: object + examples: + - 'index.ts': 'export const x = 10' + customTags: + type: array + items: + type: string + examples: ['tag1', 'tag2'] + examples: + - + code: | + const abolute = (num: number) => num < 0 ? num * -1 : num + // ^? + extension: 'ts' + defaultOptions: + noErrors: false + errors: [1016, 2307] + noStaticSemanticInfo: false + emit: false + noErrorValidation: false + defaultCompilerOptions: + target: 'es2022' + module: 'es2022' + fsMap: + 'index.ts': 'export const x = 10' + customTags: ['tag1', 'tag2'] + required: + - code + - extension + ExampleOptions: + type: object + properties: + noErrors: + type: boolean + errors: + type: array + items: + type: integer + showEmit: + type: boolean + showEmittedFile: + type: string + noStaticSemanticInfo: + type: boolean + emit: + type: boolean + noErrorValidation: + type: boolean + TwoSlashReturn: + type: object + properties: + code: + type: string + description: The resulting code after twoslash. + extension: + type: string + highlights: + type: array + items: + $ref: '#/components/schemas/Highlight' + staticQuickInfos: + type: array + items: + $ref: '#/components/schemas/StaticQuickInfo' + queries: + type: array + items: + $ref: '#/components/schemas/Query' + tags: + type: array + items: + $ref: '#/components/schemas/Tag' + errors: + type: array + items: + $ref: '#/components/schemas/Error' + description: Any error that occurred in twoslash or typescript. + warnings: + type: array + items: + $ref: '#/components/schemas/Error' + description: Any non breaking error that occurred in twoslash or typescript. + playgroundURL: + type: string + examples: + - + code: | + // @filename: maths.ts + /** + * Gets the length of a string + * @param value a string + */ + function fnx2(s: string) { + console.log(s.substr(3)) + } + export function absolute(num: number) { + if (num < 0) return num * -1; + return num; + } + + import {SpringEasing} from "spring-easing" + SpringEasing + + /** + * Gets the length of a string + * @param value a string + */ + function fnx(s: string) { + console.log(s.substr(3)) + } + + export const slash = [] as string[] + fnx("42") + + function greet(person: string, date: Date) { + console.log(`Hello ${person}, today is ${date.toDateString()}!`) + } + + greet("Maddison", new Date()) + console.g + + // @filename: index.ts + import {absolute} from "./maths" + const value = absolute(-1) + const value2 = absolute(-2) + + function fn(s) { + console.log(s.substr(3)) + } + extension: ts + highlights: + - kind: highlight + offset: 370 + length: 11 + text: '' + line: 21 + start: 14 + - kind: highlight + offset: 425 + length: 7 + text: You need a description for highlight to work properly + line: 27 + start: 3 + - kind: highlight + offset: 553 + length: 5 + text: A Quick explanation + line: 34 + start: 3 + - kind: highlight + offset: 39 + length: 6 + text: Velue + line: 2 + start: 6 + - kind: highlight + offset: 66 + length: 6 + text: Value2 + line: 5 + start: 6 + queries: + - docs: >- + Generates an Array of values using frame functions which in turn create + the effect of spring easing. + + To use this properly make sure to set the easing animation option to + "linear". + + Check out a demo of SpringEasing at + + + + SpringEasing has 3 properties they are `easing` (all the easings from +
{@link
EasingFunctions
}
are supported on top of frame + functions like SpringFrame, SpringFrameOut, etc..), `numPoints` (the size + of the Array the frame function should create), and `decimal` (the number + of decimal places of the values within said Array). + + + | Properties | Default Value | + + | ----------- | ----------------------- | + + | `easing` | `spring(1, 100, 10, 0)` | + + | `numPoints` | `50` | + + | `decimal` | `3` | + + + By default, Spring Easing support easings in the form, + + + | constant | accelerate | decelerate | accelerate-decelerate + | decelerate-accelerate | + + | :--------- | :----------------- | :------------- | :-------------------- + | :-------------------- | + + | | spring / spring-in | spring-out | spring-in-out + | spring-out-in | + + + All **Spring** easing's can be configured using theses parameters, + + + `spring-*(mass, stiffness, damping, velocity)` + + + Each parameter comes with these defaults + + + | Parameter | Default Value | + + | --------- | ------------- | + + | mass | `1` | + + | stiffness | `100` | + + | damping | `10` | + + | velocity | `0` | + + e.g. + ```ts + import { SpringEasing, SpringOutFrame } from "spring-easing"; + import anime from "animejs"; + + // Note: this is the return value of
{@link
SpringEasing
}
and
{@link
GenerateSpringFrames
}
, you don't need the object to get this format + let [translateX, duration] = SpringEasing([0, 250], { + easing: "spring-out-in(1, 100, 10, 0)", + + // You can change the size of Array for the SpringEasing function to generate + numPoints: 200, + + // The number of decimal places to round, final values in the generated Array + // This option doesn't exist on
{@link
GenerateSpringFrames
}
+ decimal: 5, + }); + + anime({ + targets: "div", + + // Using spring easing animate from [0 to 250] using `spring-out-in` + translateX, + + // You can set the easing without an object + rotate: SpringEasing(["0turn", 1, 0, 0.5], [SpringOutFrame, 1, 100, 10, 0])[0], + + // TIP... Use linear easing for the proper effect + easing: "linear", + + // The optimal duration for this specific spring + duration + }) + ``` + kind: query + start: 255 + length: 197 + text: >- + (alias) function SpringEasing(values: T[], options?: TypeEasingOptions + | TypeEasingOptions["easing"], customInterpolate?: + TypeInterpolationFunction): readonly [any[], number] + + import SpringEasing + offset: 3 + line: 14 + - docs: Gets the length of a string + kind: query + start: 421 + length: 29 + text: 'function fnx(s: string): void' + offset: 2 + line: 26 + - completions: + - name: assert + kind: method + kindModifiers: declare + sortText: '11' + - name: clear + kind: method + kindModifiers: declare + sortText: '11' + - name: count + kind: method + kindModifiers: declare + sortText: '11' + - name: countReset + kind: method + kindModifiers: declare + sortText: '11' + - name: debug + kind: method + kindModifiers: declare + sortText: '11' + - name: dir + kind: method + kindModifiers: declare + sortText: '11' + - name: dirxml + kind: method + kindModifiers: declare + sortText: '11' + - name: error + kind: method + kindModifiers: declare + sortText: '11' + - name: group + kind: method + kindModifiers: declare + sortText: '11' + - name: groupCollapsed + kind: method + kindModifiers: declare + sortText: '11' + - name: groupEnd + kind: method + kindModifiers: declare + sortText: '11' + - name: info + kind: method + kindModifiers: declare + sortText: '11' + - name: log + kind: method + kindModifiers: declare + sortText: '11' + - name: table + kind: method + kindModifiers: declare + sortText: '11' + - name: time + kind: method + kindModifiers: declare + sortText: '11' + - name: timeEnd + kind: method + kindModifiers: declare + sortText: '11' + - name: timeLog + kind: method + kindModifiers: declare + sortText: '11' + - name: timeStamp + kind: method + kindModifiers: declare + sortText: '11' + - name: trace + kind: method + kindModifiers: declare + sortText: '11' + - name: warn + kind: method + kindModifiers: declare + sortText: '11' + kind: completions + start: 662 + completionsPrefix: g + length: 1 + offset: 9 + line: 35 + - docs: '' + kind: query + start: 40 + length: 19 + text: 'const value: number' + offset: 7 + line: 2 + - docs: '' + kind: query + start: 77 + length: 20 + text: 'const value2: number' + offset: 7 + line: 4 + staticQuickInfos: + - text: 'function fnx2(s: string): void' + docs: Gets the length of a string + start: 73 + length: 4 + line: 3 + character: 14 + targetString: fnx2 + - text: '(parameter) s: string' + docs: '' + start: 78 + length: 1 + line: 3 + character: 19 + targetString: s + - text: 'var console: Console' + docs: '' + start: 93 + length: 7 + line: 5 + character: 5 + targetString: console + - text: '(method) Console.log(...data: any[]): void' + docs: '' + start: 101 + length: 3 + line: 5 + character: 13 + targetString: log + - text: '(parameter) s: string' + docs: '' + start: 105 + length: 1 + line: 5 + character: 17 + targetString: s + - text: '(method) String.substr(from: number, length?: number | undefined): string' + docs: >- + Gets a substring beginning at the specified location and having the + specified length. + start: 107 + length: 6 + line: 5 + character: 19 + targetString: substr + - text: 'function absolute(num: number): number' + docs: '' + start: 136 + length: 8 + line: 6 + character: 21 + targetString: absolute + - text: '(parameter) num: number' + docs: '' + start: 145 + length: 3 + line: 8 + character: 1 + targetString: num + - text: '(parameter) num: number' + docs: '' + start: 166 + length: 3 + line: 8 + character: 22 + targetString: num + - text: '(parameter) num: number' + docs: '' + start: 182 + length: 3 + line: 8 + character: 38 + targetString: num + - text: '(parameter) num: number' + docs: '' + start: 201 + length: 3 + line: 9 + character: 17 + targetString: num + - text: >- + (alias) function SpringEasing(values: T[], options?: TypeEasingOptions + | TypeEasingOptions["easing"], customInterpolate?: + TypeInterpolationFunction): readonly [any[], number] + + import SpringEasing + docs: >- + Generates an Array of values using frame functions which in turn create + the effect of spring easing. + + To use this properly make sure to set the easing animation option to + "linear". + + Check out a demo of SpringEasing at + + + + SpringEasing has 3 properties they are `easing` (all the easings from + {@link EasingFunctions} are supported on top of frame functions like + SpringFrame, SpringFrameOut, etc..), `numPoints` (the size of the Array + the frame function should create), and `decimal` (the number of decimal + places of the values within said Array). + + + | Properties | Default Value | + + | ----------- | ----------------------- | + + | `easing` | `spring(1, 100, 10, 0)` | + + | `numPoints` | `50` | + + | `decimal` | `3` | + + + By default, Spring Easing support easings in the form, + + + | constant | accelerate | decelerate | accelerate-decelerate + | decelerate-accelerate | + + | :--------- | :----------------- | :------------- | :-------------------- + | :-------------------- | + + | | spring / spring-in | spring-out | spring-in-out + | spring-out-in | + + + All **Spring** easing's can be configured using theses parameters, + + + `spring-*(mass, stiffness, damping, velocity)` + + + Each parameter comes with these defaults + + + | Parameter | Default Value | + + | --------- | ------------- | + + | mass | `1` | + + | stiffness | `100` | + + | damping | `10` | + + | velocity | `0` | + + e.g. + ```ts + import { SpringEasing, SpringOutFrame } from "spring-easing"; + import anime from "animejs"; + + // Note: this is the return value of {@link SpringEasing} and {@link GenerateSpringFrames}, you don't need the object to get this format + let [translateX, duration] = SpringEasing([0, 250], { + easing: "spring-out-in(1, 100, 10, 0)", + + // You can change the size of Array for the SpringEasing function to generate + numPoints: 200, + + // The number of decimal places to round, final values in the generated Array + // This option doesn't exist on {@link GenerateSpringFrames} + decimal: 5, + }); + + anime({ + targets: "div", + + // Using spring easing animate from [0 to 250] using `spring-out-in` + translateX, + + // You can set the easing without an object + rotate: SpringEasing(["0turn", 1, 0, 0.5], [SpringOutFrame, 1, 100, 10, 0])[0], + + // TIP... Use linear easing for the proper effect + easing: "linear", + + // The optimal duration for this specific spring + duration + }) + ``` + start: 217 + length: 12 + line: 10 + character: 1 + targetString: SpringEasing + - text: >- + (alias) function SpringEasing(values: T[], options?: TypeEasingOptions + | TypeEasingOptions["easing"], customInterpolate?: + TypeInterpolationFunction): readonly [any[], number] + + import SpringEasing + docs: >- + Generates an Array of values using frame functions which in turn create + the effect of spring easing. + + To use this properly make sure to set the easing animation option to + "linear". + + Check out a demo of SpringEasing at + + + + SpringEasing has 3 properties they are `easing` (all the easings from + {@link EasingFunctions} are supported on top of frame functions like + SpringFrame, SpringFrameOut, etc..), `numPoints` (the size of the Array + the frame function should create), and `decimal` (the number of decimal + places of the values within said Array). + + + | Properties | Default Value | + + | ----------- | ----------------------- | + + | `easing` | `spring(1, 100, 10, 0)` | + + | `numPoints` | `50` | + + | `decimal` | `3` | + + + By default, Spring Easing support easings in the form, + + + | constant | accelerate | decelerate | accelerate-decelerate + | decelerate-accelerate | + + | :--------- | :----------------- | :------------- | :-------------------- + | :-------------------- | + + | | spring / spring-in | spring-out | spring-in-out + | spring-out-in | + + + All **Spring** easing's can be configured using theses parameters, + + + `spring-*(mass, stiffness, damping, velocity)` + + + Each parameter comes with these defaults + + + | Parameter | Default Value | + + | --------- | ------------- | + + | mass | `1` | + + | stiffness | `100` | + + | damping | `10` | + + | velocity | `0` | + + e.g. + ```ts + import { SpringEasing, SpringOutFrame } from "spring-easing"; + import anime from "animejs"; + + // Note: this is the return value of {@link SpringEasing} and {@link GenerateSpringFrames}, you don't need the object to get this format + let [translateX, duration] = SpringEasing([0, 250], { + easing: "spring-out-in(1, 100, 10, 0)", + + // You can change the size of Array for the SpringEasing function to generate + numPoints: 200, + + // The number of decimal places to round, final values in the generated Array + // This option doesn't exist on {@link GenerateSpringFrames} + decimal: 5, + }); + + anime({ + targets: "div", + + // Using spring easing animate from [0 to 250] using `spring-out-in` + translateX, + + // You can set the easing without an object + rotate: SpringEasing(["0turn", 1, 0, 0.5], [SpringOutFrame, 1, 100, 10, 0])[0], + + // TIP... Use linear easing for the proper effect + easing: "linear", + + // The optimal duration for this specific spring + duration + }) + ``` + start: 252 + length: 12 + line: 13 + character: 19 + targetString: SpringEasing + - text: 'function fnx(s: string): void' + docs: Gets the length of a string + start: 345 + length: 3 + line: 18 + character: 20 + targetString: fnx + - text: '(parameter) s: string' + docs: '' + start: 349 + length: 1 + line: 18 + character: 24 + targetString: s + - text: 'var console: Console' + docs: '' + start: 364 + length: 7 + line: 20 + character: 10 + targetString: console + - text: '(method) Console.log(...data: any[]): void' + docs: '' + start: 372 + length: 3 + line: 20 + character: 18 + targetString: log + - text: '(parameter) s: string' + docs: '' + start: 376 + length: 1 + line: 20 + character: 22 + targetString: s + - text: '(method) String.substr(from: number, length?: number | undefined): string' + docs: >- + Gets a substring beginning at the specified location and having the + specified length. + start: 378 + length: 6 + line: 20 + character: 24 + targetString: substr + - text: 'const slash: string[]' + docs: '' + start: 432 + length: 5 + line: 24 + character: 22 + targetString: slash + - text: 'function fnx(s: string): void' + docs: Gets the length of a string + start: 457 + length: 3 + line: 25 + character: 11 + targetString: fnx + - text: 'function greet(person: string, date: Date): void' + docs: '' + start: 547 + length: 5 + line: 28 + character: 43 + targetString: greet + - text: '(parameter) person: string' + docs: '' + start: 553 + length: 6 + line: 28 + character: 49 + targetString: person + - text: '(parameter) date: Date' + docs: '' + start: 569 + length: 4 + line: 28 + character: 65 + targetString: date + - text: interface Date + docs: Enables basic storage and retrieval of dates and times. + start: 575 + length: 4 + line: 31 + character: 1 + targetString: Date + - text: 'var console: Console' + docs: '' + start: 585 + length: 7 + line: 31 + character: 11 + targetString: console + - text: '(method) Console.log(...data: any[]): void' + docs: '' + start: 593 + length: 3 + line: 31 + character: 19 + targetString: log + - text: '(parameter) person: string' + docs: '' + start: 606 + length: 6 + line: 31 + character: 32 + targetString: person + - text: '(parameter) date: Date' + docs: '' + start: 626 + length: 4 + line: 34 + character: 7 + targetString: date + - text: '(method) Date.toDateString(): string' + docs: Returns a date as a string value. + start: 631 + length: 12 + line: 34 + character: 12 + targetString: toDateString + - text: 'function greet(person: string, date: Date): void' + docs: '' + start: 656 + length: 5 + line: 35 + character: 13 + targetString: greet + - text: |- + var Date: DateConstructor + new () => Date (+4 overloads) + docs: '' + start: 678 + length: 4 + line: 36 + character: 2 + targetString: Date + - text: 'var console: Console' + docs: '' + start: 717 + length: 7 + line: 37 + character: 14 + targetString: console + - text: any + start: 725 + length: 1 + line: 37 + character: 22 + targetString: g + - text: |- + (alias) function absolute(num: number): number + import absolute + docs: '' + start: 8 + length: 8 + line: 0 + character: 8 + targetString: absolute + - text: 'const value: number' + docs: '' + start: 39 + length: 5 + line: 2 + character: 11 + targetString: value + - text: |- + (alias) absolute(num: number): number + import absolute + docs: '' + start: 47 + length: 8 + line: 2 + character: 19 + targetString: absolute + - text: 'const value2: number' + docs: '' + start: 95 + length: 6 + line: 5 + character: 7 + targetString: value2 + - text: |- + (alias) absolute(num: number): number + import absolute + docs: '' + start: 104 + length: 8 + line: 5 + character: 16 + targetString: absolute + - text: 'function fn(s: any): void' + docs: '' + start: 157 + length: 2 + line: 8 + character: 13 + targetString: fn + - text: '(parameter) s: any' + docs: '' + start: 160 + length: 1 + line: 8 + character: 16 + targetString: s + - text: 'var console: Console' + docs: '' + start: 167 + length: 7 + line: 8 + character: 23 + targetString: console + - text: '(method) Console.log(...data: any[]): void' + docs: '' + start: 175 + length: 3 + line: 8 + character: 31 + targetString: log + - text: '(parameter) s: any' + docs: '' + start: 179 + length: 1 + line: 8 + character: 35 + targetString: s + - text: any + start: 181 + length: 6 + line: 8 + character: 37 + targetString: substr + errors: + - category: 1 + code: 2339 + length: 1 + start: 749 + line: 36 + character: 8 + renderedMessage: Property 'g' does not exist on type 'Console'. + id: err-2339-725-1 + - category: 1 + code: 7006 + length: 1 + start: 803 + line: 8 + character: 12 + renderedMessage: Parameter 's' implicitly has an 'any' type. + id: err-7006-160-1 + warnings: + - category: 2 + code: 6133 + length: 4 + start: 97 + line: 4 + character: 9 + renderedMessage: '''fnx2'' is declared but its value is never read.' + id: warn-6133-73-4 + - category: 2 + code: 6387 + length: 6 + start: 131 + line: 5 + character: 16 + renderedMessage: >- + The signature '(from: number, length?: number | undefined): string' of + 's.substr' is deprecated. + id: warn-6387-107-6 + - category: 2 + code: 6387 + length: 6 + start: 402 + line: 21 + character: 16 + renderedMessage: >- + The signature '(from: number, length?: number | undefined): string' of + 's.substr' is deprecated. + id: warn-6387-378-6 + - category: 2 + code: 6133 + length: 5 + start: 682 + line: 1 + character: 6 + renderedMessage: '''value'' is declared but its value is never read.' + id: warn-6133-39-5 + - category: 2 + code: 6133 + length: 6 + start: 738 + line: 4 + character: 6 + renderedMessage: '''value2'' is declared but its value is never read.' + id: warn-6133-95-6 + - category: 2 + code: 6133 + length: 2 + start: 800 + line: 8 + character: 9 + renderedMessage: '''fn'' is declared but its value is never read.' + id: warn-6133-157-2 + playgroundURL: >- + https://www.typescriptlang.org/play/#code/PTAEAEFsHsBMFcA2BTAXKZBnAdsgHgC4BQIEBAhgE4DmyB6AogMoBMADCyyWOMpZdEqZ0ARjZsAzKBYS2AFlAB2cQDZpEiQE5uEWMgDGiKuQIBLaNnQFK8ZDt6RTxUuABmplNnKQ0oSCYALTAA6AkxQEgAqSKJQSNAAcTpwggDkUE9qVNBoV1ByUExrU2xqWPjwAAdjSFAAN3JEW3zC4tLy4CJXeGx9MwtQV2w8FgAKYVbKEuoASlAAb1jQfQtMaBRgxGhqceDMeAAjIspRiRmZogBfInxKwQJBnr7zbHyj9fgCZFHseEh0X6QA58OaLUCgUx5H5-UAAHlAbDmlDo8Eor0BcVAAFoRABuJbIgio9F-fHXIimSB3SgPeZMSpTUoMciYaaXQYCWoAIkwDOmWOQLOmXKI9MZ1GZrPapAAegB+IhRGKYpJhUCpdKZbK5FrHablCDVSjeeqNZoFPXtOKdbq9fqvIZ4cboS2zBZLFbYNYbLY7EL7I7WU7nHTgsPh8EyqPRmMyiLk273ZarB6YIyYAKgAC8oAA2gBdfLhV0FpaO0ZcuQsLkXEDynSxqOgACa0HgoFwyFgLT0mH0U0q9sGglAAVM1ACiHHAQeBGgoAA7oIANagBnQSp8RAAT0VtueA2oyLoo03QgsLra1AANKBYCZfAARB+gj2rdbITbbUYAAwAEsgiBbKAAAk8xnms2CXLec73tuELhGB95fKE0DPl8TBXqMMyXAAhD+FzkmGR7ICeXIALLkLAsCmJBXK3rgC6gOh3whrKMagAAgqAACK8CmPoq63EYXhDhEnrep+1ARKQEagDKAA+iouO4njeL4JR6HgoThBSVJJvM5DvE0Xzsq4nKgFywTAP4qSYCKEkPA0TTpDmRnep83w4rWYDhvWsmRrGoAAGqAbYRCOaaLksNmbweV8oxYiwPkRv5vmBRxwVmsgXBdE8Q5DOMr7ghJH5fn6eyHMcwaEUQQA + tags: [] + + + + Highlight: + type: object + properties: + kind: + type: string + start: + type: integer + line: + type: integer + offset: + type: integer + text: + type: string + length: + type: integer + StaticQuickInfo: + type: object + properties: + targetString: + type: string + text: + type: string + docs: + type: string + start: + type: integer + length: + type: integer + line: + type: integer + character: + type: integer + Query: + type: object + properties: + kind: + type: string + line: + type: integer + offset: + type: integer + text: + type: string + docs: + type: string + start: + type: integer + length: + type: integer + completions: + type: array + items: + type: object + additionalProperties: true + completionsPrefix: + type: string + Tag: + type: object + properties: + name: + type: string + line: + type: integer + annotation: + type: string + Error: + type: object + properties: + renderedMessage: + type: string + id: + type: string + category: + type: integer + code: + type: integer + start: + type: integer + length: + type: integer + line: + type: integer + character: + type: integer + codeAction: + type: array + items: + $ref: "#/components/schemas/CodeAction" + + + TextSpan: + type: object + description: The text span to be changed. + properties: + start: + type: number + description: The starting position of the text span. + examples: + - 10 + length: + type: number + description: The length of the text span. + examples: [5] + + TextChange: + type: object + properties: + span: + $ref: "#/components/schemas/TextSpan" + newText: + type: string + description: The new text to replace the span. + examples: ["Hello, world!"] + + FileTextChanges: + type: object + properties: + fileName: + type: string + description: The name of the file to be changed. + examples: ["example.ts"] + textChanges: + type: array + items: + $ref: "#/components/schemas/TextChange" + description: The array of text changes to be applied. + isNewFile: + type: boolean + description: Indicates if the file is a new file. + examples: [true] + + CodeAction: + type: object + properties: + description: + type: string + description: Description of the code action to display in the UI of the editor. + examples: ["Fix formatting issues"] + changes: + type: array + items: + $ref: "#/components/schemas/FileTextChanges" + description: Text changes to apply to each file as part of the code action. + + TwoslashError: + type: object + properties: + error: + type: string + message: + type: string + errors: + type: array + items: + type: integer + compilerErrors: + type: string + examples: + - + error: "Uncaught Error" + message: "Errors were thrown in the sample, but not included in an errors tag" + errors: [7006] + compilerErrors: "index.ts [7006] 76 - Parameter 's' implicitly has an 'any' type." + + CompilerOptions: + type: object + properties: + allowImportingTsExtensions: + type: boolean + description: | + Allows importing TypeScript files with .ts extension. + By enabling this option, TypeScript files with the `.ts` extension can be imported in the TypeScript project. By default, only files with the `.tsx` and `.d.ts` extensions are allowed to be imported. + examples: [true] + allowJs: + type: boolean + description: | + Allows JavaScript files to be included in the TypeScript project. + When this option is enabled, JavaScript files (`.js`) can be included and compiled within the TypeScript project. This is useful for mixed JavaScript and TypeScript projects. + examples: [true] + allowArbitraryExtensions: + type: boolean + description: | + Allows importing files with arbitrary extensions. + Enabling this option allows importing files with extensions that are not commonly associated with TypeScript or JavaScript, such as `.txt`, `.css`, or custom file extensions. It can be useful for special scenarios but should be used with caution. + examples: [false] + allowSyntheticDefaultImports: + type: boolean + description: | + Allows synthetic default imports for modules. + Synthetic default imports enable importing modules that have a default export, even if the module itself doesn't explicitly define a default export. When enabled, TypeScript will attempt to generate an appropriate default import. This is useful when working with modules that don't provide a default export but are commonly consumed with default imports. + examples: [true] + allowUmdGlobalAccess: + type: boolean + description: | + Allows accessing UMD globals from modules. + When using UMD modules, this option allows TypeScript to access global variables defined by UMD modules directly. UMD modules typically expose their functionality via global variables, and enabling this option makes those globals accessible from TypeScript code. + examples: [true] + allowUnreachableCode: + type: boolean + description: | + Allows unreachable code in the TypeScript project. + By default, TypeScript flags unreachable code as an error. However, in certain cases, such as during development or debugging, it may be necessary to have unreachable code that is intentionally not executed. Enabling this option allows the presence of unreachable code without raising an error. + examples: [false] + allowUnusedLabels: + type: boolean + description: | + Allows unused labels in the TypeScript project. + Labels in TypeScript are used to mark specific locations in the code for control flow purposes. By default, TypeScript raises an error when a label is declared but not used. Enabling this option allows the presence of unused labels without raising an error. + examples: [false] + alwaysStrict: + type: boolean + description: | + Enables strict mode for all files in the TypeScript project. + Strict mode enforces stricter rules and more rigorous type checking in TypeScript. Enabling this option ensures that strict mode is applied to all files in the TypeScript project, regardless of whether they include a `"use strict"` directive or not. + examples: [true] + baseUrl: + type: string + description: | + Specifies the base directory for resolving non-relative module names. + The `baseUrl` option is used to specify the base directory that TypeScript uses for resolving non-relative module names. When a module name is encountered that does not start with `./` or `../`, TypeScript will resolve the module path relative to the `baseUrl` directory. + examples: ["./src"] + charset: + type: string + description: | + Specifies the character set of the input files. + The `charset` option allows you to specify the character set encoding used for reading TypeScript source files. It is important to ensure that the specified character set matches the actual encoding of the source files to avoid potential parsing issues. + examples: ["utf-8"] + checkJs: + type: boolean + description: | + Enables type checking for JavaScript files. + By enabling the `checkJs` option, TypeScript will perform type checking on JavaScript files (`.js`). This can help catch type-related issues and provide better tooling support for JavaScript code within a TypeScript project. + examples: [true] + customConditions: + type: array + items: + type: string + description: | + Specifies custom conditions for conditional type inclusion. + Custom conditions are used in TypeScript's conditional types to control type inclusion based on specific conditions. This option allows you to specify custom conditions that can be used within your project's conditional types, providing flexibility in type checking and inference. + examples: ["A", "B"] + declaration: + type: boolean + description: | + Generates corresponding .d.ts files for the TypeScript project. + Enabling the `declaration` option instructs TypeScript to generate corresponding declaration files (`.d.ts`) alongside the emitted JavaScript files. Declaration files contain type information and enable better tooling support for using TypeScript code from other JavaScript projects. + examples: [true] + declarationMap: + type: boolean + description: | + Generates source maps for .d.ts files. + When the `declarationMap` option is enabled, TypeScript will generate source maps for the declaration files (`.d.ts`). Source maps provide a mapping between the emitted JavaScript files and their corresponding TypeScript source files, allowing for improved debugging and tooling support. + examples: [true] + emitDeclarationOnly: + type: boolean + description: | + Only emits .d.ts files and not the compiled JavaScript files. + When `emitDeclarationOnly` is enabled, TypeScript will only emit the declaration files (`.d.ts`) and skip emitting the compiled JavaScript files. This is useful when you only need the type information and don't require the compiled JavaScript output. + examples: [false] + declarationDir: + type: string + description: | + Specifies the output directory for .d.ts files. + The `declarationDir` option allows you to specify the output directory for the generated declaration files (`.d.ts`). By default, declaration files are emitted alongside the corresponding JavaScript files. Use this option to customize the output directory for the declaration files. + examples: ["./dist/types"] + disableSizeLimit: + type: boolean + description: | + Disables the size limit imposed on JavaScript projects. + By default, TypeScript imposes a size limit on JavaScript projects, and if the limit is exceeded, it raises an error. Enabling `disableSizeLimit` removes this size limit, allowing the compilation of larger JavaScript projects. However, it's important to ensure that the project's size is manageable and doesn't impact performance. + examples: [false] + disableSourceOfProjectReferenceRedirect: + type: boolean + description: | + Disables source file redirection in composite projects. + TypeScript's composite projects allow splitting a large project into smaller sub-projects for incremental compilation. By default, composite projects redirect source files to their composite project's output directory. Enabling this option disables the source file redirection, preserving the original source file paths during compilation. + examples: [false] + disableSolutionSearching: + type: boolean + description: | + Disables searching for solutions in sibling directories. + When resolving dependencies in a TypeScript project, TypeScript automatically searches for solution files (e.g., `tsconfig.json`) in the parent and sibling directories. Enabling `disableSolutionSearching` prevents TypeScript from searching for solutions in sibling directories, limiting the scope of project resolution. + examples: [false] + disableReferencedProjectLoad: + type: boolean + description: | + Disables loading referenced projects in TypeScript project references. + TypeScript project references allow dividing a project into separate projects that can reference each other. By default, TypeScript loads the referenced projects during compilation. Enabling `disableReferencedProjectLoad` disables the automatic loading of referenced projects, requiring manual management of project dependencies. + examples: [false] + downlevelIteration: + type: boolean + description: | + Enables iteration of ES6 generators for downlevel iteration. + ES6 generators introduce new iteration functionality. When targeting older ECMAScript versions, such as ES5, enabling `downlevelIteration` allows TypeScript to emit code that supports the iteration of ES6 generators in downlevel targets. This option is useful when targeting environments that don't natively support ES6 generators. + examples: [true] + emitBOM: + type: boolean + description: | + Specifies whether to emit a byte order mark (BOM) in emitted files. + The byte order mark (BOM) is a Unicode character that serves as an indicator for the encoding of a text file. By default, TypeScript emits files without a BOM. Enabling `emitBOM` instructs TypeScript to include the BOM character at the beginning of emitted files, which can be useful for compatibility with certain tools and environments. + examples: [false] + emitDecoratorMetadata: + type: boolean + description: | + Enables emitting decorator metadata in TypeScript compiled output. + Decorators are a TypeScript language feature used for adding metadata and modifying the behavior of classes, methods, properties, etc. Enabling `emitDecoratorMetadata` ensures that metadata associated with decorators is emitted in the compiled JavaScript output. This is required for certain frameworks or tools that rely on decorator metadata. + examples: [true] + exactOptionalPropertyTypes: + type: boolean + description: | + Enables strict checking of optional properties. + By default, TypeScript allows assigning `null` or `undefined` to optional properties regardless of their declared type. Enabling `exactOptionalPropertyTypes` enforces strict checking for optional properties, ensuring that their types must match exactly, including `null` or `undefined`. + examples: [true] + experimentalDecorators: + type: boolean + description: | + Enables experimental support for ES7 decorators. + Experimental decorators are a proposed feature of the ECMAScript standard (ES7) that TypeScript supports. Enabling `experimentalDecorators` allows you to use and experiment with decorators in your TypeScript code. It's important to note that experimental features may be subject to change or have limited compatibility. + examples: [true] + forceConsistentCasingInFileNames: + type: boolean + description: | + Forces consistent casing of referenced TypeScript files. + The `forceConsistentCasingInFileNames` option enforces consistent casing for references to TypeScript files. When enabled, TypeScript checks that references to files in the code match the exact casing of the file names on disk. This helps avoid potential issues when working on case-sensitive file systems. + examples: [true] + ignoreDeprecations: + type: string + description: | + Specifies deprecation warnings to be ignored. + TypeScript emits deprecation warnings when using deprecated features or APIs. The `ignoreDeprecations` option allows you to specify specific deprecation warnings to be ignored. Provide the deprecation warning message or code to suppress specific deprecation warnings during compilation. + examples: ["example-deprecation"] + importHelpers: + type: boolean + description: | + Enables the import of helper functions from tslib. + When working with certain language features or runtime helpers, TypeScript may emit additional helper functions to support the compilation output. Enabling `importHelpers` instructs TypeScript to import these helper functions from the `tslib` library instead of emitting them directly, resulting in smaller emitted JavaScript files. + examples: [true] + importsNotUsedAsValues: + $ref: "#/components/schemas/ImportsNotUsedAsValues" + inlineSourceMap: + type: boolean + description: | + Specifies whether to inline source maps in emitted JavaScript files. + Source maps provide a mapping between the emitted JavaScript files and their corresponding TypeScript source files, allowing for easier debugging. By default, TypeScript emits separate source map files. Enabling `inlineSourceMap` instructs TypeScript to include the source map content directly within the emitted JavaScript files, resulting in a single combined file. + examples: [false] + inlineSources: + type: boolean + description: | + Specifies whether to inline the original source code in emitted JavaScript files. + When working with source maps, TypeScript can include the original TypeScript source code within the emitted JavaScript files. Enabling `inlineSources` instructs TypeScript to include the original source code inline, making it accessible within the emitted JavaScript files. This can be useful for debugging purposes. + examples: [false] + isolatedModules: + type: boolean + description: | + Enables each file to be treated as a separate module. + By default, TypeScript treats all files within a project as part of the same module. Enabling `isolatedModules` instructs TypeScript to treat each file as a separate module, regardless of their dependencies or imports. This can be useful for projects where each file is independently executable or if you want to enforce strict module boundaries. + examples: [false] + jsx: + $ref: "#/components/schemas/JsxEmit" + keyofStringsOnly: + type: boolean + description: | + Disallows symbols other than string in keyof. + TypeScript's `keyof` operator allows you to obtain a union type representing the keys of a given object or type. By default, `keyof` includes all symbol types, including number and symbol keys. Enabling `keyofStringsOnly` restricts the keys to only string types, excluding number and symbol keys. + examples: [true] + lib: + type: array + items: + type: string + description: | + Specifies the libraries to be included in the TypeScript project. + TypeScript provides a set of pre-defined library files that include type definitions for common JavaScript APIs and runtime environments. The `lib` option allows you to specify the libraries to include in the TypeScript project. Available library options include `ES5`, `ES6`, `ES2015`, `DOM`, `DOM.Iterable`, `WebWorker`, and more. + examples: ["ES2018", "DOM"] + locale: + type: string + description: | + Specifies the locale to use for error messages. + The `locale` option allows you to specify the locale to use for error messages and diagnostics. This affects the language used in error messages, type checking output, and other compiler diagnostics. Specify the locale using the BCP 47 language tag format, such as `"en-us"` for English (United States). + examples: ["en-us"] + mapRoot: + type: string + description: | + Specifies the location where debugger should locate map files. + Source maps provide a mapping between the emitted JavaScript files and their corresponding TypeScript source files. The `mapRoot` option allows you to specify the location where the debugger should look for the source map files. Use this option when the source maps are hosted at a different location than the emitted JavaScript files. + examples: ["./maps"] + maxNodeModuleJsDepth: + type: number + description: | + Specifies the maximum folder depth for checking JavaScript files in node_modules. + When resolving JavaScript files in the `node_modules` directory, TypeScript may encounter deeply nested files. The `maxNodeModuleJsDepth` option allows you to limit the folder depth TypeScript checks when looking for JavaScript files. Setting a value of `0` restricts the search to the top-level folder only. + examples: [0] + module: + $ref: "#/components/schemas/ModuleKind" + moduleResolution: + $ref: "#/components/schemas/ModuleResolutionKind" + moduleSuffixes: + type: array + items: + type: string + description: | + Specifies the file suffixes to consider during module resolution. + When resolving module imports, TypeScript considers files with specific suffixes. The `moduleSuffixes` option allows you to specify the file suffixes to consider during module resolution. By default, TypeScript considers files with `.ts`, `.tsx`, and `.js` extensions. Customize this option to include additional or different file suffixes as needed. + examples: [".ts", ".tsx", ".js"] + moduleDetection: + $ref: "#/components/schemas/ModuleDetectionKind" + newLine: + $ref: "#/components/schemas/NewLineKind" + noEmit: + type: boolean + description: | + Disables emitting JavaScript files. + Enabling the `noEmit` option instructs TypeScript not to emit any JavaScript files as output. This is useful when you only want to perform type checking and validation without generating compiled JavaScript files. Use this option during development or when TypeScript is used solely for static type checking. + examples: [false] + noEmitHelpers: + type: boolean + description: | + Disables generating custom helper functions in emitted JavaScript files. + When targeting certain ECMAScript versions or using certain language features, TypeScript may emit additional helper functions to support the compiled JavaScript output. Enabling `noEmitHelpers` disables the generation of these custom helper functions, resulting in smaller emitted JavaScript files. + examples: [false] + + noEmitOnError: + type: boolean + description: | + Disables emitting JavaScript files if any type errors are reported. + By default, TypeScript emits JavaScript files even if there are type errors in the project. Enabling `noEmitOnError` instructs TypeScript to prevent emitting any JavaScript files if there are any reported type errors. This ensures that only error-free code is compiled and emitted. + examples: [true] + noErrorTruncation: + type: boolean + description: | + Disables truncating error messages. + Error messages generated by TypeScript are often truncated to fit within a certain length limit. Enabling `noErrorTruncation` disables this truncation, allowing the full error messages to be displayed. This can be useful for detailed error analysis, but keep in mind that very long error messages may be harder to read. + examples: [false] + noFallthroughCasesInSwitch: + type: boolean + description: | + Disallows fallthrough cases in switch statements. + TypeScript performs analysis on switch statements to detect fallthrough cases where one case does not include a `break` statement and execution continues into the next case. Enabling `noFallthroughCasesInSwitch` flags such cases as errors, ensuring that switch statements are handled correctly and explicitly in the code. + examples: [true] + noImplicitAny: + type: boolean + description: | + Disallows implicit `any` type declarations. + By default, TypeScript allows implicit `any` types, where a variable or expression's type is automatically inferred as `any` when it is not explicitly annotated. Enabling `noImplicitAny` flags such cases as errors, requiring explicit type annotations to avoid relying on implicit `any` types. + examples: [true] + noImplicitReturns: + type: boolean + description: | + Disallows missing return types on function signatures. + TypeScript checks for missing return types on function signatures and flags them as errors. Enabling `noImplicitReturns` ensures that all code paths within a function have a return statement or throw an error, avoiding potential logic errors or unintended control flow. + examples: [true] + noImplicitThis: + type: boolean + description: | + Disallows the use of `this` types without an explicit type annotation. + In TypeScript, the `this` type is used to represent the type of the current object within a class or method. By default, TypeScript allows the use of `this` without an explicit type annotation. Enabling `noImplicitThis` flags such cases as errors, requiring explicit type annotations for `this` usage. + examples: [true] + noStrictGenericChecks: + type: boolean + description: | + Disables strict checking of generic signatures in TypeScript projects. + Generics in TypeScript allow creating reusable functions or classes that can work with multiple types. Enabling `noStrictGenericChecks` relaxes the strict checking of generic signatures, allowing looser type inference and compatibility. However, it's important to note that stricter generic checks help ensure type safety and correctness. + examples: [false] + noUnusedLocals: + type: boolean + description: | + Disallows unused local variables. + Unused local variables are variables declared within a function or block scope that are never referenced or used. Enabling `noUnusedLocals` flags such cases as errors, helping to identify and remove unused variables, which can improve code readability and maintainability. + examples: [true] + noUnusedParameters: + type: boolean + description: | + Disallows unused function parameters. + Unused function parameters are parameters declared in function signatures that are never used or referenced within the function body. Enabling `noUnusedParameters` flags such cases as errors, encouraging the removal of unused parameters to improve code clarity and eliminate potential confusion. + examples: [true] + noImplicitUseStrict: + type: boolean + description: | + Disallows the use of implicit `use strict` directive. + The `use strict` directive enables strict mode in JavaScript, which enforces stricter rules and eliminates certain language pitfalls. By default, TypeScript automatically adds the `use strict` directive to the emitted JavaScript files. Enabling `noImplicitUseStrict` disables the implicit insertion of `use strict`, allowing you to manually control its usage. + examples: [true] + noPropertyAccessFromIndexSignature: + type: boolean + description: | + Disallows accessing properties using the index signature notation. + In TypeScript, objects can be accessed using property access notation (`obj.prop`) or index signature notation (`obj['prop']`). By default, TypeScript allows accessing properties using both notations. Enabling `noPropertyAccessFromIndexSignature` flags property access using index signature notation as errors, promoting consistent property access syntax. + examples: [false] + assumeChangesOnlyAffectDirectDependencies: + type: boolean + description: | + Instructs TypeScript to assume that changes only affect direct dependencies. + The `assumeChangesOnlyAffectDirectDependencies` option is used in TypeScript's incremental compilation feature. When enabled, TypeScript assumes that changes made in the project only affect the directly dependent files, allowing for faster incremental builds. This option should be used with caution, as it may lead to incorrect compilation results if dependencies are not accurately tracked. + examples: [true] + noLib: + type: boolean + description: | + Disables including the default library file (lib.d.ts). + By default, TypeScript includes the default library file (`lib.d.ts`) that provides type definitions for common JavaScript APIs and runtime environments. Enabling `noLib` instructs TypeScript not to include the default library file. This can be useful in specific scenarios where you want to provide your own custom library definitions. + examples: [false] + noResolve: + type: boolean + description: | + Disables automatic resolution of non-relative module names. + TypeScript automatically resolves non-relative module names by searching for matching modules in various locations, such as `node_modules`. Enabling `noResolve` disables this automatic resolution, requiring all module names to be explicitly specified with a relative or absolute path. Use this option when you want full control over module resolution. + examples: [false] + noUncheckedIndexedAccess: + type: boolean + description: | + Disallows unchecked indexed access on possibly undefined values. + By default, TypeScript allows indexing into possibly undefined values without checking for null or undefined. Enabling `noUncheckedIndexedAccess` flags such cases as errors, requiring explicit null or undefined checks before indexing into objects or arrays. This promotes safer coding practices and avoids potential runtime errors. + examples: [true] + out: + type: string + description: | + Specifies the single output file for the TypeScript project. + The `out` option allows you to specify a single output file for the TypeScript project. When specified, TypeScript will concatenate and emit all compiled JavaScript files into the specified output file. Note that using `out` disables incremental compilation and should be used with caution for larger projects. + examples: ["./dist/bundle.js"] + outDir: + type: string + description: | + Specifies the output directory for emitted JavaScript files. + The `outDir` option specifies the directory where TypeScript should emit the compiled JavaScript files. All emitted JavaScript files, including declaration files and source maps, will be placed in this directory. Use this option to control the location of the output files within your project's directory structure. + examples: ["./dist"] + outFile: + type: string + description: | + Specifies the single output file for the TypeScript project (alternative to `out`). + The `outFile` option is an alternative to the `out` option for specifying a single output file for the TypeScript project. It functions in a similar way as `out`, but allows you to specify the output file directly within the `tsconfig.json` file. Note that using `outFile` disables incremental compilation and should be used with caution for larger projects. + examples: ["./dist/bundle.js"] + paths: + type: object + additionalProperties: + type: array + items: + type: string + description: | + Specifies path mappings for module resolution. + The `paths` option allows you to specify path mappings for module resolution. This is particularly useful when working with module aliases or custom directory structures. Specify the module name or alias as the key and the corresponding path or pattern as the value in the `paths` object. + examples: + - + "@utils/*": ["./src/utils/*"] + "@components/*": ["./src/components/*"] + preserveConstEnums: + type: boolean + description: | + Preserves const enums in the emitted JavaScript output. + Const enums in TypeScript are enums that are fully inlined during compilation, resulting in more efficient JavaScript output. By default, TypeScript removes const enums during compilation to reduce the emitted code size. Enabling `preserveConstEnums` instructs TypeScript to preserve const enums in the emitted JavaScript output. + examples: [true] + noImplicitOverride: + type: boolean + description: | + Disallows explicit overriding of methods or properties. + TypeScript allows explicit method or property overrides, where a derived class explicitly overrides a method or property from its base class. Enabling `noImplicitOverride` flags explicit overrides as errors, ensuring that methods or properties are properly overridden using the `override` keyword. + examples: [true] + preserveSymlinks: + type: boolean + description: | + Preserves symbolic links when resolving modules. + By default, TypeScript follows symbolic links when resolving modules. Enabling `preserveSymlinks` instructs TypeScript to preserve symbolic links during module resolution. Use this option when you want TypeScript to treat symbolic links as separate entities and not follow them to their target locations. + examples: [false] + preserveValueImports: + type: boolean + description: | + Preserves unused values imported solely for their types. + When importing modules in TypeScript, it is common to import certain values solely for their types, without actually using the imported values in the code. Enabling `preserveValueImports` ensures that these unused values are preserved during compilation, allowing TypeScript to retain their type information for better type checking and tooling support. + examples: [true] + project: + type: string + description: | + Specifies the path or file glob patterns for the TypeScript project. + The `project` option specifies the path or file glob patterns for the TypeScript project configuration. It can be a path to a specific `tsconfig.json` file or a glob pattern matching multiple configuration files. When this option is provided, TypeScript will use the specified project configuration for compilation and other operations. + examples: ["./tsconfig.json"] + reactNamespace: + type: string + description: | + Specifies the namespace for JSX factory and JSX fragment. + When working with JSX in TypeScript, the `reactNamespace` option allows you to specify the namespace for the JSX factory and JSX fragment. By default, TypeScript uses `React` as the namespace. Use this option to customize the namespace based on your specific JSX implementation or library. + examples: ["React"] + jsxFactory: + type: string + description: | + Specifies the function to use as the JSX factory. + The `jsxFactory` option specifies the function to use as the JSX factory. In JSX syntax, elements are transpiled into function calls, and the `jsxFactory` option determines the function to be used for creating these elements. Specify the function name or expression as the value of `jsxFactory`. + examples: ["h"] + jsxFragmentFactory: + type: string + description: | + Specifies the function to use as the JSX fragment factory. + JSX fragments allow grouping multiple adjacent JSX elements without an enclosing wrapper element. The `jsxFragmentFactory` option specifies the function to use as the JSX fragment factory. Specify the function name or expression as the value of `jsxFragmentFactory`. This option is applicable when using JSX syntax. + examples: ["Fragment"] + jsxImportSource: + type: string + description: | + Specifies the module to import JSX-related functions from. + When using JSX syntax, TypeScript needs to import certain functions, such as the JSX factory or JSX fragment factory. The `jsxImportSource` option allows you to specify the module from which these JSX-related functions should be imported. Specify the module name or path as the value of `jsxImportSource`. + examples: ["preact"] + composite: + type: boolean + description: | + Enables building TypeScript projects in composite mode. + TypeScript's composite mode allows dividing a large project into separate sub-projects that can be built independently and incrementally. Enabling `composite` mode enables the use of project references and incremental compilation for faster builds. Use this option when working with complex or large-scale TypeScript projects. + examples: [true] + incremental: + type: boolean + description: | + Enables incremental compilation for TypeScript projects. + Incremental compilation is a feature of TypeScript that allows recompiling only the necessary files when changes are made, resulting in faster builds. Enabling `incremental` mode enables the incremental compilation feature for the TypeScript project. This option is recommended for projects where build speed is a priority. + examples: [true] + tsBuildInfoFile: + type: string + description: | + Specifies the file to store incremental build information. + Incremental compilation in TypeScript relies on storing build information for efficient recompilation. The `tsBuildInfoFile` option specifies the file where the incremental build information should be stored. This information is used to determine which files need to be recompiled when changes are made. + examples: ["./tsconfig.tsbuildinfo"] + removeComments: + type: boolean + description: | + Removes comments from the emitted JavaScript files. + By default, TypeScript preserves comments from the source code in the emitted JavaScript files. Enabling `removeComments` instructs TypeScript to remove all comments during the compilation process, resulting in cleaner and more concise JavaScript output. + examples: [true] + resolvePackageJsonExports: + type: boolean + description: | + Enables resolving package.json exports field. + Starting from ECMAScript modules (ESM) support in Node.js 12, the `exports` field in `package.json` files is used to define the exports of a module. Enabling `resolvePackageJsonExports` allows TypeScript to resolve module imports using the `exports` field in `package.json` files. Use this option when working with ESM and package exports. + examples: [true] + resolvePackageJsonImports: + type: boolean + description: | + Enables resolving imports from `package.json` files. + TypeScript can resolve module imports directly from `package.json` files, bypassing the need for separate type declaration files (`*.d.ts`). Enabling `resolvePackageJsonImports` allows TypeScript to resolve imports using the `main` or `module` field in `package.json` files. This can simplify the import configuration for certain packages. + examples: [true] + rootDir: + type: string + description: | + Specifies the root directory of input files. + The `rootDir` option specifies the root directory of input files in the TypeScript project. It is used to determine the relative path of each file within the project. This option is especially useful when working with projects that have a complex file structure or when using tools that rely on the project's root directory. + examples: ["./src"] + rootDirs: + type: array + items: + type: string + description: | + Specifies multiple root directories for the TypeScript project. + The `rootDirs` option allows you to specify multiple root directories for the TypeScript project. When specified, TypeScript will consider all files within the specified root directories as part of the project. This can be useful when working with projects that span multiple directories or when using tools that require multiple root directories. + examples: ["./src", "./tests"] + skipLibCheck: + type: boolean + description: | + Skips type checking of declaration files in `node_modules`. + By default, TypeScript performs type checking on declaration files (`*.d.ts`) in the `node_modules` directory. Enabling `skipLibCheck` skips the type checking of declaration files, which can significantly improve build performance, especially for large projects with many dependencies. + examples: [true] + + skipDefaultLibCheck: + type: boolean + description: | + Skips type checking of default library file (lib.d.ts). + The default library file (`lib.d.ts`) provides type definitions for common JavaScript APIs and runtime environments. Enabling `skipDefaultLibCheck` skips the type checking of the default library file. Use this option when you want to exclude the default library from type checking or when using alternative library files. + examples: [true] + sourceMap: + type: boolean + description: | + Specifies whether to generate source map files. + Source maps provide a mapping between the emitted JavaScript files and their corresponding TypeScript source files, allowing for easier debugging. Enabling `sourceMap` instructs TypeScript to generate source map files along with the emitted JavaScript files. These source map files can be used by debuggers and other tools for source-level debugging. + examples: [true] + sourceRoot: + type: string + description: | + Specifies the location of the TypeScript source files. + The `sourceRoot` option specifies the location of the TypeScript source files relative to the emitted JavaScript files. This option is used in the source maps to provide the correct path information for the TypeScript sources. It is especially useful when the TypeScript sources are located in a different directory from the emitted JavaScript files. + examples: ["./src"] + strict: + type: boolean + description: | + Enables strict type checking options. + The `strict` option enables a set of strict type checking options in TypeScript. Enabling `strict` is equivalent to enabling several individual strict options, including `strictNullChecks`, `strictFunctionTypes`, `strictBindCallApply`, `strictPropertyInitialization`, `noImplicitThis`, and more. Use this option to enforce strict type checking rules in your project. + examples: [true] + strictFunctionTypes: + type: boolean + description: | + Enables strict checking of function types. + Function types in TypeScript include parameters and return types. By default, TypeScript allows for certain assignment compatibility between function types. Enabling `strictFunctionTypes` flags stricter checking of function types, ensuring that parameter types and return types must match exactly. + examples: [true] + strictBindCallApply: + type: boolean + description: | + Enables strict checking of `bind`, `call`, and `apply` methods. + The `bind`, `call`, and `apply` methods in JavaScript allow for dynamic binding of functions and altering their execution context. Enabling `strictBindCallApply` enables strict checking of these methods, ensuring that the number of arguments and the types of arguments passed to these methods match the function's signature. + examples: [true] + strictNullChecks: + type: boolean + description: | + Enables strict null checking. + Null and undefined are often sources of bugs in JavaScript. Enabling `strictNullChecks` enables strict checking for null and undefined values, preventing variables from being assigned null or undefined unless explicitly allowed. This option helps eliminate many common null-related errors. + examples: [true] + strictPropertyInitialization: + type: boolean + description: | + Enables strict checking of uninitialized class properties. + Class properties in TypeScript can be initialized during declaration or within the constructor. Enabling `strictPropertyInitialization` flags uninitialized class properties as errors, ensuring that all class properties are explicitly initialized either during declaration or within the constructor. + examples: [true] + stripInternal: + type: boolean + description: | + Removes internal declaration files from the emitted JavaScript files. + TypeScript includes internal declaration files that provide type information for the TypeScript language and compiler. Enabling `stripInternal` instructs TypeScript to remove these internal declaration files from the emitted JavaScript files. This can help reduce the size of the emitted JavaScript files, especially in production builds. + examples: [true] + suppressExcessPropertyErrors: + type: boolean + description: | + Suppresses excess property errors when assigning object literals. + When assigning object literals to variables or parameters, TypeScript performs excess property checking to ensure that only known properties are assigned. Enabling `suppressExcessPropertyErrors` suppresses the excess property errors, allowing object literals to be assigned to variables or parameters without strict property checking. + examples: [true] + suppressImplicitAnyIndexErrors: + type: boolean + description: | + Suppresses implicit `any` errors for indexing objects. + TypeScript performs implicit `any` checks when indexing into objects with arbitrary property names. Enabling `suppressImplicitAnyIndexErrors` suppresses the implicit `any` errors, allowing indexing into objects without strict type checking. Use this option when you need to work with objects that have dynamic or unknown property names. + examples: [true] + target: + $ref: "#/components/schemas/ScriptTarget" + traceResolution: + type: boolean + description: | + Outputs detailed trace logs for module resolution. + Enabling `traceResolution` outputs detailed trace logs during module resolution in TypeScript. These logs provide information about how TypeScript resolves module imports, including the paths searched, module resolutions, and more. Use this option for debugging or diagnosing module resolution issues in your project. + examples: [true] + useUnknownInCatchVariables: + type: boolean + description: | + Enables `unknown` type for catch clause variables. + The `unknown` type in TypeScript represents values that are of an unknown type. Enabling `useUnknownInCatchVariables` allows catch clause variables to be typed as `unknown`, allowing more flexible handling of unknown error values in catch blocks. + examples: [true] + resolveJsonModule: + type: boolean + description: | + Enables importing JSON files as modules. + Starting from ECMAScript modules (ESM) support in Node.js 10, JSON files can be imported as modules. Enabling `resolveJsonModule` allows TypeScript to import JSON files as modules, providing type checking and autocompletion for the imported JSON data. + examples: [true] + types: + type: array + items: + type: string + description: | + Specifies the type declaration files to include. + Type declaration files (`.d.ts`) provide type information for JavaScript libraries and modules. The `types` option allows you to specify the type declaration files to include in the TypeScript project. Specify the names of the desired type declaration files or packages as elements of the `types` array. + examples: ["node", "jest"] + typeRoots: + type: array + items: + type: string + description: | + Specifies the locations to search for type declaration files. + The `typeRoots` option specifies the locations to search for type declaration files (`.d.ts`). TypeScript searches these directories to find type declarations for installed packages and custom type definitions. Use this option to include additional directories containing type declaration files in your project. + examples: ["./typings", "./custom-types"] + verbatimModuleSyntax: + type: boolean + description: | + Enables verbatim module syntax for CommonJS modules. + CommonJS modules in TypeScript are transpiled into the CommonJS module format. Enabling `verbatimModuleSyntax` allows the emitted JavaScript output to use verbatim module syntax, preserving the original module import and export statements. This can be useful when interoperating with other tools or libraries that rely on the original CommonJS syntax. + examples: [true] + esModuleInterop: + type: boolean + description: | + Enables interoperability between CommonJS and ECMAScript modules. + The `esModuleInterop` option enables interoperability between CommonJS modules and ECMAScript modules (ESM). When enabled, TypeScript generates code that allows importing ESM modules into CommonJS modules and vice versa, without the need for additional interop libraries or syntax transformations. + examples: [true] + useDefineForClassFields: + type: boolean + description: | + Uses the `defineProperty` method for class fields initialization. + When initializing class fields in TypeScript, the default behavior is to assign the values directly to the instance. Enabling `useDefineForClassFields` uses the `defineProperty` method for initializing class fields. This can provide more fine-grained control over the initialization process and ensure consistency with the property accessors. + examples: [true] + + + ImportsNotUsedAsValues: + type: string + enum: [remove, error, preserve] + description: | + Specifies how imports that are not used as values are handled. + Imports that are not used as values refer to imports that are solely used for their type information or for side effects (e.g., polyfills or registering decorators). The `importsNotUsedAsValues` option allows you to configure how these imports are handled. The possible values are: + - `remove`: Removes unused imports that are not used as values. + - `error`: Raises an error for unused imports that are not used as values. + - `preserve`: Preserves all imports, even if they are not used as values. + examples: ["remove"] + + JsxEmit: + type: string + enum: [react, react-jsx, react-jsxdev, preserve, react-native] + description: | + Specifies the JSX output mode. + JSX is a syntax extension for JavaScript that allows embedding XML-like syntax within JavaScript code. The `jsx` option specifies the desired JSX output mode for the TypeScript project. Available options are: + - `react`: Emit JSX code compatible with React. + - `react-jsx`: Emit JSX code with a ".jsx" file extension. + - `react-jsxdev`: Emit JSX code with a ".js" file extension (development mode). + - `preserve`: Preserve JSX code as part of the emitted JavaScript. + - `react-native`: Emit JSX code compatible with React Native. + examples: ["react"] + + ModuleKind: + type: string + enum: [none, commonjs, amd, system, umd, es2015, es2020, es2021, es2022, es2023, esnext] + description: | + Specifies the module code generation method. + The `module` option specifies the module code generation method for the emitted JavaScript output. Different module formats are suitable for different runtime environments. Available options are: `none`, `commonjs`, `amd`, `system`, `umd`, `es2015`, `es2020`, `esnext`, and more. Choose the appropriate option based on your target environment and module loading system. + examples: ["commonjs"] + + ModuleResolutionKind: + type: string + enum: [classic, node, node12, node16, nodenext, bundler] + description: | + Specifies the module resolution strategy. + The `moduleResolution` option determines how TypeScript resolves module imports. Different module resolution strategies are suitable for different project structures and module loading systems. Available options are: `classic`, `node`, `node12`, and more. Choose the appropriate option based on your project's configuration and module resolution requirements. + examples: ["node"] + + ModuleDetectionKind: + type: string + enum: [node, node12, node16, nodenext, bundler, modern, classic] + description: | + Specifies how modules are detected. + The `moduleDetection` option determines how TypeScript detects and resolves modules. Different module detection methods have different behavior and compatibility. Available options are: `node`, `node12`, `modern`, `classic`, and more. Choose the appropriate option based on your project's configuration and module detection requirements. + examples: ["node"] + + NewLineKind: + type: string + enum: [crlf, lf] + description: | + Specifies the end of line sequence to be used. + The `newLine` option specifies the desired end-of-line (EOL) sequence to be used in the emitted JavaScript output. Available options are: `crlf` (carriage return + line feed) and `lf` (line feed). The chosen EOL sequence affects how lines are terminated in the emitted files. + examples: ["crlf"] + + ScriptTarget: + type: string + enum: [es3, es5, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext] + description: | + Specifies the ECMAScript target version for emitted JavaScript files. + The `target` option specifies the ECMAScript (ES) target version for the emitted JavaScript output. TypeScript provides support for different ECMAScript versions, such as `ES5`, `ES2015`, `ES2016`, `ES2017`, `ES2018`, `ES2019`, `ES2020`, `ESNext`, and more. Choose the appropriate target version based on your project's compatibility requirements. + examples: ["es2020"] + + \ No newline at end of file diff --git a/.well-known/openapi.yaml b/.well-known/openapi.yaml index 7f061c9..0cfba9d 100644 --- a/.well-known/openapi.yaml +++ b/.well-known/openapi.yaml @@ -49,7 +49,7 @@ paths: schema: $ref: '#/components/schemas/TwoslashError' get: - operationId: getTypescriptTwoslash + operationId: getToTypescriptTwoslash summary: Run TypeScript Twoslash on a given code description: | This endpoint accepts TwoSlashOptions as JSON/FormData and returns TwoSlashReturn JSON. @@ -59,34 +59,29 @@ paths: - name: options in: query required: true - content: - application/json: - schema: - $ref: '#/components/schemas/TwoSlashOptions' + schema: + type: object + $ref: '#/components/schemas/TwoSlashOptions' - name: option in: query - content: - application/json: - schema: - $ref: '#/components/schemas/TwoSlashOptions' + schema: + type: object + $ref: '#/components/schemas/TwoSlashOptions' - name: code in: query - content: - text/plain: - schema: - $ref: '#/components/schemas/TwoSlashOptions/properties/code' + schema: + type: string + $ref: "#/components/schemas/Code" - name: extension in: query - content: - text/plain: - schema: - $ref: '#/components/schemas/TwoSlashOptions/properties/extension' + schema: + type: string + $ref: "#/components/schemas/Extension" - name: ext in: query - content: - text/plain: - schema: - $ref: '#/components/schemas/TwoSlashOptions/properties/extension' + schema: + type: string + $ref: "#/components/schemas/Extension" responses: '200': description: Successful operation @@ -102,144 +97,148 @@ paths: $ref: '#/components/schemas/TwoslashError' components: schemas: + Code: + type: string + description: | + The TypeScript, JavaScript, TSX, or JSX code to run twoslash over. Twoslash comments can be used for various features like: + - Compiler flag comments: `// @noImplicitAny: false`, `// @target: ES2015`, etc. + - Error comments: `// @noErrors`, `// @errors` Lint the code for syntax errors and best practices. + - Emitted file comments: `// @showEmit`, `// @showEmittedFile: index.d.ts` + - Static semantic info comments: `// @noStaticSemanticInfo` + - Emit comments: `// @emit` + - Error validation comments: `// @noErrorValidation` + - Filename comments: `// @filename` + - Script Target comments: `// @target` + - Declaration comments: `// @declaration: true` + - Cut comments: `// ---cut---` to cut out unnecessary code before the comment. `// ---cut-after---` to cut out unnecessary code after the comment. + - Type queries: `// ^?` to query types of variables, objects, functions, arrays, maps, symbols, parameters and/or values. Check type information for the line of code above the comment. + - Auto-Completions: `// ^|` Auto-complete code suggestions. + - Highlighting: `// ^^^ Description` for highlighting the section of code above the comment. Remember to add a space after the `^^^` to avoid syntax errors. + - Import files: `// @filename: import_files.ts` for importing files + - Full Compile Options List: + - `// @module: esnext`, `// @jsx: preserve`, `// @lib: esnext`, `// @strict: true`, `// @noImplicitAny: false`, `// @target: ES2022`, `// @declaration: true`, + - `// @noUnusedLocals: true`, `// @noUnusedParameters: true`, `// @noImplicitReturns: true`, `// @noFallthroughCasesInSwitch: true`, `// @allowUnreachableCode: false`, + - `// @allowUnusedLabels: false`, `// @noImplicitOverride: true`, `// @exactOptionalPropertyTypes: true`, `// @noPropertyAccessFromIndexSignature: true`, + - `// @noUncheckedIndexedAccess: true`, `// @noImplicitThis: true`, `// @strictBindCallApply: true`, `// @strictFunctionTypes: true`, `// @strictNullChecks: true`, + - `// @strictPropertyInitialization: true`, `// @useUnknownInCatchVariables: true`, `// @allowArbitraryExtensions: true`, `// @allowImportingTsExtensions: true`, + - `// @alwaysStrict: true`, `// @noEmit: true`, `// @noEmitOnError: true`, `// @preserveConstEnums: true`, `// @removeComments: true`, `// @skipLibCheck: true`, + - `// @sourceMap: true`, `// @inlineSourceMap: true`, `// @inlineSources: true`, `// @emitDeclarationOnly: true`, `// @declarationMap: true`, `// @declarationDir: ./`, + - `// @listEmittedFiles: true`, `// @listFiles: true`, `// @pretty: true`, `// @downlevelIteration: true`, `// @isolatedModules: true`, `// @importHelpers: true`, + - `// @experimentalDecorators: true`, `// @emitDecoratorMetadata: true`, `// @importsNotUsedAsValues: true`, `// @noEmitHelpers: true`, `// @noImplicitUseStrict: true`, + - `// @noLib: true`, `// @noResolve: true`, `// @noStrictGenericChecks: true`, `// @noUncheckedIndexedAccess: true`, `// @noUnusedLocals: true`, `// @noUnusedParameters: true`, + - `// @strictBindCallApply: true`, `// @strictFunctionTypes: true`, `// @strictNullChecks: true`, `// @strictPropertyInitialization: true`, `// @useUnknownInCatchVariables: true`, + - `// @allowJs: true`, `// @checkJs: true`, `// @jsx: preserve`, `// @jsxFactory: React`, `// @jsxFragmentFactory: React`, `// @jsxImportSource: React`, + - `// @allowUnreachableCode`: Do not report errors on unreachable code. + - `// @allowUnusedLabels`: Do not report errors on unused labels. + - `// @alwaysStrict`: Parse in strict mode and emit "use strict" for each source file. + - `// @exactOptionalPropertyTypes`: Differentiate between optional property and undefined property in the type system. + - `// @noFallthroughCasesInSwitch`: Report errors for fallthrough cases in switch statements. + - `// @noImplicitAny`: Raise error on expressions and declarations with an implied 'any' type. + - `// @noImplicitOverride`: Ensure overriding members in derived classes are marked with an 'override' modifier. + - `// @noImplicitReturns`: Report error when not all code paths in function return a value. + - `// @noImplicitThis`: Raise error on 'this' expressions with an implied 'any' type. + - `// @noPropertyAccessFromIndexSignature`: Require undeclared properties from index signatures to be accessed with an index. + - `// @noUncheckedIndexedAccess`: Add a 'undefined' type to elements accessed via an index signature. + - `// @noUnusedLocals`: Report errors on unused locals. + - `// @noUnusedParameters`: Report errors on unused parameters. + - `// @strict`: Enable all strict type checking options. + - `// @strictBindCallApply`: Enable stricter checking of bind, call, and apply. + - `// @strictFunctionTypes`: Enable stricter checking of function types. + - `// @strictNullChecks`: Enable strict null checks. + - `// @strictPropertyInitialization`: Enable strict checking of property initialization. + - `// @useUnknownInCatchVariables`: Type catch clause variables as 'unknown' instead of 'any'. + - `// @allowArbitraryExtensions`: Allow arbitrary file extensions to be included in the program. + - `// @allowImportingTsExtensions`: Allow '.ts' and '.tsx' extensions to be imported. + - `// @allowUmdGlobalAccess`: Allow accessing UMD globals from modules. + - `// @baseUrl`: Base directory to resolve non-relative module names. + - `// @customConditions`: List of custom conditions to apply to module resolution. + - `// @module`: Specify module code generation. + - `// @moduleResolution`: Specify module resolution strategy. + - `// @moduleSuffixes`: List of file extensions to consider when resolving modules. + - `// @noResolve`: Do not add triple-slash references or module import targets to the list of compiled files. + - `// @paths`: A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. + - `// @resolveJsonModule`: Include modules imported with '.json' extension. + - `// @resolvePackageJsonExports`: Resolve the 'exports' field in 'package.json'. + - `// @resolvePackageJsonImports`: Resolve the 'imports' field in 'package.json'. + - `// @rootDir`: Specifies the root directory of input files. + - `// @rootDirs`: List of root folders whose combined content represents the structure of the project at runtime. + - `// @typeRoots`: List of folders to include type definitions from. + - `// @types`: Type declaration files to be included in compilation. + - `// @declaration`: Generates corresponding '.d.ts' file. + - `// @declarationDir`: Output directory for generated declaration files. + - `// @declarationMap`: Generates a sourcemap for each corresponding '.d.ts' file. + - `// @downlevelIteration`: Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. + - `// @emitBOM`: Specifies whether to emit a byte order mark (BOM) in emitted files. The byte order mark (BOM) is a Unicode character that serves as an indicator for the encoding of a text file. By default, TypeScript emits files without a BOM. Enabling `emitBOM` instructs TypeScript to include the BOM character at the beginning of emitted files, which can be useful for compatibility with certain tools and environments. + examples: + - | + // @module: esnext + // @target: ES2022 + // @errors: 1003 2304 7006 2339 + // @declaration: true + // @emit + // @filename: maths.ts + /** + * Gets the length of a string + * @param value a string + */ + function fnx2(s: string) { + console.log(s.substr(3)) + } + export function absolute(num: number) { + if (num < 0) return num * -1; + return num; + } + + import {SpringEasing} from "spring-easing" + SpringEasing + // ^? + + /** + * Gets the length of a string + * @param value a string + */ + function fnx(s: string) { + console.log(s.substr(3)) + } + + export const slash = [] as string[] + fnx("42") + //^? + // ^^^^^ + + function greet(person: string, date: Date) { + console.log(\`Hello \${person}, today is \${date.toDateString()}!\`) + } + + greet("Maddison", new Date()) + // ^^^^^ A Quick explanation + console.g + // ^| + + // @filename: index.ts + import {absolute} from "./maths" + const value = absolute(-1) + // ^? + // ^^^^^^^^^^ + const value2 = absolute(-2) + // ^? + // ^^^^^^^^ + + function fn(s) { + console.log(s.substr(3)) + } + Extension: + type: string + description: The extension of the code file. Can be 'typescript', 'javascript', 'json', 'jsn', 'ts', 'js', 'tsx', or 'jsx'. + examples: + - "ts" TwoSlashOptions: type: object properties: code: - type: string - description: | - The TypeScript, JavaScript, TSX, or JSX code to run twoslash over. Twoslash comments can be used for various features like: - - Compiler flag comments: `// @noImplicitAny: false`, `// @target: ES2015`, etc. - - Error comments: `// @noErrors`, `// @errors` Lint the code for syntax errors and best practices. - - Emitted file comments: `// @showEmit`, `// @showEmittedFile: index.d.ts` - - Static semantic info comments: `// @noStaticSemanticInfo` - - Emit comments: `// @emit` - - Error validation comments: `// @noErrorValidation` - - Filename comments: `// @filename` - - Script Target comments: `// @target` - - Declaration comments: `// @declaration: true` - - Cut comments: `// ---cut---` to cut out unnecessary code before the comment. `// ---cut-after---` to cut out unnecessary code after the comment. - - Type queries: `// ^?` to query types of variables, objects, functions, arrays, maps, symbols, parameters and/or values. Check type information for the line of code above the comment. - - Auto-Completions: `// ^|` Auto-complete code suggestions. - - Highlighting: `// ^^^ Description` for highlighting the section of code above the comment. Remember to add a space after the `^^^` to avoid syntax errors. - - Import files: `// @filename: import_files.ts` for importing files - - Full Compile Options List: - - `// @module: esnext`, `// @jsx: preserve`, `// @lib: esnext`, `// @strict: true`, `// @noImplicitAny: false`, `// @target: ES2022`, `// @declaration: true`, - - `// @noUnusedLocals: true`, `// @noUnusedParameters: true`, `// @noImplicitReturns: true`, `// @noFallthroughCasesInSwitch: true`, `// @allowUnreachableCode: false`, - - `// @allowUnusedLabels: false`, `// @noImplicitOverride: true`, `// @exactOptionalPropertyTypes: true`, `// @noPropertyAccessFromIndexSignature: true`, - - `// @noUncheckedIndexedAccess: true`, `// @noImplicitThis: true`, `// @strictBindCallApply: true`, `// @strictFunctionTypes: true`, `// @strictNullChecks: true`, - - `// @strictPropertyInitialization: true`, `// @useUnknownInCatchVariables: true`, `// @allowArbitraryExtensions: true`, `// @allowImportingTsExtensions: true`, - - `// @alwaysStrict: true`, `// @noEmit: true`, `// @noEmitOnError: true`, `// @preserveConstEnums: true`, `// @removeComments: true`, `// @skipLibCheck: true`, - - `// @sourceMap: true`, `// @inlineSourceMap: true`, `// @inlineSources: true`, `// @emitDeclarationOnly: true`, `// @declarationMap: true`, `// @declarationDir: ./`, - - `// @listEmittedFiles: true`, `// @listFiles: true`, `// @pretty: true`, `// @downlevelIteration: true`, `// @isolatedModules: true`, `// @importHelpers: true`, - - `// @experimentalDecorators: true`, `// @emitDecoratorMetadata: true`, `// @importsNotUsedAsValues: true`, `// @noEmitHelpers: true`, `// @noImplicitUseStrict: true`, - - `// @noLib: true`, `// @noResolve: true`, `// @noStrictGenericChecks: true`, `// @noUncheckedIndexedAccess: true`, `// @noUnusedLocals: true`, `// @noUnusedParameters: true`, - - `// @strictBindCallApply: true`, `// @strictFunctionTypes: true`, `// @strictNullChecks: true`, `// @strictPropertyInitialization: true`, `// @useUnknownInCatchVariables: true`, - - `// @allowJs: true`, `// @checkJs: true`, `// @jsx: preserve`, `// @jsxFactory: React`, `// @jsxFragmentFactory: React`, `// @jsxImportSource: React`, - - `// @allowUnreachableCode`: Do not report errors on unreachable code. - - `// @allowUnusedLabels`: Do not report errors on unused labels. - - `// @alwaysStrict`: Parse in strict mode and emit "use strict" for each source file. - - `// @exactOptionalPropertyTypes`: Differentiate between optional property and undefined property in the type system. - - `// @noFallthroughCasesInSwitch`: Report errors for fallthrough cases in switch statements. - - `// @noImplicitAny`: Raise error on expressions and declarations with an implied 'any' type. - - `// @noImplicitOverride`: Ensure overriding members in derived classes are marked with an 'override' modifier. - - `// @noImplicitReturns`: Report error when not all code paths in function return a value. - - `// @noImplicitThis`: Raise error on 'this' expressions with an implied 'any' type. - - `// @noPropertyAccessFromIndexSignature`: Require undeclared properties from index signatures to be accessed with an index. - - `// @noUncheckedIndexedAccess`: Add a 'undefined' type to elements accessed via an index signature. - - `// @noUnusedLocals`: Report errors on unused locals. - - `// @noUnusedParameters`: Report errors on unused parameters. - - `// @strict`: Enable all strict type checking options. - - `// @strictBindCallApply`: Enable stricter checking of bind, call, and apply. - - `// @strictFunctionTypes`: Enable stricter checking of function types. - - `// @strictNullChecks`: Enable strict null checks. - - `// @strictPropertyInitialization`: Enable strict checking of property initialization. - - `// @useUnknownInCatchVariables`: Type catch clause variables as 'unknown' instead of 'any'. - - `// @allowArbitraryExtensions`: Allow arbitrary file extensions to be included in the program. - - `// @allowImportingTsExtensions`: Allow '.ts' and '.tsx' extensions to be imported. - - `// @allowUmdGlobalAccess`: Allow accessing UMD globals from modules. - - `// @baseUrl`: Base directory to resolve non-relative module names. - - `// @customConditions`: List of custom conditions to apply to module resolution. - - `// @module`: Specify module code generation. - - `// @moduleResolution`: Specify module resolution strategy. - - `// @moduleSuffixes`: List of file extensions to consider when resolving modules. - - `// @noResolve`: Do not add triple-slash references or module import targets to the list of compiled files. - - `// @paths`: A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. - - `// @resolveJsonModule`: Include modules imported with '.json' extension. - - `// @resolvePackageJsonExports`: Resolve the 'exports' field in 'package.json'. - - `// @resolvePackageJsonImports`: Resolve the 'imports' field in 'package.json'. - - `// @rootDir`: Specifies the root directory of input files. - - `// @rootDirs`: List of root folders whose combined content represents the structure of the project at runtime. - - `// @typeRoots`: List of folders to include type definitions from. - - `// @types`: Type declaration files to be included in compilation. - - `// @declaration`: Generates corresponding '.d.ts' file. - - `// @declarationDir`: Output directory for generated declaration files. - - `// @declarationMap`: Generates a sourcemap for each corresponding '.d.ts' file. - - `// @downlevelIteration`: Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. - - `// @emitBOM`: Specifies whether to emit a byte order mark (BOM) in emitted files. The byte order mark (BOM) is a Unicode character that serves as an indicator for the encoding of a text file. By default, TypeScript emits files without a BOM. Enabling `emitBOM` instructs TypeScript to include the BOM character at the beginning of emitted files, which can be useful for compatibility with certain tools and environments. - examples: - - | - // @module: esnext - // @target: ES2022 - // @errors: 1003 2304 7006 2339 - // @declaration: true - // @emit - // @filename: maths.ts - /** - * Gets the length of a string - * @param value a string - */ - function fnx2(s: string) { - console.log(s.substr(3)) - } - export function absolute(num: number) { - if (num < 0) return num * -1; - return num; - } - - import {SpringEasing} from "spring-easing" - SpringEasing - // ^? - - /** - * Gets the length of a string - * @param value a string - */ - function fnx(s: string) { - console.log(s.substr(3)) - } - - export const slash = [] as string[] - fnx("42") - //^? - // ^^^^^ - - function greet(person: string, date: Date) { - console.log(\`Hello \${person}, today is \${date.toDateString()}!\`) - } - - greet("Maddison", new Date()) - // ^^^^^ A Quick explanation - console.g - // ^| - - // @filename: index.ts - import {absolute} from "./maths" - const value = absolute(-1) - // ^? - // ^^^^^^^^^^ - const value2 = absolute(-2) - // ^? - // ^^^^^^^^ - - function fn(s) { - console.log(s.substr(3)) - } + $ref: "#/components/schemas/Code" extension: - type: string - description: The extension of the code file. Can be 'typescript', 'javascript', 'json', 'jsn', 'ts', 'js', 'tsx', or 'jsx'. - examples: - - "ts" + $ref: "#/components/schemas/Extension" defaultOptions: $ref: '#/components/schemas/ExampleOptions' defaultCompilerOptions: diff --git a/README.md b/README.md index cfa7ba7..0b9d307 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ formData.append("code", "import { hasTransferables } from \"transferables\"") formData.append("extension", "ts"); const res = await fetch("https://ts-check.okikio.dev/twoslash", { - method: "POST", - body: formData + method: "POST", + body: formData }) console.log({ @@ -22,10 +22,11 @@ console.log({ // OR const options = JSON.stringify({ - "code": "import { hasTransferables } from \"transferables\"", + "code": `import { hasTransferables } from "transferables"`, "extension": "ts" }); +// const res = await fetch(`https://ts-check.okikio.dev/twoslash?options=${options}`) console.log({ diff --git a/deps.ts b/deps.ts index aced762..eec3728 100644 --- a/deps.ts +++ b/deps.ts @@ -1,14 +1,12 @@ -export { default as Typescript } from "https://esm.sh/typescript@5.0.4" +export { default as Typescript } from "https://esm.sh/typescript@5" export * as lzstring from "https://esm.sh/@amoutonbrady/lz-string@0.1.0" -export * as path from "https://deno.land/std@0.189.0/path/mod.ts" +export * as path from "https://deno.land/std/path/mod.ts" -export { serve } from "https://deno.land/std@0.189.0/http/server.ts" -export { cors } from "https://deno.land/x/dewy@0.1.0/middlewares/cors.ts" -export * as media_types from "https://deno.land/std@0.189.0/media_types/mod.ts" -export * as dewy from "https://deno.land/x/dewy@0.1.0/mod.ts" +export * as oak from "https://deno.land/x/oak/mod.ts" +export { oakCors as cors } from "https://deno.land/x/cors/mod.ts" -declare module "https://esm.sh/typescript@5.0.4" { +declare module "https://esm.sh/typescript@5" { // Hacking in some internal stuff type TypescriptOption = { name: string; diff --git a/mod.ts b/mod.ts index 06ef70f..a59fd9d 100644 --- a/mod.ts +++ b/mod.ts @@ -1,11 +1,10 @@ -import { cors, dewy, media_types, path, serve } from "./deps.ts"; +import { cors, oak, path } from "./deps.ts"; import { twoslasher } from "./vendor/twoslash.ts"; import type { TwoSlashOptions } from "./vendor/twoslash.ts"; -const { extname, basename, dirname, fromFileUrl, join } = path; -const { Router } = dewy; -const { contentType } = media_types; +const { Application, Router, send, isHttpError, Status } = oak; +const { dirname, fromFileUrl, join } = path; const __dirname = dirname(fromFileUrl(import.meta.url)); interface TwoslashRequestOptions extends TwoSlashOptions { @@ -14,33 +13,65 @@ interface TwoslashRequestOptions extends TwoSlashOptions { } const router = new Router(); -// router.use(cors()); -router.get("/", () => { - try { - return Response.json({ +router + .get("/", (context) => { + context.response.body = ({ hey: "Hello World! The API is working!", message: "/twoslash - Accepts a JSON & Form Data body with the following properties: code, extension, and options.", + }) + }) + .get("/.well-known/(.*)", async (context) => { + await send(context, context.request.url.pathname.replace("/.well-known", ""), { + root: join(Deno.cwd(), "./.well-known"), + index: "ai-plugin.json", }); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), + }) + .get("/favicon/(.*)", async (context) => { + await send(context, context.request.url.pathname.replace("/favicon", ""), { + root: join(__dirname, "./favicon"), + index: "favicon.svg", }); - } -}); - -router.get("/twoslash", async ({ request }) => { - try { + }) + .get("/favicon.svg", async (context) => { + await send(context, context.request.url.pathname, { + root: join(__dirname, "./favicon"), + index: "favicon.svg", + }); + }) + .get("/favicon.ico", async (context) => { + await send(context, context.request.url.pathname, { + root: join(__dirname, "./favicon"), + index: "favicon.ico", + }); + }) + .options("/twoslash", cors()) // enable pre-flight request for OPTIONS request + .post("/twoslash", async (context) => { + const { request } = context; + const contentType = request.headers.get("content-type"); console.log({ - method: "get", + method: "post", url: request.url, + contentType, }); - const url = new URL(request.url); + + const { type, value } = request.body(); + if (type !== "form-data" && type !== "json") context.throw(Status.UnsupportedMediaType, `${type} isn't a supported content type`); + + // Max file size to handle + const data: TwoslashRequestOptions = type === "form-data" ? (await value.read({ maxSize: 10000000 })).fields : await value; + const { code, extension, ...opts } = data; + + const twoslash = await twoslasher(code, extension, opts); + console.log("twoslash ", twoslash); + context.response.body = twoslash; + }) + .get("/twoslash", async (context) => { + const { request } = context; + + const url = request.url; if (!url.search) { - return Response.json({ + context.response.body = ({ title: "You can send requests in these formats", requests: [ `GET: /twoslash?options={"code":"import { hasTransferables } from \"transferables\"","extension":"ts"}`, @@ -49,150 +80,64 @@ router.get("/twoslash", async ({ request }) => { `POST: /twoslash --> FormData Body={"code":"import { hasTransferables } from \"transferables\"","extension":"ts"}`, ], }); - } - const codeParam = url.searchParams.get("code")! || undefined; - const extensionParam = url.searchParams.get("extension")! || - url.searchParams.get("ext")! || undefined; - const optionsParam = url.searchParams.get("options")! || - url.searchParams.get("option")! || "{}"; + return; + } + + const params = url.searchParams; + const codeParam = params.get("code")! || undefined; + const extensionParam = + params.get("extension")! || + params.get("ext")! || + undefined; + const optionsParam = + params.get("options")! || + params.get("option")! || + "{}"; const decodedQuery: TwoslashRequestOptions = Object.assign( - JSON.parse(optionsParam), { code: codeParam, extension: extensionParam }, + JSON.parse(optionsParam), ); const { code, extension = "ts", ...opts } = decodedQuery; const twoslash = await twoslasher(code, extension, opts); console.log("twoslash ", twoslash); - return Response.json(twoslash); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), - }); - } -}); + context.response.body = twoslash; + }); -router.post("/twoslash", async ({ request }) => { +const app = new Application(); +app.use(async (context, next) => { try { - const headers = request.headers; - const contentType = headers.get("content-type"); - console.log({ - method: "post", - url: request.url, - contentType, - }); - const { code, extension, ...opts }: TwoslashRequestOptions = - contentType && /multipart\/form\-data/.test(contentType) - ? Object.fromEntries((await request.formData()).entries()) - : await request.json(); - - const twoslash = await twoslasher(code, extension, opts); - console.log("twoslash ", twoslash); - return Response.json(twoslash); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), - }); - } -}); - -router.get("/.well-known/*", async ({ request }) => { - try { - const url = new URL(request.url); - const ext = extname(url.pathname); - const fileName = basename(url.pathname); - return new Response( - await Deno.readFile(join(__dirname, "./.well-known", fileName)), - { - status: 200, - headers: new Headers([ - ["Content-Type", contentType(ext) ?? "application/json"], - ]), - }, - ); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), - }); - } -}); - -router.get("/favicon/*", async ({ request }) => { - try { - const url = new URL(request.url); - const ext = extname(url.pathname); - const fileName = basename(url.pathname); - return new Response( - await Deno.readFile(join(__dirname, "./favicon", fileName)), - { - status: 200, - headers: new Headers([ - ["Content-Type", contentType(ext) ?? "text/plain"], - ]), - }, - ); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), - }); + await next(); + } catch (err) { + if (isHttpError(err)) { + context.response.status = err.status; + const { message, status, stack } = err; + if (context.request.accepts("json")) { + context.response.body = { message, status, stack }; + context.response.type = "json"; + } else { + context.response.body = `${status} ${message}\n\n${stack ?? ""}`; + context.response.type = "text/plain"; + } + } else { + // handle all other Errors + context.response.status = 500; + context.response.body = "Internal server error"; + console.error(err); + } } }); -router.get("/favicon.ico", async () => { - try { - const ext = ".ico"; - return new Response( - await Deno.readFile(join(__dirname, "./favicon/favicon.ico")), - { - status: 200, - headers: new Headers([ - ["Content-Type", contentType(ext)], - ]), - }, - ); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), - }); - } -}); +app.use(cors()); // Enable CORS for All Routes +app.use(router.routes()); -const ext = ".svg"; -router.get("/favicon.svg", async () => { - try { - return new Response( - await Deno.readFile(join(__dirname, "./favicon/favicon.svg")), - { - status: 200, - headers: new Headers([ - ["Content-Type", contentType(ext)], - ]), - }, - ); - } catch (e) { - return new Response(e.toString(), { - status: 400, - headers: new Headers([ - ["Content-Type", "text/plain"], - ]), - }); - } +// 404 middleware +app.use((context) => { + context.response.status = Status.NotFound; + context.response.body = "404 Not Found"; }); -serve(router.dispatch.bind(router)); +console.info("CORS-enabled web server listening on port 8000"); +await app.listen({ port: 8000 }); \ No newline at end of file -- 2.51.2