Developing IoT Applications with TypeScript
Learn how to build Internet of Things (IoT) applications using TypeScript for device communication and data processing.
0 likes
10 views
Rule Content
title: Developing IoT Applications with TypeScript description: Enforce best practices for building IoT applications using TypeScript, focusing on type safety, interfaces, and clean code structure. category: TypeScript Cursor Rules globs: - "**/*.ts" - "**/*.tsx" rules: - id: no-any-type description: Disallow the use of the 'any' type to maintain type safety. severity: error pattern: ":matches(:function, :variable):has(:type_annotation > :identifier[value='any'])" fix: "Replace 'any' with a specific type or a generic type parameter." examples: - bad: | let data: any; good: | let data: string; - id: explicit-function-return-type description: Require explicit return types on functions to enhance readability and maintainability. severity: warning pattern: ":function:not(:has(:return_type))" fix: "Add an explicit return type to the function." examples: - bad: | function fetchData() { // ... } good: | function fetchData(): Promise<Data> { // ... } - id: prefer-interfaces-over-type-aliases description: Encourage the use of interfaces over type aliases for defining object shapes to improve extensibility. severity: warning pattern: ":type_alias:has(:type_annotation > :object_type)" fix: "Convert the type alias to an interface." examples: - bad: | type User = { id: number; name: string; }; good: | interface User { id: number; name: string; } - id: use-enums-for-constants description: Promote the use of enums for defining a set of named constants to enhance code readability. severity: warning pattern: ":variable_declaration:has(:variable > :identifier):has(:initializer > :string_literal)" fix: "Replace the string literals with an enum." examples: - bad: | const status = 'active'; good: | enum Status { Active = 'active', Inactive = 'inactive', } const status = Status.Active; - id: enable-strict-mode description: Ensure that TypeScript's strict mode is enabled to catch more errors during development. severity: error pattern: ":tsconfig:has(:property > :identifier[value='strict']):not(:has(:boolean[value=true]))" fix: "Set 'strict' to true in tsconfig.json." examples: - bad: | { "compilerOptions": { "strict": false } } good: | { "compilerOptions": { "strict": true } }