-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Design Meeting Notes, 6/12/2020 #39054
Comments
@DanielRosenwasser Just out of curiosity, why does I recall working with APIs in the past that would benefit from the ability to type things like "any number of strings, followed by exactly one function". |
Also, with this new work on type-level tuple transformations, I suspect #27995 will come up more often... 🤔 Time will tell I guess. |
(From microsoft/TypeScript-DOM-lib-generator#858 (comment))
Could this be elaborated more?
Should a way be introduced? Merging static side of class sounds like a general language issue.
As far as I remember, I suggested same in the past and it was rejected because it would introduce tons of unnecessary names to the global namespace. It means if you type |
@treybrisbane we could in theory type that when assigning from a fixed tuple to that type, but then it ceases to be useful; for example, there's no (clean) way to know where to grab the last element from. @ahejlsberg can answer the capabilities a bit better since he's working on the PR. |
@saschanaz (CC @sandersn)
From my understanding, they're not declared as if they were classes. For example, I can define another |
That's true, although I think the specific behavior doesn't affect TS users as it's an error in TS. Or does it? |
@treybrisbane With the PR I'm working on you'll be able to model a function taking any number of strings followed by a function as declare function foo<T extends string[]>(...args: [...T, () => void]): T; This will indeed infer appropriate strings-only tuple types for foo(() => {}); // []
foo('hello', 'world', () => {}); // [string, string]
foo('hello', 42, () => {}); // Error, number not assignable to string The one kind of type you won't be able to represent is something like |
@ahejlsberg Makes sense. Thanks for the explanation! 🙂 |
Custom JSX Fragment Factories
#38720
We didn't give a way to specify the factory for fragments the same way we do for regular tags
Fragments are a little unique in that there is no tag name. It's just assumed to be
React.Fragment
Wait, what is a fragment?
We didn't know at the time how fragments were going to be used.
Conclusion: Approve pending another review.
Use
declare class
when Generating Typesmicrosoft/TypeScript-DOM-lib-generator#858
#39044
class
esglobalThis
Node Factory PR
#35282
src/compat/deprecations.ts
await
after the fact.Higher Order Tuple Spreads
#5453
[string, ...T, number]
T
is a tuple with a fixed length ([boolean, boolean]
), this just flattens to a fixed tuple. ([string, boolean, boolean, number]
).T
has an open length (boolean[]
), the rest element is created at the end: ([string, ...(boolean | number)[]]
)[string, ...T, number]
[...T]
- important becauseT
might be constrainted to a readonly array (e.g.T extends readonly any[]
).BUT, with this, you can have a rest parameter whose type is a tuple with multiple rest positions.
Can represent a function that takes numbers at both the beginning and the end.
bind
.function foo<T extends unknown[]>(x: [] | T)
readonly [...T]
instead.The text was updated successfully, but these errors were encountered: