fix types

This commit is contained in:
Lhcfl 2024-04-23 22:40:57 +08:00
parent 62f5c84ca6
commit c0afa4a2f7
5 changed files with 16 additions and 11 deletions

View file

@ -182,7 +182,7 @@ export default {
const props = defineProps<{
type: string;
q: string | null;
textarea: HTMLTextAreaElement;
textarea: HTMLTextAreaElement | HTMLInputElement;
close: () => void;
x: number;
y: number;
@ -435,7 +435,7 @@ onUpdated(() => {
onMounted(() => {
setPosition();
props.textarea.addEventListener("keydown", onKeydown);
(props.textarea as HTMLTextAreaElement).addEventListener("keydown", onKeydown);
document.body.addEventListener("mousedown", onMousedown);
nextTick(() => {
@ -453,7 +453,7 @@ onMounted(() => {
});
onBeforeUnmount(() => {
props.textarea.removeEventListener("keydown", onKeydown);
(props.textarea as HTMLTextAreaElement).removeEventListener("keydown", onKeydown);
document.body.removeEventListener("mousedown", onMousedown);
});
</script>

View file

@ -9,7 +9,7 @@ export function byteify(string: string, encoding: "ascii" | "base64" | "hex") {
);
case "hex":
return new Uint8Array(
string.match(/.{1,2}/g).map((byte) => Number.parseInt(byte, 16)),
string.match(/.{1,2}/g)!.map((byte) => Number.parseInt(byte, 16)),
);
}
}

View file

@ -1,4 +1,4 @@
import type { EndoRelation, Predicate } from "./relation";
import type { EndoRelation, Predicate } from "@/types/relation";
/**
* Count the number of elements that satisfy the predicate
@ -126,7 +126,7 @@ export function lessThan(xs: number[], ys: number[]): boolean {
* Returns the longest prefix of elements that satisfy the predicate
*/
export function takeWhile<T>(f: Predicate<T>, xs: T[]): T[] {
const ys = [];
const ys: T[] = [];
for (const x of xs) {
if (f(x)) {
ys.push(x);

View file

@ -13,7 +13,7 @@ export class Autocomplete {
} | null;
private textarea: HTMLInputElement | HTMLTextAreaElement;
private currentType: string;
private currentType?: string;
private textRef: Ref<string>;
private opening: boolean;
@ -69,7 +69,7 @@ export class Autocomplete {
*
*/
private onInput() {
const caretPos = this.textarea.selectionStart;
const caretPos = this.textarea.selectionStart!;
const text = this.text.substring(0, caretPos).split("\n").pop()!;
const mentionIndex = text.lastIndexOf("@");
@ -147,10 +147,10 @@ export class Autocomplete {
this.opening = true;
this.currentType = type;
// #region サジェストを表示すべき位置を計算
// #region Calculate the position where suggestions should be displayed
const caretPosition = getCaretCoordinates(
this.textarea,
this.textarea.selectionStart,
this.textarea.selectionStart!,
);
const rect = this.textarea.getBoundingClientRect();
@ -216,7 +216,7 @@ export class Autocomplete {
private complete({ type, value }) {
this.close();
const caret = this.textarea.selectionStart;
const caret = this.textarea.selectionStart!;
if (type === "user") {
const source = this.text;

View file

@ -0,0 +1,5 @@
export type Predicate<T> = (a: T) => boolean;
export type Relation<T, U> = (a: T, b: U) => boolean;
export type EndoRelation<T> = Relation<T, T>;