You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creation of a type Tuple that only accepts the structure [Element, ItsAttributes] :
interfaceMyComponents{Container: {fluid?: boolean},Text: {text?: stringclassName?: stringsize: number}}//Get the keys of the list of my componentstypeElement=keyofMyComponents//Create a mapped tuple type [Element, Attributes]// and the attributes depend on the elementexporttypeTuple={[ElementinkeyofMyComponents] : readonly[Element,MyComponents[Element]]}[keyofMyComponents]consttuple1 : Tuple=['Text',{size : 3}]//Okayconsttuple2 : Tuple=['Text',{fluid : true}]//Throw error
Creation of the editor with all possibles combinations :
After typing first element, the second element shows all possible attributes (even the wrong ones). When I choose a wrong one Typescript also knows it's incompatible
Example:
['Container',{/* It currently shows all attributes in MyComponents : fluid, text, className, size */}]
🙂 Expected behavior
After typing first element (Container, Text, etc), Typescript shows only the attributes that belongs to it.
Example:
['Container',{/* Should only show fluid */}]
The text was updated successfully, but these errors were encountered:
typetuple=['1','2']|['a','b']consttest: tuple=['a','']//<- autocomplete on 2nd field// actual options - 'b' | '2' ('2' will cause a type error)// expected options - 'b'
Also it'd be great if functions had this behavior as well:
Bug Report - Intellisense/Auto completion
Typescript can't infer tuple's second element type depending on first one's type
🔎 Search Terms
🕗 Versions
v4.2.3
v1.55.2
🎈 Context
The goal is to build a text editor with a structure like
Tuple = [Element, ItsAttributes, ...Tuple[]] (with mapped tuples & recursivity)
This will help when I need to construct data with this format
⏯ Payground link
Playground link
💻 Code
Creation of a type Tuple that only accepts the structure [Element, ItsAttributes] :
Creation of the editor with all possibles combinations :
How to use it ?
🙁 Actual behavior
After typing first element, the second element shows all possible attributes (even the wrong ones).
When I choose a wrong one Typescript also knows it's incompatible
Example:
🙂 Expected behavior
After typing first element (Container, Text, etc), Typescript shows only the attributes that belongs to it.
Example:
The text was updated successfully, but these errors were encountered: