Registry / type-stubs / sf-symbols-typescript

sf-symbols-typescript

JSON →
library2.2.0jsnpmunverified

sf-symbols-typescript is a utility library providing TypeScript type definitions for Apple's SF Symbols. It enables developers to use SF Symbol names as string literal types, enhancing type safety in applications that consume these icons, particularly useful in environments like React Native. The current stable version is 2.2.0. The library primarily updates its types in sync with new releases of SF Symbols from Apple, incorporating new icons and symbol versions. Its key differentiators include having zero runtime dependencies and zero runtime code, making it a pure type-level utility. It also offers advanced features for restricting the available symbols globally via declaration merging or individually by importing specific version types, which is crucial for maintaining compatibility with target iOS/macOS versions.

npm install sf-symbols-typescript
INSTALL
IMPORT
SIG · SF-SYMBOLS-TYPESCR
S
sf-symbols-typescript
type-stubsjavascriptv2.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SFSymbol
import type { SFSymbol } from 'sf-symbols-typescript'
import { SFSymbol } from 'sf-symbols-typescript'
This is a type-only import. Using `import` without `type` will result in an error as there's no runtime value.
SFSymbols{major}_{minor}
import type { SFSymbols5_0 } from 'sf-symbols-typescript'
import { SFSymbols5_0 } from 'sf-symbols-typescript'
To restrict symbols to a specific version, import the corresponding type like `SFSymbols5_0`. Ensure you use `import type`.
Overrides (declaration merging)
declare module 'sf-symbols-typescript' { interface Overrides { SFSymbolsVersion: '6.0' } }
import { Overrides } from 'sf-symbols-typescript'
The `Overrides` interface is meant for declaration merging to globally restrict SF Symbol versions. Do not attempt to import it directly.

Demonstrates basic usage of `SFSymbol` for type safety, global restriction via declaration merging, and importing version-specific symbol types.

import type { SFSymbol } from 'sf-symbols-typescript'; // Basic usage: type-checking SF Symbol names const basicIcon: SFSymbol = 'arrow.up'; // const invalidIcon: SFSymbol = 'non.existent.symbol'; // This would cause a TypeScript error // Globally restricting SF Symbol versions using declaration merging declare module 'sf-symbols-typescript' { interface Overrides { // Restrict symbols to those found in SF Symbols 5.0 (e.g., for iOS 17.0+) SFSymbolsVersion: '5.0'; } } // After declaration merging, SFSymbol now only includes 5.0 symbols. // This ensures your app only uses symbols available on its minimum target OS. const restrictedIcon: SFSymbol = 'faceid'; // 'faceid' is available in 5.0 // const newerIcon: SFSymbol = 'globe.desk'; // If 'globe.desk' was introduced in 6.0, this would now be a type error // Alternatively, importing specific version types for granular control import type { SFSymbols6_0 } from 'sf-symbols-typescript'; const specificVersionIcon: SFSymbols6_0 = 'globe.desk'; // Explicitly use a 6.0 symbol type console.log(`Using basic icon: ${basicIcon}`); console.log(`Using restricted icon: ${restrictedIcon}`); console.log(`Using specific version icon: ${specificVersionIcon}`); // This library has no runtime code, so these lines just demonstrate type usage. // In a real app, you would pass these strings to a native UI component.
Debug
Known issues
breakingVersion 2 introduced a new mechanism for specifying SF Symbols compatibility through declaration merging with the `Overrides` interface. This replaces any previous, less flexible methods of version restriction.
fix
Migrate any custom version restriction logic to use the `declare module 'sf-symbols-typescript' { interface Overrides { SFSymbolsVersion: 'X.Y' } }` pattern, or import specific version types like `SFSymbolsX_Y`.
affects: >=2.0.0
gotchaThe package provides only TypeScript types. There is no JavaScript runtime code or default export. Attempting a standard `import SFSymbol from 'sf-symbols-typescript'` or `require('sf-symbols-typescript')` will result in runtime or build errors.
fix
Always use `import type { SFSymbol } from 'sf-symbols-typescript'` for type-only imports to ensure it's stripped correctly during compilation.
affects: >=1.0.0
gotchaWhen restricting symbols globally via `Overrides` interface declaration merging, ensure the `declare module` block is in a global declaration file (e.g., `src/globals.d.ts` or `src/types.d.ts`) that is included in your `tsconfig.json`. Placing it directly in a `.ts` or `.tsx` file that's part of your main application logic might not apply it globally.
fix
Move global `declare module 'sf-symbols-typescript' { ... }` blocks to a dedicated `.d.ts` file in your project's root or `src` directory, ensuring it's picked up by the TypeScript compiler.
affects: >=2.0.0
Errors
Common errors & fixes
Error: "SFSymbol" cannot be used as a value because it was imported using 'import type'.
Attempting to use `SFSymbol` or other type imports as if they were runtime values (e.g., `console.log(SFSymbol)` or passing it to a functionExpectingAValue).
fix
Remember that `SFSymbol` is a TypeScript type only. It has no runtime representation. It should only be used in type annotations or declarations, such as `const icon: SFSymbol = '...'`.
Property 'SFSymbolsVersion' does not exist on type 'Overrides'.
This error occurs if you're trying to directly modify the `Overrides` interface without using a `declare module` block, or if your `declare module` block for `Overrides` is syntactically incorrect.
fix
Ensure you are using declaration merging correctly: `declare module 'sf-symbols-typescript' { interface Overrides { SFSymbolsVersion: 'X.Y' } }` in a global `.d.ts` file. Do not try to import or extend `Overrides` as a regular interface.
Type '"non.existent.symbol"' is not assignable to type 'SFSymbol'.
This error means the string literal you provided does not match any of the valid SF Symbol names defined by the `SFSymbol` type. This can happen if you made a typo, or if you restricted the `SFSymbol` type to an older version of SF Symbols and are trying to use a newer symbol.
fix
Double-check the symbol name for typos. If you've restricted the `SFSymbol` type to an older version (e.g., '5.0'), ensure the symbol you're using is available in that version. Consult the SF Symbols app or the Version Support Table in the package's README to verify symbol availability for your chosen version.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
sf-symbols-typescript — npm install sf-symbols-typescript · libregistry