Skip to content

Fix TypeScript typechecking not working #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
path = blueprint-compiler
url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git
[submodule "src/langs/typescript/template/gi-types"]
path = gi-types
path = src/langs/typescript/template/gi-types
url = https://gitlab.gnome.org/BrainBlasted/gi-typescript-definitions.git
branch = nightly
branch = main
1 change: 0 additions & 1 deletion gi-types
Submodule gi-types deleted from 396fe1
6 changes: 3 additions & 3 deletions src/cli/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export default async function javascript({
const text = await diagnose({ file, lspc, languageId });

await checkFile({
lspc: lspc,
file: file,
lang: getLanguage("javascript"),
lspc,
file,
lang: getLanguage(languageId),
uri: file.get_uri(),
});

Expand Down
8 changes: 6 additions & 2 deletions src/cli/typescript.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-restricted-globals */

import { getLanguage } from "../common.js";
import { setupTypeScriptProject } from "../langs/typescript/typescript.js";
import { checkFile, getCodeObjectIds, diagnose, Interrupt } from "./util.js";

const languageId = "typescript";
Expand All @@ -17,6 +18,8 @@ export default async function typescript({
}) {
print(` ${file.get_path()}`);

await setupTypeScriptProject(file.get_parent(), { lspc });

const text = await diagnose({ file, lspc, languageId });

await checkFile({
Expand Down Expand Up @@ -45,8 +48,9 @@ export default async function typescript({
preview() {},
};

await import(`file://${file.get_path()}`);
print(" ✅ runs");
// TODO: Support running TypeScript files by compiling them first
// await import(`file://${file.get_path()}`);
// print(" ✅ runs");

await lspc._notify("textDocument/didClose", {
textDocument: {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/vala.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default async function vala({ file, lspc, demo_dir }) {
await checkFile({
lspc,
file,
lang: getLanguage("vala"),
lang: getLanguage(languageId),
uri: file.get_uri(),
});

Expand Down
1 change: 1 addition & 0 deletions src/langs/typescript/template/gi-types
Submodule gi-types added at e70b49
7 changes: 5 additions & 2 deletions src/langs/typescript/template/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
"outDir": "compiled_javascript",
"baseUrl": ".",
"paths": {
"*": ["*", "@pkgdatadir@/langs/typescript/gi-types/*"]
"*": [
"*",
"@pkgdatadir@/langs/typescript/gi-types/*"
]
},
"skipLibCheck": true
},
"include": [
"main.ts",
"@pkgdatadir@/langs/typescript/types/ambient.d.ts",
"@pkgdatadir@/langs/typescript/gi-types/gi.d.ts"
"@pkgdatadir@/langs/typescript/gi-types/index.d.ts"
]
}
59 changes: 13 additions & 46 deletions src/langs/typescript/types/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
// import Adw from "gi://Adw";
// import Gtk from "gi://Gtk?version=4.0";
// import GObject from "gi://GObject";
/// <reference path="../template/gi-types/index.d.ts" />

// additional type declarations for GJS
import Adw from "gi://Adw";
import Gtk from "gi://Gtk?version=4.0";
import GObject from "gi://GObject";

// additional GJS log utils
declare function print(...args: any[]): void;
declare function log(...args: any[]): void;

// GJS pkg global
declare const pkg: {
version: string;
name: string;
};

// old GJS global imports
// used like: imports.format.printf("...");
declare module imports {
// format import
const format: {
format(this: String, ...args: any[]): string;
printf(fmt: string, ...args: any[]): string;
vprintf(fmt: string, args: any[]): string;
declare global {
const workbench: {
window: Adw.ApplicationWindow;
application: Adw.Application;
builder: Gtk.Builder;
template: string;
resolve(path: string): string;
preview(object: Gtk.Widget): void;
build(params: Record<string, Function | GObject.Object>): void;
};
}

// gettext import
declare module "gettext" {
export function gettext(id: string): string;
export function ngettext(
singular: string,
plural: string,
n: number,
): string;
}

// TODO: uncomment correct typings after we switch to `ts-for-gir`
// declare const workbench: {
// window: Adw.ApplicationWindow;
// application: Adw.Application;
// builder: Gtk.Builder;
// template: string;
// resolve(path: string): string;
// preview(object: Gtk.Widget): void;
// build(params: Record<string, Function | GObject.Object>): void;
// };

// global workbench object
declare const workbench: any;
Loading