cocos creator 3.x 如何优雅的 import 第三库

如果 在 vsCode import后, 不丢失类型自动提示

我在 引入protobuf库的 时候 这样写

// @ts-ignore

import * as protobufjsAll from ‘protobufjs’;

// @ts-ignore

import { default as protobufjsDef, Root, Type } from ‘protobufjs’;

let parse = protobufjsAll && protobufjsAll.parse

if (protobufjsDef && protobufjsDef.parse) {

// @ts-ignore

parse = protobufjsDef.parse

}

但是 当我在引入 LRUCache 和 yallist 这个两个库的 时候,

import * as LRUCache from "lru-cache"

import * as Yallist from “yallist”;

// @ts-ignore

import { default as LRUCacheDef } from “lru-cache”;

// @ts-ignore

import { default as YallistDef } from “yallist”;

// @ts-ignore

if (LRUCacheDef) {

// @ts-ignore

LRUCache = LRUCacheDef

}

// @ts-ignore

if (YallistDef) {

// @ts-ignore

Yallist = YallistDef

}

这样写编译 会报 Illegal reassignment to import ‘LRUCache’ 错误