mirror of
https://github.com/denoland/deno.git
synced 2025-01-22 06:09:25 -05:00
Turn on TS strict mode for deno_typescript (#3330)
This commit is contained in:
parent
8b90b8e883
commit
4902a1cacb
9 changed files with 27 additions and 9 deletions
|
@ -143,9 +143,10 @@ export class Body implements domTypes.Body {
|
||||||
this._stream = this._bodySource;
|
this._stream = this._bodySource;
|
||||||
}
|
}
|
||||||
if (typeof this._bodySource === "string") {
|
if (typeof this._bodySource === "string") {
|
||||||
|
const bodySource = this._bodySource;
|
||||||
this._stream = new ReadableStream({
|
this._stream = new ReadableStream({
|
||||||
start(controller: ReadableStreamController): void {
|
start(controller: ReadableStreamController): void {
|
||||||
controller.enqueue(this._bodySource);
|
controller.enqueue(bodySource);
|
||||||
controller.close();
|
controller.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -285,7 +285,7 @@ async function processImports(
|
||||||
referrer = ""
|
referrer = ""
|
||||||
): Promise<SourceFileJson[]> {
|
): Promise<SourceFileJson[]> {
|
||||||
if (!specifiers.length) {
|
if (!specifiers.length) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
const sources = specifiers.map(([, moduleSpecifier]) => moduleSpecifier);
|
const sources = specifiers.map(([, moduleSpecifier]) => moduleSpecifier);
|
||||||
const sourceFiles = await fetchSourceFiles(sources, referrer);
|
const sourceFiles = await fetchSourceFiles(sources, referrer);
|
||||||
|
@ -385,6 +385,8 @@ class Host implements ts.CompilerHost {
|
||||||
private readonly _options: ts.CompilerOptions = {
|
private readonly _options: ts.CompilerOptions = {
|
||||||
allowJs: true,
|
allowJs: true,
|
||||||
allowNonTsExtensions: true,
|
allowNonTsExtensions: true,
|
||||||
|
// TODO(#3324) Enable strict mode for user code.
|
||||||
|
// strict: true,
|
||||||
checkJs: false,
|
checkJs: false,
|
||||||
esModuleInterop: true,
|
esModuleInterop: true,
|
||||||
module: ts.ModuleKind.ESNext,
|
module: ts.ModuleKind.ESNext,
|
||||||
|
|
8
cli/js/lib.deno_runtime.d.ts
vendored
8
cli/js/lib.deno_runtime.d.ts
vendored
|
@ -2858,4 +2858,10 @@ declare namespace WebAssembly {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
|
// Catch-all for JSX elements.
|
||||||
|
// See https://www.typescriptlang.org/docs/handbook/jsx.html#intrinsic-elements
|
||||||
|
declare namespace JSX {
|
||||||
|
interface IntrinsicElements {
|
||||||
|
[elemName: string]: any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -95,7 +95,8 @@ export function start(preserveDenoNamespace = true, source?: string): Start {
|
||||||
for (const [name, opId] of Object.entries(ops)) {
|
for (const [name, opId] of Object.entries(ops)) {
|
||||||
const opName = `OP_${name.toUpperCase()}`;
|
const opName = `OP_${name.toUpperCase()}`;
|
||||||
// Assign op ids to actual variables
|
// Assign op ids to actual variables
|
||||||
dispatch[opName] = opId;
|
// TODO(ry) This type casting is gross and should be fixed.
|
||||||
|
((dispatch as unknown) as { [key: string]: number })[opName] = opId;
|
||||||
}
|
}
|
||||||
// First we send an empty `Start` message to let the privileged side know we
|
// First we send an empty `Start` message to let the privileged side know we
|
||||||
// are ready. The response should be a `StartRes` message containing the CLI
|
// are ready. The response should be a `StartRes` message containing the CLI
|
||||||
|
|
|
@ -259,7 +259,7 @@ export function isReadableStreamLocked<OutputType>(
|
||||||
|
|
||||||
export function readableStreamGetNumReadIntoRequests<OutputType>(
|
export function readableStreamGetNumReadIntoRequests<OutputType>(
|
||||||
stream: SDReadableStream<OutputType>
|
stream: SDReadableStream<OutputType>
|
||||||
): number | undefined {
|
): number {
|
||||||
// TODO remove the "as unknown" cast
|
// TODO remove the "as unknown" cast
|
||||||
// This is in to workaround a compiler error
|
// This is in to workaround a compiler error
|
||||||
// error TS2352: Conversion of type 'SDReadableStreamReader<OutputType>' to type 'SDReadableStreamBYOBReader' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
// error TS2352: Conversion of type 'SDReadableStreamReader<OutputType>' to type 'SDReadableStreamBYOBReader' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
||||||
|
|
|
@ -156,7 +156,7 @@ export class URL {
|
||||||
"search"
|
"search"
|
||||||
];
|
];
|
||||||
const objectString = keys
|
const objectString = keys
|
||||||
.map((key: string) => `${key}: "${this[key] || ""}"`)
|
.map((key: string) => `${key}: "${this[key as keyof this] || ""}"`)
|
||||||
.join(", ");
|
.join(", ");
|
||||||
return `URL { ${objectString} }`;
|
return `URL { ${objectString} }`;
|
||||||
}
|
}
|
||||||
|
|
2
deno_typescript/lib.deno_core.d.ts
vendored
2
deno_typescript/lib.deno_core.d.ts
vendored
|
@ -21,7 +21,7 @@ interface EvalErrorInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface DenoCore {
|
declare interface DenoCore {
|
||||||
print(s: string, isErr?: boolean);
|
print(s: string, isErr?: boolean): void;
|
||||||
dispatch(
|
dispatch(
|
||||||
opId: number,
|
opId: number,
|
||||||
control: Uint8Array,
|
control: Uint8Array,
|
||||||
|
|
|
@ -127,6 +127,7 @@ pub fn compile_bundle(
|
||||||
|
|
||||||
let config_json = serde_json::json!({
|
let config_json = serde_json::json!({
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"lib": ["esnext"],
|
"lib": ["esnext"],
|
||||||
"module": "amd",
|
"module": "amd",
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
import { notImplemented, intoCallbackAPIWithIntercept } from "./_utils.ts";
|
import {
|
||||||
|
notImplemented,
|
||||||
|
intoCallbackAPIWithIntercept,
|
||||||
|
MaybeEmpty
|
||||||
|
} from "./_utils.ts";
|
||||||
const { readFile: denoReadFile, readFileSync: denoReadFileSync } = Deno;
|
const { readFile: denoReadFile, readFileSync: denoReadFileSync } = Deno;
|
||||||
|
|
||||||
type ReadFileCallback = (err: Error | null, data: string | Uint8Array) => void;
|
type ReadFileCallback = (
|
||||||
|
err: MaybeEmpty<Error>,
|
||||||
|
data: MaybeEmpty<string | Uint8Array>
|
||||||
|
) => void;
|
||||||
|
|
||||||
interface ReadFileOptions {
|
interface ReadFileOptions {
|
||||||
encoding?: string | null;
|
encoding?: string | null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue