ts: Migrate narrow_error to TypeScript.

This commit migrates narrow_error.js to TypeScript by inferring the
required types in the file and defining types in types.ts.
This commit is contained in:
nzai 2023-03-28 22:47:19 +03:00 committed by Tim Abbott
parent 602be3ed68
commit 97ff259506
2 changed files with 28 additions and 10 deletions

View File

@ -1,10 +0,0 @@
import render_empty_feed_notice from "../templates/empty_feed_notice.hbs";
export function narrow_error(narrow_banner_data) {
const title = narrow_banner_data.title;
const html = narrow_banner_data.html;
const search_data = narrow_banner_data.search_data;
const empty_feed_notice = render_empty_feed_notice({title, html, search_data});
return empty_feed_notice;
}

28
web/src/narrow_error.ts Normal file
View File

@ -0,0 +1,28 @@
import render_empty_feed_notice from "../templates/empty_feed_notice.hbs";
type QueryWord = {
query_word: string;
is_stop_word: boolean;
};
type SearchData = {
query_word: QueryWord[];
has_stop_word: boolean;
stream_query?: string;
topic_query?: string;
};
type NarrowBannerData = {
title: string;
html?: string;
search_data?: SearchData;
};
export function narrow_error(narrow_banner_data: NarrowBannerData): string {
const title = narrow_banner_data.title;
const html = narrow_banner_data.html;
const search_data = narrow_banner_data.search_data;
const empty_feed_notice = render_empty_feed_notice({title, html, search_data});
return empty_feed_notice;
}