-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/Improve some typings #909
Open
agilgur5
wants to merge
5
commits into
jaredpalmer:master
Choose a base branch
from
agilgur5:typings-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
422ca59
types: add remaining external typings
agilgur5 6c5da74
refactor/fix: consistently use capital TSDX everywhere
agilgur5 ca25438
refactor/types: explicitly name "at least one" types
agilgur5 b85734b
refactor/types: add a type for RollupOptionsWithOutput
agilgur5 7216476
refactor/types: add a TSDXConfig type
agilgur5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,4 @@ declare module 'asyncro'; // doesn't have types (unmerged 2+ year old PR: https: | |
declare module 'enquirer'; // doesn't have types for Input or Select | ||
declare module 'jpjs'; // doesn't ship types (written in TS though) | ||
declare module 'tiny-glob/sync'; // /sync isn't typed (but maybe we can use async?) | ||
|
||
// Patch Babel | ||
// @see line 226 of https://unpkg.com/@babel/[email protected]/lib/index.js | ||
declare module '@babel/core' { | ||
export const DEFAULT_EXTENSIONS: string[]; | ||
export function createConfigItem(boop: any[], options: any): any[]; | ||
} | ||
|
||
// Rollup plugins | ||
declare module 'rollup-plugin-terser'; | ||
declare module '@babel/traverse'; | ||
declare module '@babel/helper-module-imports'; | ||
|
||
declare module 'lodash.merge'; | ||
declare module '@babel/helper-module-imports'; // doesn't have types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { RollupOptions, OutputOptions } from 'rollup'; | ||
|
||
interface SharedOpts { | ||
// JS target | ||
target: 'node' | 'browser'; | ||
|
@@ -8,6 +10,7 @@ interface SharedOpts { | |
} | ||
|
||
export type ModuleFormat = 'cjs' | 'umd' | 'esm' | 'system'; | ||
export type AtLeastOneModuleFormat = [ModuleFormat, ...ModuleFormat[]]; | ||
|
||
export interface BuildOpts extends SharedOpts { | ||
name?: string; | ||
|
@@ -29,10 +32,10 @@ export interface NormalizedOpts | |
extends Omit<WatchOpts, 'name' | 'input' | 'format'> { | ||
name: string; | ||
input: string[]; | ||
format: [ModuleFormat, ...ModuleFormat[]]; | ||
format: AtLeastOneModuleFormat; | ||
} | ||
|
||
export interface TsdxOptions extends SharedOpts { | ||
export interface TSDXOptions extends SharedOpts { | ||
// Name of package | ||
name: string; | ||
// path to file | ||
|
@@ -48,6 +51,7 @@ export interface TsdxOptions extends SharedOpts { | |
// Only transpile, do not type check (makes compilation faster) | ||
transpileOnly?: boolean; | ||
} | ||
export type AtLeastOneTSDXOptions = [TSDXOptions, ...TSDXOptions[]]; | ||
|
||
export interface PackageJson { | ||
name: string; | ||
|
@@ -60,3 +64,9 @@ export interface PackageJson { | |
node?: string; | ||
}; | ||
} | ||
|
||
export type RollupOptionsWithOutput = RollupOptions & { output: OutputOptions }; | ||
|
||
export interface TSDXConfig { | ||
rollup: (config: RollupOptions, options: TSDXOptions) => RollupOptions; | ||
} | ||
Comment on lines
+70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still has the same problem as in #823 (comment) . Should probably try being more specific here and in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a simple one and doesn't change any behavior, but the type-cast seemed to have eroded some typing requirements that exist without it. E.g. Rollup requires each
Plugin
to have aname
property, and some of these custom ones here do not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh think I need a type predicate here per microsoft/TypeScript#20812. I've been using these type-casts after
filter
like #54 did, but a type predicate / type guard is the right way to do it that I believe will prevent eroding of typesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tried the below:
but that didn't fully work either. It also eroded some types, like the
name
property requirement mentioned above 😕With the
TSDXOptions
cast it didn't work because it doesn't seem to be able to infer theAtLeastOne
portion 😕 Using enums didn't help with that either 😕But I was able to fix some type erosion since the
esm
format one doesn't fit the type since it's missingenv
. Need to link those two together somehow...For this Rollup config piece, I was able to rewrite the
condition && plugin
to...(condition ? [plugin] : [])
which I've done before elsewhere, and then that worked, but it is quite verbose... maybe I can abstract that into a function...