TypeScript 缺失数组类型约束中可选属性的IntelliSense ```markdown 缺失数组类型约束中可选属性的IntelliSense ```

ax6ht2ek  于 9个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(123)

Bug报告

🔎 搜索词

🕗 版本与回归信息

搜索了一个相关的问题:#30058

⏯ Playground链接

带有相关代码的Playground链接

💻 代码

  1. type ZZZ = {
  2. bar?: number,
  3. foo: string
  4. }
  5. function test<T extends ZZZ>(c: T) {
  6. }
  7. function testArr<T extends ZZZ[]>(c: T) {
  8. }
  9. // case 1:
  10. test({
  11. // foo got intellisense
  12. // bar got intellisense
  13. })
  14. // case 2:
  15. test({
  16. foo: '333',
  17. // bar got intellisense
  18. })
  19. // case 3:
  20. testArr([
  21. {
  22. foo: '111',
  23. // bar got no intellisense
  24. },
  25. ])
  26. // case 4:
  27. testArr([
  28. {
  29. // foo got intellisense
  30. // bar got intellisense
  31. }
  32. ]);

🙁 实际行为

案例3缺少选项属性的IntelliSense bar

🙂 预期行为

显示属性的完成情况 bar

kcwpcxri

kcwpcxri1#

我想要演示数组中的几个元素如何影响自动补全:

  1. type ZZZ = {
  2. foo: number;
  3. bar?: number;
  4. baz?: number;
  5. }
  6. function testArr<T extends ZZZ[]>(c: T) {
  7. }
  8. // case 1:
  9. testArr([
  10. {
  11. foo: 1,
  12. baz: 1
  13. },
  14. {
  15. foo: 1,
  16. //baz has autcomplete
  17. //bar missing autocomplete
  18. }
  19. ]);
  20. // case 2:
  21. testArr([
  22. {
  23. foo: 1,
  24. //Neither baz or bar have autcomplete
  25. },
  26. {
  27. foo: 1,
  28. //Neither baz or bar have autcomplete
  29. }
  30. ]);
  31. // case 3:
  32. testArr([
  33. {
  34. foo: 1,
  35. //bar and baz appear in autcomplete
  36. },
  37. {
  38. foo: 1,
  39. bar: 1,
  40. //bar and baz appear in autcomplete
  41. },
  42. {
  43. //bar, baz and foo appear in autocomplete
  44. }
  45. ]);

playground链接

展开查看全部

相关问题