Skip to content

Commit

Permalink
fix: TS setup for @observablehq/runtime + @observablehq/inspector (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
neoncitylights authored Jul 25, 2023
1 parent 03e8e93 commit 4887b19
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 28 deletions.
12 changes: 10 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions packages/observablehq_inspector/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
]
}
11 changes: 8 additions & 3 deletions packages/observablehq_runtime/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
declare module '@observablehq/runtime' {
import '@wandering-app/types-observablehq_inspector';
import '@wandering-app/types-observablehq_stdlib';
import '@observablehq/inspector';
import { FileAttachments } from '@observablehq/stdlib';

export { Inspector } from '@observablehq/inspector';

export class Module {
Expand All @@ -8,7 +13,7 @@ declare module '@observablehq/runtime' {
export class Runtime {
dispose(): void;
module<T, U>(v1: T, v2: U): Module;
fileAttachments: FileAttachments;
fileAttachments: typeof FileAttachments;
}

export interface Observer {
Expand All @@ -18,8 +23,8 @@ declare module '@observablehq/runtime' {
}

export namespace array {
export const map = Array.prototype.map;
export const forEach = Array.prototype.forEach;
export const map: typeof Array.prototype.map;
export const forEach: typeof Array.prototype.forEach;
}

export namespace constant {
Expand Down
6 changes: 5 additions & 1 deletion packages/observablehq_runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"directory": "packages/observablehq_runtime"
},
"devDependencies": {
"@observablehq/runtime": "^5.8.2"
"@observablehq/inspector": "^5.0.0",
"@observablehq/runtime": "^5.8.2",
"@observablehq/stdlib": "^5.7.7",
"@wandering-app/types-observablehq_inspector": "file:../observablehq_inspector",
"@wandering-app/types-observablehq_stdlib": "file:../observablehq_stdlib"
}
}
23 changes: 23 additions & 0 deletions packages/observablehq_runtime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
]
}
22 changes: 0 additions & 22 deletions packages/observablehq_stdlib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,6 @@ declare module '@observablehq/stdlib' {
// table.js
export function coerceToType<T, U>(value: T, type: string): U;

/* eslint-disable @typescript-eslint/no-unused-vars */
export function coerceToType<T, string>(value: T, type = 'string'): string;
export function coerceToType<T, boolean>(value: T, type = 'boolean'): boolean;
export function coerceToType<T, bigint>(value: T, type = 'bigint'): bigint;
export function coerceToType<T, number>(value: T, type = 'integer'|'number'): number;
export function coerceToType<T, Date>(value: T, type = 'date'): Date;
export function coerceToType<T, Array>(value: T, type = 'array'): Array;
export function coerceToType<T, T>(value: T, type = 'object'|'value'): T;
export function coerceToType<T, ArrayBuffer>(value: T, type = 'buffer'): ArrayBuffer;
export function getTypeValidator<T>(colType: string): (value: any) => T;
export function getTypeValidator(colType = 'string'): (value: any) => value is string;
export function getTypeValidator(colType = 'boolean'): (value: any) => value is boolean;
export function getTypeValidator(colType = 'bigint'): (value: any) => value is bigint;
export function getTypeValidator(colType = 'number'): (value: any) => value is number;
export function getTypeValidator(colType = 'integer'): (value: any) => boolean;
export function getTypeValidator(colType = 'date'): (value: any) => value is Date;
export function getTypeValidator(colType = 'buffer'): (value: any) => value is ArrayBuffer;
export function getTypeValidator(colType = 'array'): (value: any) => value is Array;
/* eslint-enable @typescript-eslint/no-unused-vars */

export function getTypeValidator(colType = 'object'): (value: any) => value is Object; // eslint-disable-line @typescript-eslint/ban-types

export type DataSource = 'chart'|'table'|'sql';
export function loadDataSource(source: any, mode: DataSource, name: string);

Expand Down

0 comments on commit 4887b19

Please sign in to comment.