Skip to content

RFC: declarative app preferences - #54

Open
sitefinitysteve wants to merge 3 commits into
NativeScript:mainfrom
sitefinitysteve:rfc-declarative-app-preferences
Open

RFC: declarative app preferences#54
sitefinitysteve wants to merge 3 commits into
NativeScript:mainfrom
sitefinitysteve:rfc-declarative-app-preferences

Conversation

@sitefinitysteve

Copy link
Copy Markdown

No description provided.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ebcf1b77-c1c0-4fdf-8dc3-113368e5ac6f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sitefinitysteve

Copy link
Copy Markdown
Author

I just THINK... having a proper preferences story in the project that's supported and polished instead of just "Store some crap as strings in a generic ApplicationSettings object" (not that you still can't) is just NICER to be a core feature.

@sitefinitysteve
sitefinitysteve force-pushed the rfc-declarative-app-preferences branch from 354c569 to 6b22f52 Compare September 8, 2026 23:17
@rigor789

rigor789 commented Sep 8, 2026

Copy link
Copy Markdown
Member

I feel like authoring the definition in TypeScript would be a nice approach, fully typed, and could directly serve as the runtime types too. Something like

// src/app.preferences.ts (or wherever)

import { definePreferences } from "@nativescript/preferences";

export default definePreferences({
 /* ... */
});

The definePreferences ensures correct schema, and provides intellisense to editors.

Usage becomes:

import settings from './app.preferences';

settings.get('theme');            // 'system' | 'light' | 'dark', never undefined
settings.set('volume', 80);       // NSUserDefaults / SharedPreferences
settings.set('enabled', 'yes');   // compile error
settings.onChange('theme', applyTheme);
await settings.openSettings();

sitefinitysteve added a commit to sitefinitysteve/nativescript-preferences that referenced this pull request Sep 9, 2026
Settings are declared in app/app.preferences.ts as
`export default definePreferences({ items })`. Keys and value types are
inferred from the literal and the default export is the typed instance, so
there is no generated settings.generated.ts any more. The before-prepare
hook evaluates the same file under Node with ts.transpileModule, the way
the CLI reads nativescript.config.ts, and writes Settings.bundle and
preferences.xml from it as before. preferences.json keeps working.

Requires TypeScript 5.3 or newer for the typings (verified through 7.0).
TypeScript 7 no longer ships the compiler API, so the loader falls back to
the NativeScript CLI's own typescript when the project's cannot transpile.

Demo moved to app/app.preferences.ts; its native output is byte-identical
to the JSON version. Also pins decode-uri-component 0.5 in the demo.

Suggested by the core team on the RFC:
NativeScript/rfcs#54 (comment)
Per review: the settings are declared in app/app.preferences.ts with
definePreferences, which infers the keys and value types and is the
runtime instance, so no TypeScript module is generated. The hook reads
the file under Node the way the CLI reads nativescript.config.ts.
preferences.json stays supported. Implemented in nativescript-preferences 3.0.
@sitefinitysteve

Copy link
Copy Markdown
Author

I feel like authoring the definition in TypeScript would be a nice approach, fully typed, and could directly serve as the runtime types too.

I JUST upgraded it from the dated plugin years ago, easy swap, it's checked in per your notes, runs fine on both sims

https://github.com/sitefinitysteve/nativescript-preferences/releases/tag/v2.1.0

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.

2 participants