Add autogenerated Typescript definitions

This commit is contained in:
Joel Therrien 2023-08-05 21:55:16 -07:00
parent c9c3c7b59e
commit f8e99ea02f
7 changed files with 25 additions and 14 deletions

View file

@ -14,4 +14,5 @@ wasm-bindgen = { version = "0.2.87", features = ["serde-serialize"] }
serde_json = "1.0"
serde = { version = "1.0.181", features = ["derive"] }
serde-wasm-bindgen = "0.4"
tsify = { version = "0.4.5", features = ["js"] }

View file

@ -2,6 +2,7 @@ use std::collections::HashSet;
use std::fmt;
use std::fmt::{Formatter, Write};
use serde::{Deserialize, Serialize};
use tsify::Tsify;
use crate::constants::{ALL_LETTERS_BONUS, GRID_LENGTH, TRAY_LENGTH};
use crate::dictionary::DictionaryImpl;
@ -49,7 +50,8 @@ impl Coordinates {
}
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Tsify)]
#[tsify(from_wasm_abi)]
pub struct Letter {
pub text: char,
pub points: u32,

View file

@ -1,10 +1,12 @@
use serde::{Deserialize, Serialize};
use tsify::Tsify;
use crate::board::Letter;
pub mod ai;
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[tsify(from_wasm_abi)]
pub struct Tray {
pub letters: Vec<Option<Letter>>
}

View file

@ -1,11 +1,6 @@
import * as React from "react";
import {Letter as LetterData} from "word_grid";
export interface LetterData {
text: string,
points: number,
ephemeral: boolean,
is_blank: boolean,
}
export function Letter(props: { data: LetterData }): React.JSX.Element {
return <div className="letter">

View file

@ -6,7 +6,7 @@
<title>Word Grid</title>
</head>
<body>
<script src="./index.js" type="module"></script>
<script src="index.tsx" type="module"></script>
<div id="root"></div>
</body>
</html>

View file

@ -1,7 +1,7 @@
import init, {greet, GameWasm} from '../node_modules/word_grid/word_grid.js';
import {TileTray} from "./elements";
import ReactDOM from "react-dom";
import {createRoot} from "react-dom/client";
import {Tray} from "word_grid";
async function run() {
// First up we need to actually load the wasm file, so we use the
@ -34,8 +34,8 @@ async function run() {
greet("Heyo!");
let game = new GameWasm(1234n);
let tray = game.get_tray();
let game = new GameWasm(BigInt(1234));
let tray: Tray = game.get_tray();
console.log({tray});

11
ui/tsconfig.json Normal file
View file

@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2023",
"jsx": "react-jsx",
"lib": [
"es2023",
"dom"
]
}
}