defineCustomElement.test-d.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { defineCustomElement } from 'vue'
  2. import { expectType, describe } from './utils'
  3. describe('inject', () => {
  4. // with object inject
  5. defineCustomElement({
  6. props: {
  7. a: String
  8. },
  9. inject: {
  10. foo: 'foo',
  11. bar: 'bar'
  12. },
  13. created() {
  14. expectType<unknown>(this.foo)
  15. expectType<unknown>(this.bar)
  16. // @ts-expect-error
  17. this.foobar = 1
  18. }
  19. })
  20. // with array inject
  21. defineCustomElement({
  22. props: ['a', 'b'],
  23. inject: ['foo', 'bar'],
  24. created() {
  25. expectType<unknown>(this.foo)
  26. expectType<unknown>(this.bar)
  27. // @ts-expect-error
  28. this.foobar = 1
  29. }
  30. })
  31. // with no props
  32. defineCustomElement({
  33. inject: {
  34. foo: {
  35. from: 'pbar',
  36. default: 'foo'
  37. },
  38. bar: {
  39. from: 'pfoo',
  40. default: 'bar'
  41. }
  42. },
  43. created() {
  44. expectType<unknown>(this.foo)
  45. expectType<unknown>(this.bar)
  46. // @ts-expect-error
  47. this.foobar = 1
  48. }
  49. })
  50. // without inject
  51. defineCustomElement({
  52. props: ['a', 'b'],
  53. created() {
  54. // @ts-expect-error
  55. this.foo = 1
  56. // @ts-expect-error
  57. this.bar = 1
  58. }
  59. })
  60. })