Code Monkey home page Code Monkey logo

Comments (10)

sandersn avatar sandersn commented on June 18, 2024

@andrewbranch @RyanCavanaugh @DanielRosenwasser in case you're interested or have opinions.

from types-publisher.

DanielRosenwasser avatar DanielRosenwasser commented on June 18, 2024

Everything else should be referenced either through index.d.ts or through an explicit reference in the tests.

Better make that a rule too! No ignored .d.ts files.

from types-publisher.

andrewbranch avatar andrewbranch commented on June 18, 2024

this doesn't reflect how users will reference the type files as installed in @types/*.

incorrectly able to resolve glo

Just to clarify, you’re implicitly referring to the fact that the compiler’s resolution rules use only the @types package’s index.d.ts as an entry point (or more accurately, it will follow the package.json types field, which is already enforced to be index.d.ts by types-publisher), correct? So the goal is to make resolution the same for tests as it is for users.

from types-publisher.

andrewbranch avatar andrewbranch commented on June 18, 2024

Assuming I understood that right, this sounds like a good idea.

from types-publisher.

sandersn avatar sandersn commented on June 18, 2024

@DanielRosenwasser types-publisher's checks are already pretty strict about ignoring files. There are a lot of quasi-ignored files that will move from tsconfig to OTHER_FILES.txt as part of this change. I think it's important to have an opt-out so that people don't have to test their types exhaustively, but it's also important that those opted-out files look different.

@andrewbranch You are right.

from types-publisher.

ExE-Boss avatar ExE-Boss commented on June 18, 2024

I actually tried to explicitly declare /// <reference types="*"/> in my UMD @types definitions, but dtslint complained that it’s unnecessary and caused build failures.

from types-publisher.

sandersn avatar sandersn commented on June 18, 2024

"*"? That is equivalent to import "*" -- I don't think it resolves to anything.

from types-publisher.

ExE-Boss avatar ExE-Boss commented on June 18, 2024

import "*" makes the file be parsed as a module, thus making the UMD export as namespace inaccessible.

/// <reference types="*"> keeps the file parsed as is, and with no import or exports, UMD export as namespace definitions are accessible.

"*" in this context means "<module_name>".

Example:

types/foo/index.d.ts:

declare function foo(): ;

export as namespace foo;
export = foo;

types/foo/test/foo.umd.test.ts:

/// <reference types="foo">
// the above line causes a types-publisher failure, since `foo/index.d.ts`
// is in scope through `tsconfig.json#/files`

foo(); // $ExpectType …

types/foo/test/foo.cjs.test.ts:

import fooImport = require('foo');

fooImport(); // $ExpectType …

// The `foo` UMD export is correctly inaccessible in CommonJS files:
foo; // $ExpectError

from types-publisher.

sandersn avatar sandersn commented on June 18, 2024

Oh, I see. I didn't get the meaning of * before.

Even after closing this issue, index.d.ts has special handling and is implicitly included, as your example shows, even when it's not correct. I'm not sure how to fix that. We'd have to make it inaccessible only to tests of globals, not of modules.

from types-publisher.

ExE-Boss avatar ExE-Boss commented on June 18, 2024

Actually, it’s types‑publisher that doesn’t like <reference /> to self in UMD tests, which is why I couldn’t reproduce this locally (since types‑publisher doesn’t like my environment for whatever reason, and therefore I run dtslint directly).

All it takes is for #714 to be merged now, and my above example should become allowed.

from types-publisher.

Related Issues (20)

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.