981377660LMT / ts

ts学习
6 stars 1 forks source link

ts 函数重载时需要把变量少的、详细的放在前面,否则无法获得代码提示 #421

Open 981377660LMT opened 8 months ago

981377660LMT commented 8 months ago
  /**
   * dfs 遍历整棵线段树来得到每个时间点的答案.
   * @param initState 数据结构的初始状态.
   * @param mutate 添加编号为`mutationId`的变更后产生的副作用.
   * @param copy 拷贝一份数据结构的副本.
   * @param query 响应编号为`queryId`的查询.
   * @complexity 一共调用 **O(nlogn)** 次`mutate`,**O(n)** 次`copy` 和 **O(q)** 次`query`.
   */
  constructor(
    initState: S,
    options: {
      mutate: (state: S, mutationId: number) => void
      copy: (state: S) => S
      query: (state: S, queryId: number) => void
    } & ThisType<void>
  )
  constructor(
    initState: S,
    mutate: (state: S, mutationId: number) => void,
    copy: (state: S) => S,
    query: (state: S, queryId: number) => void
  )
  constructor(arg1: any, arg2: any, arg3?: any, arg4?: any) {
    this._initState = arg1
    if (typeof arg2 === 'object') {
      this._mutate = arg2.mutate
      this._copy = arg2.copy
      this._query = arg2.query
    } else {
      this._mutate = arg2
      this._copy = arg3
      this._query = arg4
    }
  }