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

TypeScript Declarations not found when using export maps #1021

Closed
TheComputerM opened this issue May 24, 2021 · 6 comments
Closed

TypeScript Declarations not found when using export maps #1021

TheComputerM opened this issue May 24, 2021 · 6 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. upstream

Comments

@TheComputerM
Copy link

Describe the bug
Suppose I have a npm package named package. The package.json of package looks like:

{
  "name": "package",
  "version": "1.0.0",
  "main": "index.js",
  "types": "./types/index.d.ts",
  "exports": {
    ".": {
      "default": "./index.js"
    },
    "./Component": {
      "default": "./Component.svelte"
    }
  }
}

The types directory in package looks like:

- index.d.ts
- Component.d.ts

The content of Component.d.ts is:

/// <reference types="svelte" />
import { SvelteComponentTyped } from 'svelte';

export interface Props {
  /**
   * @default "svelte"
   */
  prop?: string;
}

export default class Component extends SvelteComponentTyped<Props, {}, {}> {}

Now in my app where I have svelte with typescript with the content of the tsconfig.json as

{
  "extends": "@tsconfig/svelte/tsconfig.json",
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "es2020",
    "lib": ["es2020"],
    "target": "es2019",
    "importsNotUsedAsValues": "error",
    "isolatedModules": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": ".",
    "allowJs": true,
    "checkJs": true
  },
  "include": ["src/**/*"]
}

and my svelte.config.js is:

const sveltePreprocess = require('svelte-preprocess');

module.exports = {
  preprocess: sveltePreprocess(),
};

And in my Svelte file I import package/Component:

image

To Reproduce

Expected behavior
No ts error

Information about your project:

  • Windows 10
  • svelte-preprocess version 4.7.3
@dummdidumm
Copy link
Member

The same happens on normal TS files. This is an upstream issue.

@TheComputerM
Copy link
Author

Don't know much about ts so is there a workaround for this?

@TheComputerM
Copy link
Author

@mvolfik
Copy link
Contributor

mvolfik commented Jun 24, 2022

The upstream issue has been closed, and I'm still experiencing this

@dummdidumm
Copy link
Member

Fixed on master already, release soon

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jun 24, 2022
@dummdidumm
Copy link
Member

Fixed with the latest release. Note that you need to set "moduleResolution": "node16" (or "nodenext") in your tsconfig in order for the export map to get noticed - this has some other implications on relative import paths though, more about that in #1522

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release. upstream
Projects
None yet
Development

No branches or pull requests

3 participants