Skip to content

Support for bundler moduleResolution in TypeScript 5.0 #4160

@stbodurov

Description

@stbodurov

This is a request for updating lexical to TS 5.0, and making sure it supports the new bundler moduleResolution.

After upgrading a project to TS5, we switched to using the new bundler moduleResolution strategy.

We noticed that running tsc resulted in the following errors in lexical (which is currently on TS ^4.6.4):

$ tsc

> tsc

node_modules/@lexical/list/formatList.d.ts:9:40 - error TS7016: Could not find a declaration file for module './'. '~/exampleProject/node_modules/@lexical/list/LexicalList.js' implicitly has an 'any' type.
9 import { ListItemNode, ListNode } from './';
                                         ~~~~

node_modules/@lexical/list/utils.d.ts:9:40 - error TS7016: Could not find a declaration file for module './'. '~/exampleProject/node_modules/@lexical/list/LexicalList.js' implicitly has an 'any' type.
9 import { ListItemNode, ListNode } from './';
                                         ~~~~

node_modules/@lexical/table/LexicalTableUtils.d.ts:10:50 - error TS7016: Could not find a declaration file for module '.'. '~/exampleProject/node_modules/@lexical/table/LexicalTable.js' implicitly has an 'any' type.
10 import { InsertTableCommandPayloadHeaders } from '.';
                                                    ~~~

node_modules/lexical/LexicalNode.d.ts:10:29 - error TS7016: Could not find a declaration file for module '.'. '~/exampleProject/node_modules/lexical/Lexical.js' implicitly has an 'any' type.
10 import { ElementNode } from '.';
                               ~~~

node_modules/lexical/LexicalNormalization.d.ts:8:47 - error TS7016: Could not find a declaration file for module '.'. '~/exampleProject/node_modules/lexical/Lexical.js' implicitly has an 'any' type.
8 import type { RangeSelection, TextNode } from '.';
                                                ~~~

node_modules/lexical/LexicalSelection.d.ts:13:26 - error TS7016: Could not find a declaration file for module '.'. '~/exampleProject/node_modules/lexical/Lexical.js' implicitly has an 'any' type.
13 import { TextNode } from '.';
                            ~~~

node_modules/lexical/LexicalUtils.d.ts:14:59 - error TS7016: Could not find a declaration file for module '.'. '~/exampleProject/node_modules/lexical/Lexical.js' implicitly has an 'any' type.
14 import { DecoratorNode, ElementNode, LineBreakNode } from '.';
                                                             ~~~

node_modules/lexical/nodes/LexicalElementNode.d.ts:11:26 - error TS7016: Could not find a declaration file for module '../'. '~/exampleProject/node_modules/lexical/Lexical.js' implicitly has an 'any' type.
11 import { TextNode } from '../';
                            ~~~~~

Found 8 errors in 8 files.

Errors  Files
     1  node_modules/@lexical/list/formatList.d.ts:9
     1  node_modules/@lexical/list/utils.d.ts:9
     1  node_modules/@lexical/table/LexicalTableUtils.d.ts:10
     1  node_modules/lexical/LexicalNode.d.ts:10
     1  node_modules/lexical/LexicalNormalization.d.ts:8
     1  node_modules/lexical/LexicalSelection.d.ts:13
     1  node_modules/lexical/LexicalUtils.d.ts:14
     1  node_modules/lexical/nodes/LexicalElementNode.d.ts:11

We found that adding "types": "./index.d.ts", to the package.json of the libraries used worked as a temporary solution for most errors except one.

This error wasn't fixed by that, and reverting moduleResolution to node didn't help either. Deleting / in the path did:

node_modules/lexical/nodes/LexicalElementNode.d.ts:11:26 - error TS7016: Could not find a declaration file for module '../'. '~/exampleProject/node_modules/lexical/Lexical.js' implicitly has an 'any' type.
11 import { TextNode } from '../';

import {$isTextNode, TextNode} from '../';

Lexical version: 0.9.0

The current behavior

An error output is thrown by tsc when using lexical in a TS5 project.

The expected behavior

All type checks to be successful with no errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions