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_json = "1.0"
serde = { version = "1.0.181", features = ["derive"] } serde = { version = "1.0.181", features = ["derive"] }
serde-wasm-bindgen = "0.4" 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;
use std::fmt::{Formatter, Write}; use std::fmt::{Formatter, Write};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tsify::Tsify;
use crate::constants::{ALL_LETTERS_BONUS, GRID_LENGTH, TRAY_LENGTH}; use crate::constants::{ALL_LETTERS_BONUS, GRID_LENGTH, TRAY_LENGTH};
use crate::dictionary::DictionaryImpl; 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 struct Letter {
pub text: char, pub text: char,
pub points: u32, pub points: u32,

View file

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

View file

@ -1,11 +1,6 @@
import * as React from "react"; 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 { export function Letter(props: { data: LetterData }): React.JSX.Element {
return <div className="letter"> return <div className="letter">

View file

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

View file

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