Subscribe on changes!

Prop required and starts with `on`'s type is broken in ts 4.7

avatar
Jun 2nd 2022

Vue version

3.2.36

Link to minimal reproduction

nope

Steps to reproduce

index.ts

import { defineComponent } from "vue";

defineComponent({
  props: {
    onX: {
      type: Function,
      required: true,
    },
  },
  setup(props) {
    props.onX();
  },
});

package.json

{
  "name": "vue-ts",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "tsc index.ts --moduleResolution node --strict --noEmit --lib ESNext,DOM"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/types": "^7.18.4",
    "typescript": "^4.7.2",
    "vue": "^3.2.36"
  }
}

Run npm run build

What is expected?

No error

What is actually happening?

image

System Info

No response

Any additional comments?

No response

avatar
Jun 2nd 2022

in ts 4.6 it works

image
avatar
Jun 2nd 2022

It's a broken in ts 4.7.

I have some workaround:

index.ts

import { defineComponent } from "vue";

defineComponent({
  props: {
    onX: {
      type: Function,
      required: true,
    },
  },
  setup(props) {
    props.onX!();
  },
});

or

tsconfig.json

{
  "compilerOptions": {
    "strict": false
   }
}

Hope this helps.

avatar
Jun 5th 2022

I tried to change the LooseRequired to the following code and it works fine. But I don't know how to make it work with Vue.

export type LooseRequired<T> = { [P in keyof Required<T>]: T[P] }
avatar
Jun 6th 2022

/cc @pikax

avatar
Jun 12th 2022

Is there any progress? I think the problem may stop some projects migrating to ts 4.7.