Skip to content

Change in declaration file resolution in 2.9 when package.json doesn't specify types #24556

Closed
@seepel

Description

@seepel

TypeScript Version: 2.9.1 and 3.0.0-dev.201xxxxx

Typescript 2.9 seems to have changed how type declaration files are resolved when package.json does not contain a types key, and there is a declaration file next to the main script.

For example the Semantic UI React project (https://github.com/Semantic-Org/Semantic-UI-React) has the following (relevant) file structure:

* package.json
* index.d.ts
* dist
  * commonjs
    * index.js
    * index.d.ts

package.json specifies the main script to be dist/commonjs/index.js and does not specify a types key.

In typescript 2.8 when importing from this module the type declaration was resolved to node_modules/semantic-ui-react/index.d.ts.
In typescript 2.9 the type declaration is resolved to node_modules/semantic-ui-react/dist/commonjs/index.d.ts

I definitely understand how one could argue either way, but wanted to make sure that this surfaced somewhere in case it was unintentional, and perhaps suggest that if it was intentional this change be made in typescript 3.0 as it is a breaking change?

Search Terms:

  • types
  • package.json
  • declaration file
  • resolve
  • resolution

Code

import React from "react"
import { Container } from "semantic-ui-react"


export default function() { return <Container/> }

Expected behavior:
Compiles with no errors

Actual behavior:

index.tsx:2:10 - error TS2305: Module '"/Users/sean/src/test/node_modules/semantic-ui-react/dist/commonjs/index"' has no exported member 'Container'.

2 import { Container } from "semantic-ui-react"
           ~~~~~~~~~

Playground Link:
No playground link as this depends on node_modules.

Related Issues:
I did not find any related issues

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions