-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design Meeting Notes, 6/21/2023 #54735
Comments
Surely this was supposed to be |
If we’re classifying destructors as a kind of disposal method, then technically C# has either two or three depending on how you count 😉 (destructor + |
C# has // C#
class MySafeNativeHandle : IDisposable
{
private IntPtr unsafeHandle;
public SafeNativeHandle(IntPtr unsafeHandle)
{
this.unsafeHandle = unsafeHandle;
}
// implicit resource management
~SafeNativeHandle()
{
this.DisposeCommon();
}
// explicit resource management
public Dispose()
{
GC.SuppressFinalize(this);
this.DisposeCommon();
}
private DisposeCommon()
{
if (this.unsafeHandle !== IntPtr.Zero)
{
ReleaseHandle(this.unsafeHandle);
this.unsafeHandle = IntPtr.Zero;
}
}
} // ts
class MySafeNativeHandle implements Disposable {
#unregisterToken = {};
#holder: { handle: number; };
constructor(unsafeNativeHandle: number) {
this.#holder = { value: unsafeHandle; };
// register for finalization
MySafeNativeHandle.#finalizer.register(this, this.#holder, this.#unregisterToken);
}
// implicit resource management
static #finalizer = new FinalizationRegistry<{ handle: number }>(holder => {
MySafeNativeHandle.#disposeCommon(holder);
});
// explicit resource management
[Symbol.dispose]() {
MySafeNativeHandle.#finalizer.unregister(this.#unregisterToken);
MySafeNativeHandle.#disposeCommon(this.#holder);
}
static #disposeCommon(holder: { handle: number }) {
if (holder.handle !== 0) {
releaseHandle(holder.handle);
holder.handle = 0;
}
}
} |
I seem to recall that C# has a |
That is for cases when you want to support subclassing. The // C#
class MySubclassableSafeNativeHandle : IDisposable
{
private IntPtr unsafeHandle;
public MySubclassableSafeNativeHandle(IntPtr unsafeHandle)
{
this.unsafeHandle = unsafeHandle;
}
// implicit resource management
~MySubclassableSafeNativeHandle ()
{
this.Dispose(false);
}
// explicit resource management
public Dispose()
{
GC.SuppressFinalize(this);
this.Dispose(true);
}
protected virtual Dispose(bool disposing)
{
if (this.unsafeHandle !== IntPtr.Zero)
{
ReleaseHandle(this.unsafeHandle);
this.unsafeHandle = IntPtr.Zero;
}
}
} Subclasses can override interface FinalizationRegistry<T> {
register(target: object, heldValue: T, unregisterToken?: object): void;
} The |
- Don't specify TS `moduleResolution` In the next release, it will be an error to set module or moduleResolution to node16 and the other to ad istinct value. See microsoft/TypeScript#54735 `module=Node16` implies `moduleResolution=node16` - Do not preserve quoted properties (prettier, rome) We no longer need to preserve quoted properties in the codebase. The last object-map was converted to a Map.
- Don't specify TS `moduleResolution` In the next release, it will be an error to set module or moduleResolution to node16 and the other to ad istinct value. See microsoft/TypeScript#54735 `module=Node16` implies `moduleResolution=node16` - Do not preserve quoted properties (prettier, rome) We no longer need to preserve quoted properties in the codebase. The last object-map was converted to a Map.
Restricting Mixing
module
andmoduleResolution
when one isnode*
#54567
module
andmoduleResolution
.moduleResolution
is somewhat straightforward; notmodule
.moduleResolution
is strictly path lookups,module
decides emit, and is driven by a localpackage.json
, etc.--moduleResolution node16 --module esnext
--moduleResolution node16 --module esnext
--moduleResolution bundler
--module esnext --moduleResolution node16
?module
has to benode16
as well has no downsides.@tsconfig
packages use an invalid mix!--module node16 --moduleResolution node
!!!!!package.json
supported multiple values for thetypes
field depending on path/directory. - but by the time Node runtimes broadly support this, it will be a bit.@tsconfig
Naming of
Diposable
#54505 (comment)
Disposable
vs.DisposableLike
.Iterator
for iterator methods, and felt like there was some agreement in committee about placement being off; but ultimately JS can't really support extension methods, and needed an instance and constructor with a prototype so that these Iterator objects can have methods called on them.Disposable
feels... different? It's a one-and-done concept. There's no chaining.DisposableStack
.Drop
,IDisposable
, ...) has more than a single method.The text was updated successfully, but these errors were encountered: