Skip to content

6 - Simple Vue #172

Open
Open

Description

@g-plane
type Computed<C extends Record<string, any>> = { [P in keyof C]: ReturnType<C[P]> }
declare function SimpleVue<D, C extends Record<string, any>, M>(options: {
  data(this: {}): D,
  computed: C & ThisType<D & Computed<C> & M>,
  methods: M & ThisType<D & Computed<C> & M>
}): D & Computed<C> & M

Activity

  1. added
    answer
    en
    on Sep 8, 2020
  2. xianshenglu commented on Feb 23, 2021

    @xianshenglu
    Contributor

    Can we let this in data be accessible to other computed values or methods?

  3. tjx666 commented on Dec 18, 2023

    @tjx666

    What's the problem here?
    @so1ve @Andarist

    type Computed<C extends Record<string, (...args: unknown[]) => unknown>> = {
        [K in keyof C]: ReturnType<C[K]>;
    };
    
    declare function SimpleVue<
        D,
        C extends Record<string, (...args: unknown[]) => unknown>,
        M,
    >(options: {
        data: (this: {}) => D;
        computed: C & ThisType<Computed<C> & D & M>;
        methods: M & ThisType<M & D & Computed<C>>;
    }): D & Computed<C> & M;

    Code will work if I turn (...args: unknown[]) => unknown> to any

    image
  4. DCzajkowski commented on Sep 3, 2024

    @DCzajkowski

    @tjx666 I've had a lot of problems with using unknown in generic's extends clause, so I've always defaulted to any in that case. It's a generic narrowing, so it doesn't matter.

    However, in this case if you change (...args: unknown[]) => unknown to (...args: any[]) => any it also doesn't work.

    But if you do ((...args: any[]) => any) | (() => any), then it works.

    I don't know the reason 🤷‍♀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    6answeren

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions