fix: change format of output .d.ts files
This commit is contained in:
+10
-17
@@ -57,32 +57,25 @@ module.exports = {
|
||||
当 `emitTypes: true` 时,loader 会自动生成 `.d.ts` 类型定义文件:
|
||||
|
||||
```typescript
|
||||
// data.schema.d.ts
|
||||
declare module "./data.schema.csv" {
|
||||
export interface data_schema {
|
||||
name: string;
|
||||
age: number;
|
||||
active: boolean;
|
||||
scores: number[];
|
||||
}
|
||||
// data.csv.d.ts
|
||||
type Table = {
|
||||
name: string;
|
||||
age: number;
|
||||
active: boolean;
|
||||
scores: number[];
|
||||
}[];
|
||||
|
||||
export type RowType = data_schema;
|
||||
|
||||
const data: data_schema[];
|
||||
export default data;
|
||||
}
|
||||
declare const data: Table;
|
||||
export default data;
|
||||
```
|
||||
|
||||
### Importing in TypeScript
|
||||
|
||||
```typescript
|
||||
import data from './data.schema.csv';
|
||||
import data from './data.csv';
|
||||
|
||||
// TypeScript 会自动推断类型:
|
||||
// data: { name: string; age: number; active: boolean; scores: number[] }[]
|
||||
|
||||
// 如果启用了 emitTypes,也可以显式导入类型:
|
||||
import type { RowType } from './data.schema.csv';
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
Reference in New Issue
Block a user