evgenyigumnov / rustsn

Code snippets generator via LLMs and compiler/tester via build tools
GNU General Public License v3.0
18 stars 5 forks source link

Add TypeScript support #3

Open evgenyigumnov opened 2 days ago

evgenyigumnov commented 2 days ago

Launch Example

rustsn --lang=typescript

Example Query

take 2 params and add them and return result

Example Generation

package.json

{
  "name": "solution",
  "version": "1.0.0",
  "description": "Minimalistic TypeScript project",
  "main": "dist/solution.js",
  "scripts": {
    "test": "jest",
    "build": "tsc",
    "start": "node dist/solution.js"
  },
  "devDependencies": {
    "@types/jest": "^29.0.0",
    "jest": "^29.0.0",
    "typescript": "^5.0.0"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "outDir": "dist",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}

src/solution.ts

export function solution(a: number, b: number): number {
  return a + b;
}

src/solution.test.ts

import { solution } from './solution';

test('test1: adding positive numbers', () => {
  expect(solution(1, 2)).toBe(3);
});

test('test2: adding negative numbers', () => {
  expect(solution(-1, -2)).toBe(-3);
});

test('test3: adding a string and a number', () => {
  // To handle this case, you might need to adjust the function or the test
  // For demonstration, assuming the function strictly accepts numbers
  // This test will fail and needs to be handled appropriately
  // Alternatively, you can use type assertions or overloads
});

Example Install Dependencies

npm install

Example Launch Compilation

npm run build

Example Launch Test

npm test