1
0
mirror of https://github.com/flarum/core.git synced 2025-08-03 15:07:53 +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

22
extensions/flags/js/dist-typings/@types/shims.d.ts generated vendored Normal file
View File

@@ -0,0 +1,22 @@
import Flag from '../forum/models/Flag';
import FlagListState from '../forum/states/FlagListState';
import Mithril from 'mithril';
declare module 'flarum/common/models/Post' {
export default interface Post {
flags: () => false | (Flag | undefined)[];
canFlag: () => boolean;
}
}
declare module 'flarum/forum/ForumApplication' {
export default interface ForumApplication {
flags: FlagListState;
}
}
declare module 'flarum/forum/components/Post' {
export default interface Post {
flagReason: (flag: Flag) => Mithril.Children;
}
}

1
extensions/flags/js/dist-typings/admin/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1 @@
export default function _default(): void;

View File

@@ -0,0 +1 @@
export default function _default(): void;

View File

@@ -0,0 +1 @@
export default function _default(): void;

19
extensions/flags/js/dist-typings/forum/compat.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
declare var _default: {
'flags/addFlagsToPosts': typeof addFlagsToPosts;
'flags/addFlagControl': typeof addFlagControl;
'flags/addFlagsDropdown': typeof addFlagsDropdown;
'flags/models/Flag': typeof Flag;
'flags/components/FlagList': typeof FlagList;
'flags/components/FlagPostModal': typeof FlagPostModal;
'flags/components/FlagsPage': typeof FlagsPage;
'flags/components/FlagsDropdown': typeof FlagsDropdown;
};
export default _default;
import addFlagsToPosts from "./addFlagsToPosts";
import addFlagControl from "./addFlagControl";
import addFlagsDropdown from "./addFlagsDropdown";
import Flag from "./models/Flag";
import FlagList from "./components/FlagList";
import FlagPostModal from "./components/FlagPostModal";
import FlagsPage from "./components/FlagsPage";
import FlagsDropdown from "./components/FlagsDropdown";

View File

@@ -0,0 +1,7 @@
export default class FlagList extends Component<import("flarum/common/Component").ComponentAttrs, undefined> {
constructor();
oninit(vnode: any): void;
state: any;
view(): JSX.Element;
}
import Component from "flarum/common/Component";

View File

@@ -0,0 +1,15 @@
/// <reference types="flarum/@types/translator-icu-rich" />
export default class FlagPostModal extends Modal<import("flarum/common/components/Modal").IInternalModalAttrs> {
constructor();
oninit(vnode: any): void;
success: boolean | undefined;
reason: Stream<string> | undefined;
reasonDetail: Stream<string> | undefined;
title(): import("@askvortsov/rich-icu-message-formatter").NestedStringArray;
content(): JSX.Element;
flagReasons(): ItemList<any>;
onsubmit(e: any): void;
}
import Modal from "flarum/common/components/Modal";
import Stream from "flarum/common/utils/Stream";
import ItemList from "flarum/common/utils/ItemList";

View File

@@ -0,0 +1,7 @@
export default class FlagsDropdown {
static initAttrs(attrs: any): void;
getMenu(): JSX.Element;
goToRoute(): void;
getUnreadCount(): any;
getNewCount(): unknown;
}

View File

@@ -0,0 +1,9 @@
/**
* The `FlagsPage` component shows the flags list. It is only
* used on mobile devices where the flags dropdown is within the drawer.
*/
export default class FlagsPage {
oninit(vnode: any): void;
bodyClass: string | undefined;
view(): JSX.Element;
}

1
extensions/flags/js/dist-typings/forum/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,11 @@
import Model from 'flarum/common/Model';
import Post from 'flarum/common/models/Post';
import User from 'flarum/common/models/User';
export default class Flag extends Model {
type(): string;
reason(): string | null;
reasonDetail(): string | null;
createdAt(): Date | null | undefined;
post(): false | Post;
user(): false | User | null;
}

View File

@@ -0,0 +1,16 @@
export default class FlagListState {
constructor(app: any);
app: any;
/**
* Whether or not the flags are loading.
*
* @type {Boolean}
*/
loading: boolean;
/**
* Load flags into the application's cache if they haven't already
* been loaded.
*/
load(): void;
cache: any;
}

View File

@@ -3,12 +3,8 @@
"name": "@flarum/flags",
"version": "0.0.0",
"prettier": "@flarum/prettier-config",
"dependencies": {
"@flarum/prettier-config": "^1.0.0",
"flarum-webpack-config": "^1.0.0",
"flarum-tsconfig": "^1.0.2"
},
"devDependencies": {
"@types/mithril": "^2.0.8",
"prettier": "^2.5.1",
"flarum-webpack-config": "^2.0.0",
"webpack": "^5.65.0",
@@ -25,8 +21,9 @@
"format-check": "prettier --check src",
"analyze": "cross-env ANALYZER=true yarn run build",
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
"build-typings": "npm run clean-typings && cp -r src/@types dist-typings/@types && tsc",
"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"
"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

@@ -0,0 +1,22 @@
import Flag from '../forum/models/Flag';
import FlagListState from '../forum/states/FlagListState';
import Mithril from 'mithril';
declare module 'flarum/common/models/Post' {
export default interface Post {
flags: () => false | (Flag | undefined)[];
canFlag: () => boolean;
}
}
declare module 'flarum/forum/ForumApplication' {
export default interface ForumApplication {
flags: FlagListState;
}
}
declare module 'flarum/forum/components/Post' {
export default interface Post {
flagReason: (flag: Flag) => Mithril.Children;
}
}

View File

@@ -9,8 +9,8 @@ import addFlagsDropdown from './addFlagsDropdown';
import addFlagsToPosts from './addFlagsToPosts';
app.initializers.add('flarum-flags', () => {
app.store.models.posts.prototype.flags = Model.hasMany('flags');
app.store.models.posts.prototype.canFlag = Model.attribute('canFlag');
Post.prototype.flags = Model.hasMany<Flag>('flags');
Post.prototype.canFlag = Model.attribute<boolean>('canFlag');
app.store.models.flags = Flag;
@@ -26,5 +26,6 @@ app.initializers.add('flarum-flags', () => {
// Expose compat API
import flagsCompat from './compat';
import { compat } from '@flarum/core/forum';
import Post from 'flarum/common/models/Post';
Object.assign(compat, flagsCompat);

View File

@@ -1,15 +0,0 @@
import Model from 'flarum/common/Model';
class Flag extends Model {}
Object.assign(Flag.prototype, {
type: Model.attribute('type'),
reason: Model.attribute('reason'),
reasonDetail: Model.attribute('reasonDetail'),
createdAt: Model.attribute('createdAt', Model.transformDate),
post: Model.hasOne('post'),
user: Model.hasOne('user'),
});
export default Flag;

View File

@@ -0,0 +1,25 @@
import Model from 'flarum/common/Model';
import type Post from 'flarum/common/models/Post';
import type User from 'flarum/common/models/User';
export default class Flag extends Model {
type() {
return Model.attribute<string>('type').call(this);
}
reason() {
return Model.attribute<string | null>('reason').call(this);
}
reasonDetail() {
return Model.attribute<string | null>('reasonDetail').call(this);
}
createdAt() {
return Model.attribute('createdAt', Model.transformDate).call(this);
}
post() {
return Model.hasOne<Post>('post').call(this);
}
user() {
return Model.hasOne<User | null>('user').call(this);
}
}

View File

@@ -0,0 +1,17 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// 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/*/*/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/core/*": ["../vendor/flarum/core/js/dist-typings/*"]
}
}
}