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

deno types to output typings to a single file #9377

Closed
ebebbington opened this issue Feb 2, 2021 · 4 comments
Closed

deno types to output typings to a single file #9377

ebebbington opened this issue Feb 2, 2021 · 4 comments
Labels
duplicate a duplicate of another issue

Comments

@ebebbington
Copy link
Contributor

ebebbington commented Feb 2, 2021

What

As it stands, there doesn't seem to be a way to generate typings for a file, or files, using Deno. It might be possible with Deno.emit, using the 2nd argument (CompilerOptions), but i haven't checked this and I'm not too confident it can.

It also seems like deno types could be expanded upon, ie there's a great opportunity to expand upon this subcommand.

But what I propose is for deno types (and ideally a programatic way as well) to create the typings for the given file or directory that outputs to a single file

How

$ deno types src/mod.ts >> dist/mod.d.ts
await Deno.emit("./src/mod.ts", { typings: true })

Why

Well say I have a project that uses typescript. I plan to move over from Node to Deno, but I need typings. It seems impossible to do this with Deno, halting on that projects progress to make the beautiful journey of moving to Deno. This issue. is specifically with emitting a bundled .d.ts file.

Whilst I can use Deno.emit(file, { compilerOptions: { declaration: true }}), it still doesn't provide the bundled typings

Example

Here is an example, of me wanting to create a single bundled .d.ts file using the emit method, but it not actually providing typings:

// src/mod.ts
export * from "./something.ts"
export * from "./test.ts"
// compile.ts
const stuff = await Deno.emit("./src/mod.ts", {
  compilerOptions: {
    "declaration": true,
    "emitDeclarationOnly": true,
  }
})
const keys = Object.keys(stuff.files)
const key = keys.find(k => k.includes("mod.ts.d.ts")) as string
console.log(stuff.files[key])
/// <amd-module name="file:///.../.../tmp/src/mod.ts" />
export * from "./something.ts";
export * from "./test.ts";

As you can see, it doesn't provide any typings

@0kku
Copy link

0kku commented Feb 2, 2021

Specifically, interoperability between Deno and TSC seems unachievable at present. Deno doesn't understand TSC's imports, nor TSC's .d.ts files because those also use the incorrect file extensions. On the other hand, TSC doesn't understand Deno's imports. There doesn't even seem to be any tools out there that would allow automating converting between the two formats. Ideally, you'd be able to bundle the typings of a project into a single .d.ts file in order to avoid the importing conflicts and allow you to be able to use the same code base for both Deno and TSC consumers.

@ebebbington ebebbington changed the title deno types to provides typings for a given file deno types to output typings to a single file Feb 2, 2021
@kitsonk kitsonk added the duplicate a duplicate of another issue label Feb 3, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Feb 3, 2021

Duplicate of #3385

(You can already set declaration: true in the compiler options in Deno.emit() for single file declarations, just like you would with tsc)

@kitsonk kitsonk closed this as completed Feb 3, 2021
@jespertheend
Copy link
Contributor

Does declaration: true still work? It doesn't seem to do anything, and it appears in a list of ignored options:

deno/cli/config_file.rs

Lines 86 to 90 in 1fb5858

pub const IGNORED_COMPILER_OPTIONS: &[&str] = &[
"allowSyntheticDefaultImports",
"allowUmdGlobalAccess",
"baseUrl",
"declaration",

@jespertheend
Copy link
Contributor

Oh never mind, it seems declaration: true does in fact do something. But if you try to emit the same file a second time, it keeps emitting d.ts files regardless of your declaration setting. Only after you clear the Deno cache will it stop emitting them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants