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
Should we also be looking at all the places in the compiler that use {}?
Probably.
Conclusion: let's try changing the default constraint for type parameters to unknown (and also change them not to be assignable to {} (but only to unknown)).
We currently can't make changes to Node's .d.ts because of backwards-compatibility.
Ideally, we could publish one package that had all the versions in different .d.ts files.
Other situation: someone wants to use the latest features of TypeScript, but those features end up in their .d.ts files.
Proposal: typesVersions
A new field in package.json that maps versions ranges to path-mappings.
We also discussed encoding this information into file names when resolving.
Coming up with a resolution strategy seems a litle bit fuzzy.
Do you need both a types and a typesVersions field in package.json?
Yes! At least if you care about older versions of TypeScript (e.g. versions prior to whenever typesVersion was supported). In those cases, types should point to a file that supports the oldest version of TypeScript.
Does this really solve the "new types leak into my .d.ts files" issue?
Depends on what you want to do.
If your API doesn't change that much, ship stale .d.ts and maybe that's okay.
Otherwise you can write a tool that replaces types.
Is this compatible with the tagging strategy on DefinitelyTyped?
Currently the types-publisher tool looks for // TypeScript Version: X.Y on .d.ts file headers in DefinitelyTyped and tags them as tsX.Y.
We may be able to stop publishing tags.
...but it might be safer to wait a version.
How does this interact with the layouts for different package versions in DefinitelyTyped?
@andy-ms is coming up with a proposal.
Concerns about complexity, but this is meant for power-user package authors.
The text was updated successfully, but these errors were encountered:
Ooh, my issue made the design meeting! But it's #26796, not #26797. +1 to unknown being assignable to {} outside strictNullChecks; that's consistent with the idea that unknown = {} | null | undefined.
regarding changing implicit constraints from {} to unknown:
Should we also be looking at all the places in the compiler that use {}?
Probably.
Another implicit type that should be unknown is the catch clause variable, which cannot be annotated and is currently given the type-unsafe any type. Obviously changing this would also be breaking. Is it worth trying and seeing what breaks there too?
Narrowed read-only properties in functions
#9511
const
.readonly
doesn't disallow aliasing of a mutable value.const
has different semanticsreadonly
as a read-only view into some value.Aliasing means you can't guarantee other mutations
Changing implicit constraints from
{}
tounknown
#26796
We have assumptions that all type parameters (e.g.
T
) are assignable to{}
, even though an instantiation may benull
orundefined
.Really, we should say that the default constraint for all generics are
unknown
.This would definitely break stuff.
We didn't want to "rock the boat" when we shipped
strictNullChecks
by changing the constraints.unknown
at the time.{} | null | undefined
.Would want to do this in
strictNullChecks
?What about outside of
strictNullChecks
?unknown
assignable to{}
.strictNullChecks
?Should consider
unknown
the "toppest" type.Idea: we really only want new errors in the declaration, not call sites:
Should we also be looking at all the places in the compiler that use
{}
?Conclusion: let's try changing the default constraint for type parameters to
unknown
(and also change them not to be assignable to{}
(but only tounknown
)).Support for "typesVersions" redirects
#26568
.d.ts
because of backwards-compatibility..d.ts
files..d.ts
files.typesVersions
package.json
that maps versions ranges to path-mappings.types
and atypesVersions
field inpackage.json
?typesVersion
was supported). In those cases,types
should point to a file that supports the oldest version of TypeScript..d.ts
files" issue?.d.ts
and maybe that's okay.// TypeScript Version: X.Y
on.d.ts
file headers in DefinitelyTyped and tags them astsX.Y
.The text was updated successfully, but these errors were encountered: