Skip to content

Commit

Permalink
chore: upgrade typescript + fixups
Browse files Browse the repository at this point in the history
add a version override so the API extractor uses it too
  • Loading branch information
wmertens committed Mar 27, 2024
1 parent 9b61314 commit 6ea7260
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 391 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
],
"cSpell.words": ["bucketize", "Stringifiable"],
"javascript.preferences.autoImportFileExcludePatterns": ["node:test"],
"typescript.preferences.preferTypeOnlyAutoImports": true
"typescript.preferences.preferTypeOnlyAutoImports": true,
"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"syncpack": "^12.3.0",
"terser": "^5.29.2",
"tsm": "^2.3.0",
"typescript": "5.3.3",
"typescript": "5.4.3",
"undici": "*",
"vfile": "^6.0.1",
"vite": "^5.1.6",
Expand All @@ -133,7 +133,8 @@
"packageManager": "pnpm@8.15.5",
"pnpm": {
"overrides": {
"vfile": "^6.0.1",
"typescript": "$typescript",
"vfile": "$vfile",
"@supabase/realtime-js": "2.8.4"
},
"patchedDependencies": {
Expand Down Expand Up @@ -187,7 +188,6 @@
"serve": "tsm --inspect --conditions=development starters/dev-server.ts 3300",
"serve.debug": "tsm --inspect-brk --conditions=development starters/dev-server.ts 3300",
"start": "concurrently \"npm:build.watch\" \"npm:tsc.watch\" -n build,tsc -c green,cyan",
"vitest": "vitest",
"test": "pnpm build.full && pnpm test.unit && pnpm test.e2e",
"test.e2e": "pnpm test.e2e.chromium && pnpm test.e2e.webkit",
"test.e2e.chromium": "playwright test starters --browser=chromium --config starters/playwright.config.ts",
Expand All @@ -203,7 +203,8 @@
"tsc.check": "tsc --noEmit",
"tsc.trace": "tsc -p tsconfig.json --traceResolution > tsc.log",
"tsc.watch": "tsc --noEmit --watch --preserveWatchOutput",
"update.qwik.builds": "tsm scripts/update-qwik-builds.ts packages/docs && tsm scripts/update-qwik-builds.ts packages/insights; pnpm install"
"update.qwik.builds": "tsm scripts/update-qwik-builds.ts packages/docs && tsm scripts/update-qwik-builds.ts packages/insights; pnpm install",
"vitest": "vitest"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"tailwindcss": "^3.4.1",
"terser": "^5.29.2",
"tsm": "^2.3.0",
"typescript": "5.4.2",
"typescript": "5.4.3",
"undici": "*",
"valibot": "^0.29.0",
"vite": "^5.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@
}
],
"kind": "TypeAlias",
"content": "Infers `Props` from the component or tag.\n\n\n```typescript\nexport type PropsOf<COMP> = COMP extends string ? COMP extends keyof QwikIntrinsicElements ? QwikIntrinsicElements[COMP] : QwikIntrinsicElements['span'] : NonNullable<COMP> extends never ? never : COMP extends FunctionComponent<infer PROPS> ? PROPS extends Record<any, infer V> ? IsAny<V> extends true ? never : ObjectProps<PROPS> : COMP extends Component<infer OrigProps> ? ObjectProps<OrigProps> : PROPS : never;\n```\n**References:** [QwikIntrinsicElements](#qwikintrinsicelements)<!-- -->, [FunctionComponent](#functioncomponent)<!-- -->, [Component](#component)\n\n\n\n```tsx\nconst Desc = component$(({desc, ...props}: { desc: string } & PropsOf<'div'>) => {\n return <div {...props}>{desc}</div>;\n});\n\nconst TitleBox = component$(({title, ...props}: { title: string } & PropsOf<Box>) => {\n return <Box {...props}><h1>{title}</h1></Box>;\n});\n```",
"content": "Infers `Props` from the component or tag.\n\n\n```typescript\nexport type PropsOf<COMP> = IsAny<COMP> extends true ? never : unknown extends COMP ? never : COMP extends string ? COMP extends keyof QwikIntrinsicElements ? QwikIntrinsicElements[COMP] : QwikIntrinsicElements['span'] : NonNullable<COMP> extends never ? never : COMP extends FunctionComponent<infer PROPS> ? PROPS extends Record<any, infer V> ? IsAny<V> extends true ? never : ObjectProps<PROPS> : COMP extends Component<infer OrigProps> ? ObjectProps<OrigProps> : PROPS : never;\n```\n**References:** [QwikIntrinsicElements](#qwikintrinsicelements)<!-- -->, [FunctionComponent](#functioncomponent)<!-- -->, [Component](#component)\n\n\n\n```tsx\nconst Desc = component$(({desc, ...props}: { desc: string } & PropsOf<'div'>) => {\n return <div {...props}>{desc}</div>;\n});\n\nconst TitleBox = component$(({title, ...props}: { title: string } & PropsOf<Box>) => {\n return <Box {...props}><h1>{title}</h1></Box>;\n});\n```",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/core/component/component.public.ts",
"mdFile": "qwik.propsof.md"
},
Expand Down
31 changes: 18 additions & 13 deletions packages/docs/src/routes/api/qwik/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3686,21 +3686,26 @@ export type PropFunctionProps<PROPS extends Record<any, any>> = {
Infers `Props` from the component or tag.
```typescript
export type PropsOf<COMP> = COMP extends string
? COMP extends keyof QwikIntrinsicElements
? QwikIntrinsicElements[COMP]
: QwikIntrinsicElements["span"]
: NonNullable<COMP> extends never
export type PropsOf<COMP> =
IsAny<COMP> extends true
? never
: COMP extends FunctionComponent<infer PROPS>
? PROPS extends Record<any, infer V>
? IsAny<V> extends true
: unknown extends COMP
? never
: COMP extends string
? COMP extends keyof QwikIntrinsicElements
? QwikIntrinsicElements[COMP]
: QwikIntrinsicElements["span"]
: NonNullable<COMP> extends never
? never
: ObjectProps<PROPS>
: COMP extends Component<infer OrigProps>
? ObjectProps<OrigProps>
: PROPS
: never;
: COMP extends FunctionComponent<infer PROPS>
? PROPS extends Record<any, infer V>
? IsAny<V> extends true
? never
: ObjectProps<PROPS>
: COMP extends Component<infer OrigProps>
? ObjectProps<OrigProps>
: PROPS
: never;
```
**References:** [QwikIntrinsicElements](#qwikintrinsicelements), [FunctionComponent](#functioncomponent), [Component](#component)
Expand Down
19 changes: 10 additions & 9 deletions packages/docs/src/routes/docs/(qwik)/components/overview/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,18 @@ bundled with the parent component.

## Polymorphic components

When you want to output a different type of element depending on props, you can do it using something like this:
When you want to output a different type of element depending on props but default to a `<div>`, you can do it using something like this:

```tsx
export const Poly = component$(
<C extends string | FunctionComponent = string | FunctionComponent>({
as: Cmp = 'div' as C,
...props
}: { as?: C } & PropsOf<string extends C ? 'div' : C>) => {
return <Cmp {...props}>hi</Cmp>;
}
);
const Poly = component$(
<C extends string | FunctionComponent = 'div'>({
as,
...props
}: { as?: C } & PropsOf<string extends C ? 'div' : C>) => {
const Cmp = as || 'div';
return <Cmp {...props}>hi</Cmp>;
}
);

// These all work with correct types
<>
Expand Down
3 changes: 2 additions & 1 deletion packages/insights/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "insights",
"version": "0.1.0",
"description": "Qwik Insights dashboard",
"dependencies": {
"@auth/core": "0.21.0",
Expand Down Expand Up @@ -33,7 +34,7 @@
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.12",
"tailwindcss": "^3.4.1",
"typescript": "5.4.2",
"typescript": "5.4.3",
"undici": "*",
"vite": "^5.1.6",
"vite-tsconfig-paths": "^4.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"remark-gfm": "4.0.0",
"set-cookie-parser": "^2.6.0",
"tsm": "^2.3.0",
"typescript": "5.4.2",
"typescript": "5.4.3",
"unified": "11.0.4",
"unist-util-visit": "5.0.0",
"uvu": "0.5.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-labs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"eslint-plugin-qwik": "workspace:^",
"np": "^10.0.1",
"prettier": "^3.2.5",
"typescript": "5.4.2",
"typescript": "5.4.3",
"undici": "*",
"vite": "^5.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@types/react-dom": "^18.2.22",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.4.2",
"typescript": "5.4.3",
"vite": "^5.1.6"
},
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions packages/qwik/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"annotation": "This package.json is for internal use in the monorepo, the build actually makes a new package.json for the published package via scripts/package-json.ts",
"name": "@builder.io/qwik",
"description": "An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.",
"version": "1.5.1",
"annotation": "This package.json is for internal use in the monorepo, the build actually makes a new package.json for the published package via scripts/package-json.ts",
"bin": "./qwik-cli.cjs",
"bugs": "https://github.com/BuilderIO/qwik/issues",
"contributors": [
Expand Down Expand Up @@ -35,16 +35,15 @@
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
},
"exports_annotation": "We use the build for the optimizer because esbuild doesn't like the html?raw imports in the server plugin and it's only used in the vite configs",
"exports": {
".": "./src/core/index.ts",
"./cli": "./src/cli/index.ts",
"./jsx-runtime": "./src/core/index.ts",
"./jsx-dev-runtime": "./src/core/index.ts",
"./jsx-runtime": "./src/jsx-runtime/index.ts",
"./jsx-dev-runtime": "./src/jsx-runtime/index.ts",
"./build": "./src/build/index.ts",
"./optimizer.cjs": "./dist/optimizer.cjs",
"./optimizer.mjs": "./dist/optimizer.mjs",
"./optimizer": "./dist/optimizer.mjs",
"./optimizer": "./src/optimizer/src/index.ts",
"./server.cjs": "./dist/server.cjs",
"./server.mjs": "./dist/server.mjs",
"./server": "./src/server/index.ts",
Expand All @@ -55,6 +54,7 @@
"./qwik-prefetch.debug.js": "./dist/qwik-prefetch.debug.js",
"./package.json": "./package.json"
},
"exports_annotation": "We use the build for the optimizer because esbuild doesn't like the html?raw imports in the server plugin and it's only used in the vite configs",
"files": [
"bindings/qwik.darwin-x64.node",
"bindings/qwik.darwin-arm64.node",
Expand Down
5 changes: 3 additions & 2 deletions packages/qwik/src/core/render/jsx/types/jsx-types.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ describe('types', () => {

test('polymorphic component', () => () => {
const Poly = component$(
<C extends string | FunctionComponent = string | FunctionComponent>({
as: Cmp = 'div' as C,
<C extends string | FunctionComponent = 'div'>({
as,
...props
}: { as?: C } & PropsOf<string extends C ? 'div' : C>) => {
const Cmp = as || 'div';
return <Cmp {...props}>hi</Cmp>;
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/util/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const isPromise = (value: any): value is Promise<any> => {

export const safeCall = <T, B, C>(
call: () => ValueOrPromise<T>,
thenFn: (arg: Awaited<T>) => ValueOrPromise<B>,
rejectFn: (reason: any) => ValueOrPromise<C>
thenFn: { f(arg: Awaited<T>): ValueOrPromise<B> }['f'],
rejectFn: { f(reason: any): ValueOrPromise<C> }['f']
): ValueOrPromise<B | C> => {
try {
const result = call();
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/optimizer/src/plugins/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { magenta } from 'kleur/colors';
import type { IncomingMessage, ServerResponse } from 'http';

import type { Connect, ViteDevServer } from 'vite';
import type { OptimizerSystem, Path, QwikManifest } from '../types';
import type { OptimizerSystem, Path, QwikManifest, SymbolMapper } from '../types';
import { type NormalizedQwikPluginOptions, parseId } from './plugin';
import type { QwikViteDevResponse } from './vite';
import { formatError } from './vite-utils';
Expand Down Expand Up @@ -137,7 +137,7 @@ export async function configureDevServer(
manifest: isClientDevOnly ? undefined : manifest,
symbolMapper: isClientDevOnly
? undefined
: (symbolName, mapper) => {
: (symbolName: string, mapper: SymbolMapper | undefined) => {
if (symbolName === SYNC_QRL) {
return [symbolName, ''];
}
Expand Down
2 changes: 2 additions & 0 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,8 @@ interface QwikVitePluginCommonOptions {
interface QwikVitePluginCSROptions extends QwikVitePluginCommonOptions {
/** Client Side Rendering (CSR) mode. It will not support SSR, default to Vite's `index.html` file. */
csr: true;
ssr: never;
client: never;
}

interface QwikVitePluginSSROptions extends QwikVitePluginCommonOptions {
Expand Down
Loading

0 comments on commit 6ea7260

Please sign in to comment.