Skip to content

feat(native): type the theme and React Native props of each component - #1052

Open
owjs3901 wants to merge 1 commit into
feat/react-native-webfrom
feat/react-native-types
Open

owjs3901 wants to merge 1 commit into
feat/react-native-webfrom
feat/react-native-types

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Part of #411, depends on #1051 (base: feat/react-native-web). PR 12 of the React Native plan: the type side of design §8 step 8, "theme type generation for RN projects", and RN-typed props (§6 src/types/).

What it does

  • @devup-ui/metro-plugin: when Metro reads the config, withDevupUI writes two files into df/ (the new distDir option), as the web plugins do. The directory ignores itself in git.
    • theme.d.ts: the theme interface of devup.json, from the same getThemeInterface the web plugins use, so $tokens and typography complete.
    • native.d.ts: import '@devup-ui/react/native/types'.
  • @devup-ui/react: a new augmentation point, DevupElementProps. A default-element component reads its element's props through DevupIntrinsicProps<T>, which is React.ComponentProps<T> unless the interface names T. Web types are unchanged: the interface is empty there, and every web type test still passes.
  • @devup-ui/react/native/types (new, types only): it fills that interface, so each component takes the props of the React Native component the build renders it as:
    • div takes ViewProps (Box, Flex, VStack, Center, Grid);
    • span takes TextProps, img takes ImageProps, input takes TextInputProps and button takes PressableProps;
    • each also takes className, for css() (D3).
    • So onPress, onChangeText, onLayout, testID and the other React Native props type-check. HTML-only props such as href and onInput become type errors.
  • With D2 (keep importing from @devup-ui/react), this works through module augmentation, not a separate component package.

Tests

  • type-tests/native (source): it checks React Native props on each component, css() with className, and style props. It also expects href on a View and onInput on a TextInput to be type errors. Without the augmentation, the same file fails. It runs in test:types, which is part of the build.
  • type-tests/published/tsconfig.native.json checks the built dist through the package exports. rollup.types.config.mjs keeps native/types.d.ts as a hand-written declaration.
  • Metro plugin tests cover:
    • writing theme.d.ts with a token, native.d.ts and .gitignore;
    • the distDir option;
    • the engine selection.
    • Coverage is 100%.
  • Expo example:
    • its tsc --noEmit previously failed on onPress/onChangeText, and now passes;
    • the expo CI job runs it as typecheck after the export;
    • the job's path filter now also matches packages/react/src/types/.
  • CI: feat/react-native-web is added to the pull_request branches of the workflow.

#411의 일부이며 #1051에 의존합니다 (base: feat/react-native-web). React Native 계획의 12번째 PR로, 설계 §8 8단계 중 "RN 프로젝트용 theme 타입 생성"과 RN 기준 props 타입(§6 src/types/)입니다.

변경 내용

  • @devup-ui/metro-plugin: Metro가 config를 읽을 때 withDevupUI가 웹 플러그인처럼 df/(새 distDir 옵션)에 두 파일을 씁니다. 디렉터리는 스스로 git에서 제외됩니다.
    • theme.d.ts: 웹 플러그인과 같은 getThemeInterface로 만든 devup.json의 테마 interface입니다. 그래서 $토큰과 typography가 자동완성됩니다.
    • native.d.ts: import '@devup-ui/react/native/types'.
  • @devup-ui/react: 새 augmentation 지점 DevupElementProps를 추가했습니다. 기본 요소 컴포넌트는 DevupIntrinsicProps<T>로 요소의 props를 읽습니다. 이 타입은 interface에 T가 없으면 React.ComponentProps<T>입니다. 웹에서는 interface가 비어 있으므로 웹 타입은 그대로이고, 웹 타입 테스트도 모두 통과합니다.
  • @devup-ui/react/native/types(신규, 타입 전용): 위 interface를 채워, 각 컴포넌트가 빌드가 렌더링하는 React Native 컴포넌트의 props를 받게 합니다:
    • div는 ViewProps(Box·Flex·VStack·Center·Grid);
    • span은 TextProps, img는 ImageProps, input은 TextInputProps, button은 PressableProps;
    • 모두 css()용 className(D3)도 받습니다.
    • 따라서 onPress·onChangeText·onLayout·testID 등 React Native props가 타입 검사를 통과합니다. href·onInput 같은 HTML 전용 props는 타입 에러가 됩니다.
  • D2(@devup-ui/react에서 계속 import)를 따르므로, 별도 컴포넌트 패키지가 아니라 module augmentation으로 동작합니다.

테스트

  • type-tests/native(소스): 각 컴포넌트의 React Native props, className과 css(), 스타일 props를 검사합니다. View의 href와 TextInput의 onInput은 타입 에러여야 합니다. augmentation이 없으면 같은 파일이 실패합니다. 빌드에 포함된 test:types에서 실행됩니다.
  • type-tests/published/tsconfig.native.json은 빌드된 dist를 package exports를 통해 검사합니다. rollup.types.config.mjs는 native/types.d.ts를 직접 작성한 선언 파일로 유지합니다.
  • Metro 플러그인 테스트가 다루는 것:
    • 토큰이 든 theme.d.ts, native.d.ts, .gitignore 작성;
    • distDir 옵션;
    • engine 선택.
    • coverage는 100%입니다.
  • Expo 예제:
    • 이전에는 onPress/onChangeText에서 실패하던 tsc --noEmit이 이제 통과합니다;
    • expo CI job이 export 뒤에 이를 typecheck로 실행합니다;
    • job의 경로 필터가 이제 packages/react/src/types/도 포함합니다.
  • CI: workflow의 pull_request branches에 feat/react-native-web을 추가했습니다.

🤖 Generated with Claude Code

Metro writes df/theme.d.ts (the tokens of devup.json) and df/native.d.ts
when it reads the config, as the web plugins do. native.d.ts imports the
new @devup-ui/react/native/types, which fills the new DevupElementProps
augmentation point so each component takes the props of the React Native
component it renders. Web types are unchanged. The Expo example now
type-checks in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/metro-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/types.ts 100.00% <100.00%> (ø)
packages/react/src/index.ts 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant