Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
07akioni opened this issue Jun 2, 2022 · 6 comments · Fixed by #6216
Closed

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

07akioni opened this issue Jun 2, 2022 · 6 comments · Fixed by #6216

Comments

@07akioni
Copy link
Contributor

07akioni commented Jun 2, 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

@07akioni
Copy link
Contributor Author

07akioni commented Jun 2, 2022

in ts 4.6 it works

image

@liulinboyi
Copy link
Member

liulinboyi commented Jun 2, 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.

@zhmushan
Copy link
Contributor

zhmushan commented Jun 5, 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] }

@yyx990803
Copy link
Member

/cc @pikax

@07akioni
Copy link
Contributor Author

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

@07akioni 07akioni reopened this Jun 12, 2022
yyx990803 pushed a commit that referenced this issue Jul 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
fix #6052
chrislone pushed a commit to chrislone/core that referenced this issue Feb 4, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants