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

规范类型系统 #1

Open
jjyyxx opened this issue Apr 26, 2018 · 0 comments
Open

规范类型系统 #1

jjyyxx opened this issue Apr 26, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@jjyyxx
Copy link
Member

jjyyxx commented Apr 26, 2018

鉴于目前的简记法能够提供强类型的参数匹配,普通记法也应当能实现类似功能。所以我提议建立一个简易的类型系统,允许用户在每一个函数前附加一个类似jsdoc的注释(可缺省),格式大致如下

/**
 * optional desc which wil be ignored
 * @param {Subtrack} param1 optional desc which wil be ignored
 * @param {Subtrack} param2 optional desc which wil be ignored
 * @alias xxxx (目前考虑用 ;分隔优先级声明,待议)
 * @alias yyyy
 * @other tags which wil be ignored
 */

注意到alias的声明中包含了对对应参数的类型限制,因此@param@alias可以考虑相互配合

  1. 无简记的函数,仅依据param判定类型,无则任意类型
  2. 有简记的函数,如果有param,简记法声明时可以不再声明约束类型,1: subtrack 简化为 1
  3. 有简记的函数,如果无param,简记法声明中的类型约束可以作为函数的类型

以上是我的一些想法,应该属于非破坏性的功能增强。

附注:类似tm的文档语法的设计思想,设计尽量贴近jsdoc语法,但为最高效地为tm函数服务,而作出少量改变,目前包括:

  • 覆写了jsdoc对alias的定义

  • 限制了有效的类型格式

@jjyyxx jjyyxx added the enhancement New feature or request label Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant