Skip to content
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

Provide an easier way to configure type checking for other runtimes #24947

Open
kt3k opened this issue Aug 8, 2024 · 9 comments
Open

Provide an easier way to configure type checking for other runtimes #24947

kt3k opened this issue Aug 8, 2024 · 9 comments
Labels
feat new feature (which has been agreed to/accepted)

Comments

@kt3k
Copy link
Member

kt3k commented Aug 8, 2024

Currently it's difficult to configure Deno type checking to make it work with browsers.

If you like to write code which works with browsers instead of Deno, you need to configure deno.json into something like the below:

{
  "compilerOptions": {
    "lib": ["esnext", "dom", "dom.iterable"]
  }
}

This requires a lot of knowledge about tsconfig.json, and this situation seems against our zero-config/easier TypeScript principle.

I'd suggest we should have runtime field in deno.json, which accepts a list of "deno" | "browser" (for now), and that fields configures the type checking automatically for each given runtime.

{ "runtime": ["browser"] } //=> `compilerOptions.lib` becomes `["esnext", "dom", "dom.iterable"]`

For SSR situation:

{ "runtime": ["deno", "browser"] } //=> `compilerOptions.lib` becomes `["deno.ns", "esnext", "dom", "dom.iterable"]`
@lucacasonato lucacasonato added the feat new feature (which has been agreed to/accepted) label Aug 13, 2024
@lucacasonato lucacasonato added this to the 2.0 milestone Aug 13, 2024
@bartlomieju bartlomieju modified the milestones: 2.0.0, 2.1.0 Sep 6, 2024
@raashidanwar
Copy link
Contributor

I think I can pick this up.
I guess this would require to make changes in deno_json as well.

@raashidanwar
Copy link
Contributor

@bartlomieju created a pull request denoland/deno_config#130.

@BlackAsLight
Copy link

What happens in the event that both runtime and lib properties are provided?

@bartlomieju
Copy link
Member

What happens in the event that both runtime and lib properties are provided?

Most likely a warning or an error.

@kt3k
Copy link
Member Author

kt3k commented Oct 23, 2024

Warning makes sense when lib and runtime options conflict. But how about merging them when the both configurations have no overlaps? I guess some users might want to use their own type definition in addition to the runtime presets

@raashidanwar
Copy link
Contributor

pe definition in ad

I think merging with unique values would do the work, why do we even care about conflict?

@bartlomieju
Copy link
Member

Discussed with the team, if both options provided it should be a hard error.

@bartlomieju bartlomieju modified the milestones: 2.1.0, 2.2.0 Nov 19, 2024
@JOTSR
Copy link
Contributor

JOTSR commented Nov 20, 2024

I have some questions about this issue that I hope are not too out of scope:

  1. This feature seems to be like the way we define runtime support on jsr, does it will be also used as standard jsr package entry ?
  2. If (1) and for forward compatibility does the runtime entries have to be semver tagged to ensure API support between the runtime and the package (like package.json engines key) in a simpler shape { "runtime": ["deno@2", "[email protected]"] } or in full (see). It will so raise an meaning full error message during package installation or resolution instead of during runtime.
  3. Supposing (1) and (2) how to semver tag browser. It seems to be many way to do it but using a per browser key (["chrome@102", "safari@^13.3"]) is fastidious and not future proof. I think there are at least 3 interesting solutions:
    • Using the web platform baseline (["browser:baseline@2023"]) or (["browser@b2023"]) or any similar syntax, note that we refers to "baseline" in the tag to be future proof if the baseline initiative ends or change.
    • Using the tc39 version freeze (["browser:es@2021"]) or new key (["es2022"]) like in tsconfig.target.
    • Using both.

@kt3k
Copy link
Member Author

kt3k commented Nov 20, 2024

@JOTSR

This feature seems to be like the way we define runtime support on jsr, does it will be also used as standard jsr package entry ?

Currently there's no plan to use this for defining package compatiblity in JSR. I think that idea would be better discussed in JSR repository https://github.com/jsr-io/jsr/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted)
Projects
None yet
Development

No branches or pull requests

6 participants