Skip to content

Commit

Permalink
refactor(ts): prevent re-opening of closed definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Dec 4, 2022
1 parent 11ac73f commit 1459f07
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 101 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,14 @@ export default compilerOptionsForProgram

### Interfaces

- [`BuildOptions`](src/interfaces/build-options.ts)
- [`CompilerOptions`](src/interfaces/compiler-options.ts)
- [`Plugin`](src/interfaces/plugin.ts)
- [`ProjectReference`](src/interfaces/project-reference.ts)
- [`TsNodeOptions`](src/interfaces/ts-node-options.ts)
- [`TSConfig`](src/interfaces/tsconfig.ts)
- [`TypeAcquisition`](src/interfaces/type-acquisition.ts)
- [`WatchOptions`](src/interfaces/watch-options.ts)

### Types

- [`BuildOptions`](src/types/build-options.ts)
- [`CompilerOptionsValue`](src/types/compiler-options-value.ts)
- [`CompilerOptions`](src/types/compiler-options.ts)
- [`FallbackPolling`](src/types/fallback-polling.ts)
- [`ImportsNotUsedAsValues`](src/types/imports-not-used-as-values.ts)
- [`Jsx`](src/types/jsx.ts)
Expand All @@ -295,9 +291,13 @@ export default compilerOptionsForProgram
- [`NewLine`](src/types/new-line.ts)
- [`Paths`](src/types/paths.ts)
- [`PollingWatch`](src/types/polling-watch.ts)
- [`ProjectReference`](src/types/project-reference.ts)
- [`Target`](src/types/target.ts)
- [`TsNodeOptions`](src/types/ts-node-options.ts)
- [`TypeAcquisition`](src/types/type-acquisition.ts)
- [`WatchDirectory`](src/types/watch-directory.ts)
- [`WatchFile`](src/types/watch-file.ts)
- [`WatchOptions`](src/types/watch-options.ts)

## Contribute

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/__tests__/plugin.spec-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Unit Tests - Plugin
* @module tsconfig-types/interfaces/interfaces/Plugin
* @module tsconfig-types/interfaces/tests/Plugin
*/

import type TestSubject from '../plugin'
Expand Down
12 changes: 7 additions & 5 deletions src/interfaces/__tests__/tsconfig.spec-d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/**
* @file Unit Tests - TSConfig
* @module tsconfig-types/interfaces/interfaces/TSConfig
* @module tsconfig-types/interfaces/tests/TSConfig
*/

import type {
BuildOptions,
ProjectReference,
TypeAcquisition,
WatchOptions
} from '#src/types'
import tsconfig from '../../../tsconfig.json' assert { type: 'json' }
import type BuildOptions from '../build-options'
import type ProjectReference from '../project-reference'
import type TestSubject from '../tsconfig'
import type TypeAcquisition from '../type-acquisition'
import type WatchOptions from '../watch-options'

describe('unit:interfaces/TSConfig', () => {
it('should allow empty object', () => {
Expand Down
6 changes: 0 additions & 6 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@
* @module tsconfig-types/interfaces
*/

export type { default as BuildOptions } from './build-options'
export type { default as CompilerOptions } from './compiler-options'
export type { default as Plugin } from './plugin'
export type { default as ProjectReference } from './project-reference'
export type { default as TsNodeOptions } from './ts-node-options'
export type { default as TSConfig } from './tsconfig'
export type { default as TypeAcquisition } from './type-acquisition'
export type { default as WatchOptions } from './watch-options'
16 changes: 9 additions & 7 deletions src/interfaces/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* @module tsconfig-types/interfaces/TSConfig
*/

import type { CompilerOptionsValue } from '#src/types'
import type {
BuildOptions,
CompilerOptions,
CompilerOptionsValue,
ProjectReference,
TsNodeOptions,
TypeAcquisition,
WatchOptions
} from '#src/types'
import type { JsonValue } from '@flex-development/tutils'
import type BuildOptions from './build-options'
import type CompilerOptions from './compiler-options'
import type ProjectReference from './project-reference'
import type TsNodeOptions from './ts-node-options'
import type TypeAcquisition from './type-acquisition'
import type WatchOptions from './watch-options'

/**
* TypeScript configuration options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file Unit Tests - BuildOptions
* @module tsconfig-types/interfaces/interfaces/BuildOptions
* @module tsconfig-types/types/tests/BuildOptions
*/

import type TestSubject from '../build-options'

describe('unit:interfaces/BuildOptions', () => {
describe('unit:types/BuildOptions', () => {
it('should allow empty object', () => {
assertType<TestSubject>({})
})
Expand All @@ -20,8 +20,4 @@ describe('unit:interfaces/BuildOptions', () => {
verbose: false
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ key: 'value' })
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Unit Tests - CompilerOptions
* @module tsconfig-types/interfaces/interfaces/CompilerOptions
* @module tsconfig-types/types/tests/CompilerOptions
*/

import type TestSubject from '../compiler-options'
Expand Down Expand Up @@ -126,8 +126,4 @@ describe('unit:interfaces/CompilerOptions', () => {
watchFile: 'useFsEvents'
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ key: 'value' })
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Unit Tests - ProjectReference
* @module tsconfig-types/interfaces/interfaces/ProjectReference
* @module tsconfig-types/types/tests/ProjectReference
*/

import { resolve } from 'node:path'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Unit Tests - TsNodeOptions
* @module tsconfig-types/interfaces/interfaces/TsNodeOptions
* @module tsconfig-types/types/tests/TsNodeOptions
*/

import type { TsConfigOptions } from 'ts-node'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Unit Tests - TypeAcquisition
* @module tsconfig-types/interfaces/interfaces/TypeAcquisition
* @module tsconfig-types/types/tests/TypeAcquisition
*/

import type TestSubject from '../type-acquisition'
Expand All @@ -19,8 +19,4 @@ describe('unit:interfaces/TypeAcquisition', () => {
include: ['jquery']
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ key: 'value' })
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Unit Tests - WatchOptions
* @module tsconfig-types/interfaces/interfaces/WatchOptions
* @module tsconfig-types/types/tests/WatchOptions
*/

import { PollingWatchKind } from '#src/enums'
Expand All @@ -21,8 +21,4 @@ describe('unit:interfaces/WatchOptions', () => {
watchFile: 'useFsEvents'
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ key: 'value' })
})
})
10 changes: 3 additions & 7 deletions src/interfaces/build-options.ts → src/types/build-options.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* @file Interfaces - BuildOptions
* @module tsconfig-types/interfaces/BuildOptions
* @file Type Definitions - BuildOptions
* @module tsconfig-types/types/BuildOptions
*/

import type { CompilerOptionsValue } from '#src/types'

/**
* Program build options.
*/
interface BuildOptions {
[option: string]: CompilerOptionsValue | undefined

type BuildOptions = {
/**
* Have recompiles in projects that use {@linkcode incremental} assume that
* changes within a file will only affect files directly depending on it.
Expand Down
3 changes: 2 additions & 1 deletion src/types/compiler-options-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* @module tsconfig-types/types/CompilerOptionsValue
*/

import type { Plugin, ProjectReference } from '#src/interfaces'
import type { Plugin } from '#src/interfaces'
import type { JsonPrimitive, MapLike } from '@flex-development/tutils'
import type ProjectReference from './project-reference'

/**
* [`compilerOptions`][1] values.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Interfaces - CompilerOptions
* @module tsconfig-types/interfaces/CompilerOptions
* @file Type Definitions - CompilerOptions
* @module tsconfig-types/types/CompilerOptions
*/

import type {
Expand All @@ -14,32 +14,27 @@ import type {
WatchDirectoryKind,
WatchFileKind
} from '#src/enums'
import type {
CompilerOptionsValue,
FallbackPolling,
ImportsNotUsedAsValues,
Jsx,
Lib,
Module,
ModuleDetection,
ModuleResolution,
NewLine,
Paths,
Target,
WatchDirectory,
WatchFile
} from '#src/types'
import type { Plugin } from '#src/interfaces'
import type { LiteralUnion } from '@flex-development/tutils'
import type Plugin from './plugin'
import type FallbackPolling from './fallback-polling'
import type ImportsNotUsedAsValues from './imports-not-used-as-values'
import type Jsx from './jsx'
import type Lib from './lib'
import type Module from './module'
import type ModuleDetection from './module-detection'
import type ModuleResolution from './module-resolution'
import type NewLine from './new-line'
import type Paths from './paths'
import type Target from './target'
import type WatchDirectory from './watch-directory'
import type WatchFile from './watch-file'

/**
* TypeScript compiler options.
*
* @see https://www.typescriptlang.org/tsconfig#compilerOptions
*/
interface CompilerOptions {
[option: string]: CompilerOptionsValue | undefined

type CompilerOptions = {
/**
* Allow JavaScript files to be a part of the program.
*
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @module tsconfig-types/types
*/

export type { default as BuildOptions } from './build-options'
export type { default as CompilerOptions } from './compiler-options'
export type { default as CompilerOptionsValue } from './compiler-options-value'
export type { default as FallbackPolling } from './fallback-polling'
export type { default as ImportsNotUsedAsValues } from './imports-not-used-as-values'
Expand All @@ -14,6 +16,10 @@ export type { default as ModuleResolution } from './module-resolution'
export type { default as NewLine } from './new-line'
export type { default as Paths } from './paths'
export type { default as PollingWatch } from './polling-watch'
export type { default as ProjectReference } from './project-reference'
export type { default as Target } from './target'
export type { default as TsNodeOptions } from './ts-node-options'
export type { default as TypeAcquisition } from './type-acquisition'
export type { default as WatchDirectory } from './watch-directory'
export type { default as WatchFile } from './watch-file'
export type { default as WatchOptions } from './watch-options'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Interfaces - ProjectReference
* @module tsconfig-types/interfaces/ProjectReference
* @file Type Definitions - ProjectReference
* @module tsconfig-types/types/ProjectReference
*/

/**
Expand All @@ -10,7 +10,7 @@
*
* @see https://www.typescriptlang.org/docs/handbook/project-references.html
*/
interface ProjectReference {
type ProjectReference = {
/**
* Indicates if the reference forms a circularity.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Interfaces - TsNodeOptions
* @module tsconfig-types/interfaces/TsNodeOptions
* @file Type Definitions - TsNodeOptions
* @module tsconfig-types/types/TsNodeOptions
*/

import type { LiteralUnion } from '@flex-development/tutils'
Expand All @@ -13,7 +13,7 @@ import type CompilerOptions from './compiler-options'
*
* @see https://typestrong.org/ts-node/docs/options
*/
interface TsNodeOptions {
type TsNodeOptions = {
/**
* Custom TypeScript compiler.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/**
* @file Interfaces - TypeAcquisition
* @module tsconfig-types/interfaces/TypeAcquisition
* @file Type Definitions - TypeAcquisition
* @module tsconfig-types/types/TypeAcquisition
*/

import type { CompilerOptionsValue } from '#src/types'

/**
* Auto type-acquisition options.
*
* @see https://www.typescriptlang.org/tsconfig#typeAcquisition
*/
interface TypeAcquisition {
[option: string]: CompilerOptionsValue | undefined

type TypeAcquisition = {
/**
* Prevent TypeScript from inferring types based on filenames.
*/
Expand Down
15 changes: 4 additions & 11 deletions src/interfaces/watch-options.ts → src/types/watch-options.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
/**
* @file Interfaces - WatchOptions
* @module tsconfig-types/interfaces/WatchOptions
* @file Type Definitions - WatchOptions
* @module tsconfig-types/types/WatchOptions
*/

import type {
PollingWatchKind,
WatchDirectoryKind,
WatchFileKind
} from '#src/enums'
import type {
CompilerOptionsValue,
PollingWatch,
WatchDirectory,
WatchFile
} from '#src/types'
import type { PollingWatch, WatchDirectory, WatchFile } from '#src/types'

/**
* File and directory watching options.
*
* @see https://www.typescriptlang.org/tsconfig#watch-options
*/
interface WatchOptions {
[option: string]: CompilerOptionsValue | undefined

type WatchOptions = {
/**
* Specifies a list of directories to exclude from watch.
*/
Expand Down

0 comments on commit 1459f07

Please sign in to comment.