Code Monkey home page Code Monkey logo

bikeshed-to-ts's People

Contributors

darionco avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

bikeshed-to-ts's Issues

[AllowShared]

I thought I filed this, but I guess I forgot.

[AllowShared]: https://heycam.github.io/webidl/#AllowShared

[AllowShared] BufferSource should be translated as BufferSource | SharedArrayBuffer.
WebGPU doesn't use it, but also:
[AllowShared] ArrayBuffer should be translated as ArrayBuffer | SharedArrayBuffer.

`new ()` should have return type

Currently IDL interfaces with constructors will generate declare vars like:

declare var GPUOutOfMemoryError: {
  prototype: GPUOutOfMemoryError;
  new ();
};

However some compiler settings (such as the ones used in gpuweb/cts) will actually consider new () to return any instead of the apparent usual default GPUOutOfMemoryError (I'm not exactly sure why), causing linter errors. Would be best to write the return type explicitly I think.

declare var GPUOutOfMemoryError: {
  prototype: GPUOutOfMemoryError;
  new (): GPUOutOfMemoryError;
};

Consider using some sorting so that reordering in the spec doesn't churn the types

Just now I was doing the manual diff between the handwritten and generated types for WebGPU, and realized (toward the end) it is going to end up being somewhat painful when we reorder IDL chunks in the spec, which I expect we will do as we edit the spec.

We could avoid churn by doing some sorting of the top level items, either just alphabetically or by (type, name) tuple (where type is enum, dictionary, interface, etc.)

Mixins shouldn't generate nominal typing

This code from the WebGPU spec:

interface mixin NavigatorGPU {
    [SameObject] readonly attribute GPU gpu;
};
Navigator includes NavigatorGPU;

generates:

  interface Navigator {
    /**
     * Nominal type branding.
     * https://github.com/microsoft/TypeScript/pull/33038
     * @internal
     */
    readonly __brand: "Navigator";
    readonly gpu: GPU;
  }

but shouldn't make this externally-defined interface suddenly become nominally typed:

  interface Navigator {
    readonly gpu: GPU;
  }

IDL sequence should be Iterable, not Array

WebIDL sequences are (I think) equivalent to TypeScript Iterables - the WebIDL conversion rules from JS will iterate the value to produce an array. For example:

dictionary GPUBindGroupLayoutDescriptor : GPUObjectDescriptorBase {
    required sequence<GPUBindGroupLayoutEntry> entries;
};

generates:

  interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase {
    entries: Array<GPUBindGroupLayoutEntry>;
  }

but should generate:

  interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase {
    entries: Iterable<GPUBindGroupLayoutEntry>;
  }

`declare var` for WebIDL `interface` should always have `new ()`

declare var for WebIDL interfaces without constructors currently omit the new () definition:

declare var GPUDevice: {
  prototype: GPUDevice;
};

However, this prevents expressions like mydevice instanceof GPUDevice from being valid.
A new () method should be added to the generated var.

Upstream, TypeScript's built-in types would do this:

declare var GPUDevice: {
  prototype: GPUDevice;
  new (): GPUDevice;
};

However, if there is no constructor present in the IDL, then the constructor exists but will always throw. Hence, I think the generator could optionally write:

declare var GPUDevice: {
  prototype: GPUDevice;
  new (): never;
};

to be more precise.

Nullable string not translated properly

In WebGPU:

interface mixin GPUObjectBase {
    attribute USVString? label;
};

gets translated as

  interface GPUObjectBase {
    label: string;
  }

but it should be:

  interface GPUObjectBase {
    label: string | null;
  }

WebIDL dictionaries should not be nominally typed

E.g. for WebGPU's GPURequestAdapterOptions, currently I get:

  interface GPURequestAdapterOptions {
    /**
     * Nominal type branding.
     * https://github.com/microsoft/TypeScript/pull/33038
     * @internal
     */
    readonly __brand: "GPURequestAdapterOptions";
    powerPreference?: GPUPowerPreference;
  }

WebIDL dictionaries are input types; users write them as { object: literals } in TS. So they should not be nominally typed.

Show dictionary default values in doc comments

In IDL, optional dictionary members can have default values. This can't be expressed in TypeScript, but these defaults are extremely useful for developers to know about. It would be nice if the default values could be appended or prepended into the generated documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.