Skip to content

TypeScript-specific feedback & thoughts #3

@DanielRosenwasser

Description

@DanielRosenwasser

I'd like to keep the other breaking changes feedback thread scoped to breaking changes. Here's some TypeScript-specific feedback which doesn't need to be addressed immediately, but which stood out to me while exploring the package.

Generic type parameter for props (P) should come before data (D)

This was the biggest footgun I made when I worked on the Vue .d.ts files the first time. I specified Props first rather than Data and I believe that Vue 3.0 shouldn't make the same mistake. When it comes to components, almost all of them will use props and have a harder time specifying them than data.

Generic type parameter P has defaults

There are a lot of instances of P = Data (which is really just P = Record<string, any>). Is there any reason that's necessary? I feel like the class-based API doesn't really need this since, on the whole, it's mostly inferred, though I could be missing something.

Vue is currently non-generic

Vue (from packages/vue) currently has a different API than Component (from packages/core). Specifically, Vue is generic and seems to be the "full-featured" version of the component. You already mentioned that things are in a state of progress, but is the difference mostly about mount points depending on target runtimes (i.e. DOM vs. native vs. ...)?

.d.ts files are produced using dts-bundle

dts-bundle throws all of your modules into a single global file with several ambient module declarations. The problem with ambient module declarations is that they are in the global scope in the first place. If you have multiple versions of Vue loaded up by a project (via a separate dependency probably), then two ambient modules for the path @vue/renderer-dom can conflict, which can cause problems.

Mitigations

We should consider looking into API Extractor to produce .d.ts files that describe top-level APIs for Vue.

Build process could leverage project references.

Right now it appears that there's a custom TypeScript build that happens, and it seems like that's an all-or-nothing approach. Depending on whether build times are an issue, we could potentially leverage project references. If there's a reason you can't use them, it'd be helpful for our team to get an idea of the challenges. 😃

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions