Deno: Deprecated `@deno-types="./foo.d.ts"`

Created on 10 Feb 2020  路  3Comments  路  Source: denoland/deno

// @deno-types="./foo.d.ts"
import * as foo from "./foo.js";
/// <reference types="./foo.d.ts" />
export const foo = "foo";

After supporting Triple-slash reference directive

It seems there is no reason to use @deno-types

We should follow the standard, not create another one

Most helpful comment

I disagree...

Modifying the source is not always an option. The new triple slash directive only works in JavaScript files, where you can easily modify the source. @deno-types is used in situations where modifying the JavaScript source is not feasible, but the importer of the module knows the location of the types.

The reason and logic for each of the ways is discussed in the manual: https://github.com/denoland/deno/blob/master/std/manual.md#using-external-type-definitions including why triple slash references don't work in TypeScript files.

All 3 comments

I disagree...

Modifying the source is not always an option. The new triple slash directive only works in JavaScript files, where you can easily modify the source. @deno-types is used in situations where modifying the JavaScript source is not feasible, but the importer of the module knows the location of the types.

The reason and logic for each of the ways is discussed in the manual: https://github.com/denoland/deno/blob/master/std/manual.md#using-external-type-definitions including why triple slash references don't work in TypeScript files.

@kitsonk

We can customize the function languageServiceHost.resolveTypeReferenceDirectives to ignore it in the typescript file

resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];

https://github.com/denoland/deno/blob/e6167c78134182c45689bda7bcb12af05009349c/deno_typescript/compiler_main.js#L123-L133

class Host {
  // ...
  resolveTypeReferenceDirectives(typeDirectiveNames, containingFile) {
    // if it's  typescript file. then ignore it.
    if (containingFile.endsWith('.ts')) {
        return []
    }

    // resolve type file
    return // ...
  }
}

I think this should be feasible.

It works for me at vscode-deno

@axetroy we don't use the language service host in Deno.

The new triple slash directive only works in JavaScript files

That is by design. Adding it to TypeScript files does nothing for Deno, but it is important to provide the capability of "pointing" to types in JavaScript files. Is there something not working? Because adding what you are suggesting would not impact Deno at all.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ry picture ry  路  3Comments

kyeotic picture kyeotic  路  3Comments

metakeule picture metakeule  路  3Comments

somombo picture somombo  路  3Comments

xueqingxiao picture xueqingxiao  路  3Comments