Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ AutoImport({
// Default to 'append'
dtsMode: 'append',

// Preserve the original file extensions in the generated .d.ts file.
// Set to `true` to keep the extensions for .ts and .tsx files.
// Default to false
preserveExtsInDts: false,

// Array of strings of regexes that contains imports meant to be ignored during
// the declaration file generation. You may find this useful when you need to provide
// a custom signature for a function.
Expand Down
7 changes: 6 additions & 1 deletion src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function createContext(options: Options = {}, root = process.cwd()) {
const {
dts: preferDTS = isPackageExists('typescript'),
dtsMode = 'append',
preserveExtsInDts = false,
dirsScanOptions,
dirs,
vueDirectives,
Expand Down Expand Up @@ -139,7 +140,11 @@ ${dts}`.trim()}\n`
let currentContent = await unimport.generateTypeDeclarations({
resolvePath: (i) => {
if (i.from.startsWith('.') || isAbsolute(i.from)) {
const related = slash(relative(dir, i.from).replace(/\.ts(x)?$/, ''))
const related = slash(
preserveExtsInDts
? relative(dir, i.from)
: relative(dir, i.from).replace(/\.ts(x)?$/, ''),
)
return !related.startsWith('.')
? `./${related}`
: related
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ export interface Options {
*/
dtsMode?: 'overwrite' | 'append'

/**
* Preserve the original file extensions in the generated .d.ts file.
* Set to `true` to keep the extensions for .ts and .tsx files.
* @default false
*/
preserveExtsInDts?: boolean

/**
* Auto import inside Vue templates
*
Expand Down