TC39 Updates
TC39 update
globalThis to stage 4
New in stage 3: Promise.any, String#replaceAll, formalized for-in object iteration
New in stage 2: Map#upsert
New in stage 1: A bunch of stuff
Readonly collections
Records and tuples #{ x: 0 }
Optional Chaining and Narrowing
#33736
Have been iterating on feedback around narrowing optional chaining.
type Header = { headers : Record < string , any > } ;
type Options = { config : any } ;
function getHeader ( input : Header | Options , key : string , def ?: any ) {
return ( 'headers' in input ? input . headers [ key ] : undefined ) || def ;
}
Today, in adds a property to the original type.
type Header = { headers : Record < string , any > } ;
type Options = { config : any } ;
function getHeader ( input : Header | Options , key : string , def ?: any ) {
return input . headers ?. [ key ] ?? def ;
}
Uhh.
Correcting Loose Assignability Rules for Intersections to Index Signatures
#32484
declare let s : { a : string } & { b : string } ;
declare let t : { [ key : string ] : string } ;
t = s ;
Our assignability rules say that if any constituent of an intersection is assignable to an index signature, the types are assignable.
Happens when you work on dictionary-like objects.
We don't have a concrete rule yet, but have been observing some pain.
Technically even { a: string } being assignable to Record<string, string> is wrong because { a: string } can contain more properties than it declares.
Otherwise it would be extremely difficult to deal with dictionary-like bags of properties.
Probably 3.8-bound at earliest.
devDependencies in @types Packages
microsoft/types-publisher#655
Problem: today, an app can't have both @types/node and @types/react-native in the same dependency tree.
This is because they both define globals.
Solution 1: "Just let them coincide"?
Solution 2: Give a blessed configuration for web and for react native?
Solution 3: Be careful about the @types in your dependency trees.
But then other problems...
Problem: a library that wraps both react and react-native components can't have a dependency on either !
The whole situation is a mess: react depends on react-dom, react-native depends on react, some of these APIs use Buffers when you're in Node.
What about a forward-declaration mechanism?
Are there libraries with these problems in DefinitelyTyped otherwise?
With Placeholder Type Declarations #31894 , is the idea that you just say "there's a Buffer"?
Yes, "don't care what it is, but I'll take one!"
Anything else you can't do with interfaces instead of forward declarations?
Well you can't forward-declare a type alias to a union type or tuple.
IteratorResult ended up with this issue, meant we needed to do typesVersions.
What happened last time we chatted about placeholder types?
Tried to see if we could break the feature down into different functionality.
What about conditional inclusion?
Something like type polyfills?
Swift potentially has something like this.
But how do you explore versioning?
Feels like this has turned into a discussion about many different problems.
Original problem: devDependency to check on DefinitelyTyped, let users install the correct peer types.
Does this stand up to other future solutions?
Unclear if this paints us into a corner.
How do you tell users "you have to also install @types/node now"?
Also, there's an excludeTypes (Placeholder Type Declarations #31894 ) - a way to say "no, please don't add @types/node from being included".
But someone asked for those types to be included indirectly.
Aside: .NET has had this problem since...forever and solved it with...not working correctly? :(
What if @types packages could fulfull lib settings, and then we could provide lib?
Conclusion: We will scope down and isolate the concerns in a separate meeting.
Also, of all the types that rely on @types/node, what do they rely on?
TC39 Updates
globalThisto stage 4Promise.any,String#replaceAll, formalized for-in object iterationMap#upsert#{ x: 0 }Optional Chaining and Narrowing
#33736
Have been iterating on feedback around narrowing optional chaining.
Today,
inadds a property to the original type.Uhh.
Correcting Loose Assignability Rules for Intersections to Index Signatures
#32484
{ a: string }being assignable toRecord<string, string>is wrong because{ a: string }can contain more properties than it declares.devDependenciesin@typesPackagesmicrosoft/types-publisher#655
@types/nodeand@types/react-nativein the same dependency tree.@typesin your dependency trees.reactandreact-nativecomponents can't have a dependency on either!devDependencyspecifies that a package works with these packages,devDependencys means that you can't use types from these in output positions.Buffers when you're in Node.IteratorResultended up with this issue, meant we needed to dotypesVersions.devDependencyto check on DefinitelyTyped, let users install the correct peer types.@types/nodenow"?excludeTypes(Placeholder Type Declarations #31894) - a way to say "no, please don't add@types/nodefrom being included".@typespackages could fulfulllibsettings, and then we could providelib?@types/node, what do they rely on?