Prop required and starts with `on`'s type is broken in ts 4.7
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?
System Info
No response
Any additional comments?
No response
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.
We should report this issue to TS
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] }