1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 07:27:39 +02:00

fix: Assorted Typing Fixes (#3348)

With all the commits below, we resolve all outstanding typing issues in the repo, and CI jobs run green.

* fix: Convert DashboardPage and DashboardWidget to TypeScript

* fix: fix type errors in package manager ext

* fix: Convert Post component to TypeScript

* fix: avatar typings should accept null user

* fix: convert Notification component to TypeScript

* fix: properly use `typeof` in ForumApplication

* feat: make Notification content attr generic

* chore: format Notification component

* fix: Convert DiscussionRenamedNotification to TypeScript

* fix(pusher) move shims to a location where they get applied

* fix(pusher): fix some typing errors

* fix(akismet): fix some typing issues

* chore: update core dist typings

* chore(pusher): format

* fix: anchorScroll should accept string selectors

* fix: more accurately represent ApiQueryParamsPlural

* fix: convert PostStreamState to TypeScript

* chore(core): rebuild typings

* feat: allow extending app.routes

* fix: more flexible typings for highlight.ts

* fix: use primitive `number` type for Discussion typings

* fix: convert DiscussionListItem to TypeScript

* chore: rebuild core typings

* fix: final pusher type fixes

* feat: start tags TypeScript conversion

* fix: require-dev tags in pusher for CI TypeScript purposes.

* chore(core): format

* chore(tags): build dist typings

* feat(pusher): use dist types from tags.

* feat: convert flags to TypeScript

* chore(flags): generate dist typings

* fix(akismet): last type errors

* chore: update .yarn-integrity

* chore: partially run flarum-cli audit infra --fix

The tsconfig changes from that command are ignored, since we don't yet support "replacable sections" that would let us add custom config.

* chore: use type imports

* fix: broader gitattributes

* chore: run flarum-cli audit infra --monorepo --fix

* feat: make `app.data` typings extensible

* chore(core): format

* chore: boost tags TypeScript coverage

* fix(tags): further increase type coverage.
This commit is contained in:
Alexander Skvortsov
2022-03-23 11:43:14 -04:00
committed by GitHub
parent 4ecd9a9b2f
commit a595665bfb
255 changed files with 1578 additions and 1218 deletions

View File

@@ -10,7 +10,7 @@
"format": "prettier --write src",
"format-check": "prettier --check src",
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
"build-typings": "yarn run clean-typings && [ -e src/@types ] && cp -r src/@types dist-typings/@types && tsc && yarn run post-build-typings",
"build-typings": "yarn run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && yarn run post-build-typings",
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
"check-typings-coverage": "typescript-coverage-report",
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'"

View File

@@ -6,7 +6,8 @@ import DiscussionPage from 'flarum/forum/components/DiscussionPage';
import IndexPage from 'flarum/forum/components/IndexPage';
import Button from 'flarum/common/components/Button';
import ItemList from 'flarum/common/utils/ItemList';
import { Children, VnodeDOM } from 'mithril';
import type { Children } from 'mithril';
import type Tag from 'flarum/tags/common/models/Tag';
export type PusherBinding = {
channels: {
@@ -47,14 +48,15 @@ app.initializers.add('flarum-pusher', () => {
app.pusher.then((binding: PusherBinding) => {
const pusher = binding.pusher;
pusher.bind('newPost', (data: { tagIds: number[]; discussionId: number }) => {
pusher.bind('newPost', (data: { tagIds: string[]; discussionId: number }) => {
const params = app.discussions.getParams();
if (!params.q && !params.sort && !params.filter) {
if (params.tags) {
const tag = app.store.getBy('tags', 'slug', params.tags);
const tag = app.store.getBy<Tag>('tags', 'slug', params.tags);
const tagId = tag?.id();
if (!data.tagIds.includes(tag.id())) return;
if (!tagId || !data.tagIds.includes(tagId)) return;
}
const id = String(data.discussionId);
@@ -79,11 +81,11 @@ app.initializers.add('flarum-pusher', () => {
});
});
extend(DiscussionList.prototype, 'view', function (this: DiscussionList, vdom: VnodeDOM) {
extend(DiscussionList.prototype, 'view', function (this: DiscussionList, vdom: Children) {
if (app.pushedUpdates) {
const count = app.pushedUpdates.length;
if (count) {
if (count && typeof vdom === 'object' && vdom && 'children' in vdom && vdom.children instanceof Array) {
vdom.children.unshift(
Button.component(
{

View File

@@ -13,3 +13,9 @@ declare module 'flarum/forum/ForumApplication' {
pushedUpdates: Array<any>;
}
}
declare module 'flarum/forum/components/DiscussionList' {
export default interface DiscussionList {
loadingUpdated?: boolean;
}
}

View File

@@ -4,13 +4,14 @@
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*", "@types/**/*"],
"include": ["src/**/*", "../vendor/*/*/js/dist-typings/@types/**/*", "@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
"flarum/tags/*": ["../vendor/flarum/tags/js/dist-typings/*"]
}
}
}