Giter Club home page Giter Club logo

Comments (9)

wchrt avatar wchrt commented on May 16, 2024

生成DOTween这种直接声明文件时, $Extension不仅扩展了基类, 还扩展了每个子类, 导致冲突

from puerts.

chexiongsheng avatar chexiongsheng commented on May 16, 2024

DOTween是哪个版本呢?
unity是哪个版本呢?

from puerts.

wchrt avatar wchrt commented on May 16, 2024

Unity2019.4.5 DOTween 1.0

from puerts.

jihuayu avatar jihuayu commented on May 16, 2024

有没有独立的可复现版本。
我这边自己写了个这样的类没问题。

public class A { }
public class B : A { }
public static class C
{
    public static void pp(this A b) { }
    
    public static void pp1(this B b) { }
    
    public static void pp2(this string b) { }
}

from puerts.

chexiongsheng avatar chexiongsheng commented on May 16, 2024

我可以复现

from puerts.

jihuayu avatar jihuayu commented on May 16, 2024

感觉像是 $Extension 函数中

type $Extension<T1, T2> = {
    [P in keyof T2] : T2[P] extends (obj:T1//** 要严格相等 **//, ...args: infer P) => infer R ? (...args: P) => R : never;
}

原因是 ts 参数类型是双向协变的,导致 T1 的子类兼容 T1。

from puerts.

wchrt avatar wchrt commented on May 16, 2024

感觉像是 $Extension 函数中

type $Extension<T1, T2> = {
    [P in keyof T2] : T2[P] extends (obj:T1//** 要严格相等 **//, ...args: infer P) => infer R ? (...args: P) => R : never;
}

原因是 ts 参数类型是双向协变的,导致 T1 的子类兼容 T1。

T1确实没严格匹配上, 导致所有方法都被扩展到了不同类型里

from puerts.

jihuayu avatar jihuayu commented on May 16, 2024

还有一个问题,ts 判断类型相等靠的是判断类型里所有的 key 的类型是否相等。
所以,那一堆空类就全是相等的。
#79

from puerts.

jihuayu avatar jihuayu commented on May 16, 2024
type $Extension<T1, T2> = {
    [K in keyof T2]: Equals<ArgumentTypes<T2[K]>[0], T1> extends true ? (T2[K] extends (obj: T1, ...args: infer P) => infer R ? (...args: P) => R : never) : never;
}
type ArgumentTypes<F> = F extends (...args: infer A) => any ? A : never;
type Equals<X, Y> =
    (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;

这样应该可以解决。
不过要把 #79 这个先修了。

from puerts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.