Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vue module typings, dtslint -> tsd #43

Merged
merged 4 commits into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: Test

on:
push:
@@ -7,13 +7,13 @@ on:
branches: [main]

jobs:
lint:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run lint
- run: npm run test
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import "./mw";
import "./jquery";
import "./vue";
4,871 changes: 1,670 additions & 3,201 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"description": "TypeScript definitions for MediaWiki JS interface",
"types": "index.d.ts",
"scripts": {
"lint": "dtslint --localTs node_modules/typescript/lib .",
"test": "tsd",
"format": "prettier --write ."
},
"repository": {
@@ -14,6 +14,7 @@
"files": [
"mw",
"jquery",
"vue",
"api_params",
"index.d.ts"
],
@@ -24,13 +25,14 @@
"homepage": "https://github.com/wikimedia-gadgets/types-mediawiki#readme",
"dependencies": {
"@types/jquery": "^3.5.5",
"@types/oojs-ui": "^0.46.0"
"@types/oojs-ui": "^0.46.0",
"vue": "3.3.9"
},
"devDependencies": {
"dtslint": "^4.1.1",
"husky": "^4.3.7",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"tsd": "^0.31.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.2.2"
},
@@ -41,5 +43,13 @@
},
"lint-staged": {
"*.ts(x)?": "prettier --write"
},
"tsd": {
"compilerOptions": {
"typeRoots": [
"./node_modules/@types",
"."
]
}
}
}
4 changes: 4 additions & 0 deletions test-d/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mw;
mw.log.warn("foo");

$;
4 changes: 4 additions & 0 deletions test-d/vue.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expectType } from "tsd";
import { createMwApp, createApp } from "vue";

expectType<typeof createApp>(createMwApp);
9 changes: 0 additions & 9 deletions tslint.json

This file was deleted.

47 changes: 47 additions & 0 deletions vue/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { createApp } from "vue";

export * from "vue";

declare module "vue" {
/**
* Wrapper around {@link https://vuejs.org/api/application.html#createapp Vue.createApp} that
* adds the {@link module:vue#$i18n i18n plugin} and the error handler. These were added
* globally in Vue 2, but Vue 3 does not support global plugins.
*
* To ensure all Vue code has the i18n plugin and the error handler installed, use of
* `vue.createMwApp()` is recommended anywhere one would normally use `Vue.createApp()`.
*
* @method createMwApp
* @param {...any} args
* @return {Object} Vue app instance
* @memberof module:vue
* @see {@link https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/25026db6cc45d72ce7433d08c6632c03d0e60aee/resources/src/vue/index.js#29}
*/
export const createMwApp: typeof createApp;

interface ComponentCustomProperties {
/**
* Adds an `$i18n()` instance method that can be used in all components. This method is a
* proxy to {@link mw.message}.
*
* Usage:
* ```
* <p>{{ $i18n( 'my-message-key', param1, param2 ) }}</p>
* ```
* or
* ```
* <p>{{ $i18n( 'my-message-key' ).params( [ param1, param2 ] ) }}</p>
* ```
*
* Note that this method only works for messages that return text. For messages that
* need to be parsed to HTML, use the `v-i18n-html` directive.
*
* @param {string} key Key of message to get
* @param {...any} parameters Values for $N replacements
* @return {mw.Message}
* @memberof module:vue.prototype
* @see {@link https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/25026db6cc45d72ce7433d08c6632c03d0e60aee/resources/src/vue/i18n.js#31}
*/
$i18n: (key: string, ...parameters: any[]) => mw.Message;
}
}