Skip to content

Commit

Permalink
feat: 1.0.0
Browse files Browse the repository at this point in the history
Release-As: 1.0.0
  • Loading branch information
missannil committed Nov 25, 2023
0 parents commit 14c418f
Show file tree
Hide file tree
Showing 236 changed files with 17,054 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
/**
* 由名称:与插件 Prettier ESLint https://marketplace.visualstudio.com/items?itemName=rvest.vs-code-prettier-eslint 冲突
*/
// 'editor.codeActionsOnSave': {
// 'source.fixAll.eslint': true
// },
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "eslint-plugin-tsdoc"],

rules: {
"tsdoc/syntax": "warn",
// 0 1 2 对应 off warn error
// "@typescript-eslint/no-inferrable-types": 2, //禁止对初始化为数字、字符串或布尔值的变量或参数进行显式类型声明
"@typescript-eslint/explicit-member-accessibility": 2, // 类要显示声明访问权限修饰符 public private protected
"@typescript-eslint/no-var-requires": 0, // 不运行使用require的方式引入模块
"no-prototype-builtins": 0, // 不接受 Object.prototype的方法调用,需要用 call的方法调用
"@typescript-eslint/no-explicit-any": 0, // 不可以显示的写any
"@typescript-eslint/explicit-module-boundary-types": 0, // 函数返回和参数都应该明确写类型
"@typescript-eslint/no-unused-vars": 1, // 没有使用的变量,
"@typescript-eslint/ban-types": 0, // 不可以使用特殊的类型 比如 {}
"@typescript-eslint/no-namespace": 0, // 不可以使用namespace
"prefer-const": 1, // 为什么不写const 呢?
"@typescript-eslint/no-empty-interface": 2, // 不可以写空接口
"no-mixed-spaces-and-tabs": "off",
"@typescript-eslint/ban-ts-comment": 0,
"padding-line-between-statements": "off",
"@typescript-eslint/padding-line-between-statements": [
"warn",
{ blankLine: "always", prev: "const", next: "expression" },
{ blankLine: "always", prev: "export", next: "*" },
{ blankLine: "always", prev: "*", next: "class" },
{ blankLine: "always", prev: "class", next: "*" },
{ blankLine: "always", prev: "*", next: "return" },
{ blankLine: "always", prev: "expression", next: "*" },
{ blankLine: "always", prev: "*", next: ["interface", "type"] },
{ blankLine: "always", prev: ["interface", "type"], next: "*" },
],
"complexity": ["error", 10],
},
};
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
50 changes: 50 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 工作流名称
name: release-please
on:
push:
branches:
- main
# 权限
permissions:
contents: write
pull-requests: write
# 工作流程
jobs:
# 第一个工作
release-please:
# 运行环境
runs-on: ubuntu-latest
steps:
# 使用哪个action
- uses: google-github-actions/release-please-action@v3
# action id 便于其他流访问
id: release
with:
#项目类型
release-type: node
#包名称
package-name: annil
# 以下为npm发布逻辑
- uses: actions/checkout@v3
# if语句为真运行actions。
# 当id为release的action结果为created时(即并入了main分支时)
if: ${{ steps.release.outputs.release_created }}
# 开启node坏境
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: npm i husky -D
if: ${{ steps.release.outputs.release_created }}
- run: npm i
if: ${{ steps.release.outputs.release_created }}
# 打包
- run: npm run build
if: ${{ steps.release.outputs.release_created }}
# 发布
- run: npm publish
env:
# 在项目-settings-secrets and variables-actions 下建立Environment secrets,名字为NPM_TOKEN,值为npm下建立的密钥。
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test PR

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: test lint
run: npx eslint . --max-warnings=0
- name: Install dprint
run: curl -fsSL https://dprint.dev/install.sh | sh
- name : test format
run: npx dprint check
- name : test types
run: npx tsc --noEmit
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Node.js
**/*.js
**/node_modules
*.map
# .eslintcache
!ewm.config.js
!rollup.config.js
!.eslintrc.js
!.prettierrc.js
!commitlint.config.js
# !miniprogram_npm/**/*.js
dist
project.private.config.json
!jest.config.js
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"editor.defaultFormatter": "dprint.dprint",
"[jsonc]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "dprint.dprint"
},
// or specify per language, for example
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true
}
}
Empty file added CHANGELOG.md
Empty file.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013-present, Yuxi (Evan) You

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### 介绍

原生开发微信小程序(typescript-wechat-mini-program)

140 changes: 140 additions & 0 deletions SomeQuestions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// 泛型约束的一些特性

import type { Func } from "hry-types/src/Misc/Func";

/**
* 1. 泛型无默认值有字段提示
*/
declare function foo<T extends Partial<{ str: string; num: number; bool: boolean }>>(opts: T): void;

foo({
str: "str",
// 键入n有字段提示num
});

/**
* 2. 泛型有默认值,只有首key类型提示
*/
declare function foo1<T extends Partial<{ str: string; num: number; bool: boolean }> = {}>(opts: T): void;

foo1({
bool: false, // 首key,有字段提示,即输入b,提示bool
// 键入n无字段提示num
});

type ValueIsFunc = Record<string, Func>;
/**
* 3. 泛型字段为`ValueIsFunc`时,若要通过this相互间引用且实现自动类型推导,需要加默认值。(不加默认值需手动声明返回类型)
*/

declare function foo2<
TComputed extends ValueIsFunc = {},
ComputedReturnType = { [k in keyof TComputed]: ReturnType<TComputed[k]> },
>(
obj: {
computed: TComputed;
} & ThisType<ComputedReturnType>,
): void;

foo2({
computed: {
str() {
return "a";
},
bool() {
return !!this.str; // 去除 `TComputed extends ValueIsFunc = {}`的默认值`{}`, str为any
},
},
});

type Obj = {
Cuser: User;
Cstr: string;
Cnum: number;
CliteralNum: 123;
};

type User = {
name: string;
age: number;
};

/**
* 4. TComputed有具体字段约束时,相互引用会报错,要显示声明返回类型 采取这个方法写计算属性。
*/
declare function foo3<
TComputed extends { [k in keyof Obj]?: () => Obj[k] },
ComputedReturnType = { [k in keyof TComputed]: TComputed[k] extends Func ? ReturnType<TComputed[k]> : never },
>(
obj: {
computed: TComputed;
} & ThisType<ComputedReturnType & { user: User }>,
): void;

foo3({
computed: {
Cuser(): User {
return this.user;
},
Cnum(): number {
return this.Cuser.age;
},
Cstr(): string {
return this.user.name;
},
CliteralNum() {
return 123;
},
name() {
return this.user.name; // 没有引用到其他计算属性且没被其他计算属性引用,可以不显示声明返回类型。
},
},
});

type validatorOfKey<
TComputed extends object,
TCompare extends Record<PropertyKey, any>,
> = {
[
k in keyof TComputed as k extends keyof TCompare ? never : k
]: `⚠ The field is incorrect ⚠`;
};

type validatorOfValue<TComputed extends object, TCompare extends Record<PropertyKey, any>> = {
[
k in keyof TComputed as TComputed[k] extends (() => TCompare[k]) ? never : k
]: `⚠ The value is incorrect ⚠`;
};

/**
* 5. 通过验证key和value验证器,没有提示,又时需要加const,还要显示声明返回类型。不如4
*/
declare function foo4<
TComputed extends ValueIsFunc = {},
ComputedReturnType extends object = {
[k in keyof TComputed]: TComputed[k] extends Func ? ReturnType<TComputed[k]> : never;
},
>(
obj: {
computed: TComputed & validatorOfKey<TComputed, Obj> & validatorOfValue<TComputed, Obj>;
} & ThisType<ComputedReturnType & { user: User }>,
): void;

foo4({
computed: {
Cuser(): User {
return this.user;
},
// @ts-expect-error 类型错误 name 是string
Cstr(): number {
return this.user.age;
},
CliteralNum() {
return 123 as const;
},
// @ts-expect-error 超出字段
xxx() {
return 123;
},
},
});
20 changes: 20 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [2, "always", [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
// 增加 deps (修改依赖) 符合 please-release 提交规范
"deps",
]],
},
};

0 comments on commit 14c418f

Please sign in to comment.