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
Background: we've talked about placeholder types, the idea is you need to talk about a type which exists even though you don't know all of the contents before you use it.
Normally that's an issue WRT conflicting environments. You can do an interface but they have flaws like
interfaceBuffer{}letx: Bufferfunctionfoo(x:Buffer){}// all work though :(foo(1)foo("")foo({})
A proposal:
placeholdertypeFoo
which is verbose for searchability, it can be declared but not assigned
and you can have many constraints which are intersected:
placeholdertypeFooextendsstringplaceholdertypeFooextendsnumber// fails because foo is a neverconsta: Foo=12
Is this bascially an existential type? Is this a new type kind
Ish. It needs to act like a type param in assignability. Needs to be able to do the same circularity checking for type aliases and type parameters.
Has to have all the same interface validation too. Because it does all that, it needs to anticipate being a class, interface or type - it needs to encode a lot of different data.
So I opted for a new 'type kind' - which is
What's TODO?
Generics is tricky (higher kinded types ish)
placeholdertypefoo<T>extendsstring
Could this be figured out at bind time? And at check time we know if there's an implementation. Can it be resolved before figuring out where it is about it?
That's already what it does.
Foo isn't higher kinded, but once resolved it is - you can know whether there was an implementation or not post bind-time.
placeholdertypeFoo<T>extends{x: T}
If an implementation exists, you can discard all placeholder resolution logic and just perform consistency checks on the declarations.
Lots of people want to bikeshed on the name placeholder - maybe defer?
Q: How does this relate to placeholder types for values
Lots of deps have a hard dep on Node.js types (often for Buffer) - instead of including all of Node.js (and changing your entire environment)
then you can instead declare "I use buffer" and your package does not need to include all of types for environment
Also, the point about placeholder types being higher-kinded-ish has definitely peaked my interest! Some notion of higher-kinded types could address a few of TypeScript's limitations, including things like #32523 and #26242. I'm not sure if placeholder types would help in either of those two cases specifically, but it's nice to see some thinking in the higher-kinded area. 🙂
unknown
annotation on catch clause variables#36775
unknown
, can you writeany
?never
?unknown
andany
?Placeholder Types
#31894
Thanks to @orta for helping with the notes here
Background: we've talked about placeholder types, the idea is you need to talk about a type which exists even though you don't know all of the contents before you use it.
Normally that's an issue WRT conflicting environments. You can do an
interface
but they have flaws likeA proposal:
which is verbose for searchability, it can be declared but not assigned
Fails! You need to have an implementation
Now it's legal.
You can constrain the placeholder:
and you can have many constraints which are intersected:
Ish. It needs to act like a type param in assignability. Needs to be able to do the same circularity checking for type aliases and type parameters.
Has to have all the same interface validation too. Because it does all that, it needs to anticipate being a class, interface or type - it needs to encode a lot of different data.
So I opted for a new 'type kind' - which is
Generics is tricky (higher kinded types ish)
Could this be figured out at bind time? And at check time we know if there's an implementation. Can it be resolved before figuring out where it is about it?
Foo
isn't higher kinded, but once resolved it is - you can know whether there was an implementation or not post bind-time.Lots of people want to bikeshed on the name
placeholder
- maybedefer
?Q: How does this relate to placeholder types for values
Think some of those ideas could be re-used
Or examples:
Q: What kind of problems does this solve?
Lots of deps have a hard dep on Node.js types (often for
Buffer
) - instead of including all of Node.js (and changing your entire environment)then you can instead declare "I use buffer" and your package does not need to include all of types for environment
are real-world cases across ImmutableJS, Vue, etc.
Q: How do we deal with a world where people keep moving things into the global scope, can I do a placeholder module?
e.g. something like?
You also need placeholder values (this module has this value which has this type). Are we making higher order namespaces?
Note: Buffer is both exported by node global and a buffer types, and the global is deprecated
Q: Do We want a way to assert a module has a specific type?
Idea: We want to declare a type alias which defaults to something. Today you can only have one, but it'd be great to have multiple.
Some of the implementation details for this can be done offline.
Variadic Tuples
#5453
Current work: can now have any number of generic placeholders in the middle of a tuple
If you instantiate one of these with an un-fixed array type, the type unions with subsequent element types to create a rest type.
With some inference smarts, can now write
Inference rules make sense, but get hairy.
Open String Union Types
#29729
boolean | number | any
- same deal?keyof
keyof
on that thing makes sense.string
is the samestring
no matter where you use it.string
, but this one with auto-complete"out of time
The text was updated successfully, but these errors were encountered: