defineCustomElement.test-d.ts 1.2 KB

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