Skip to content

Commit

Permalink
build: Add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonkeating committed Apr 4, 2023
1 parent 97914c3 commit 85d3812
Show file tree
Hide file tree
Showing 40 changed files with 3,901 additions and 3,797 deletions.
44 changes: 44 additions & 0 deletions docs/decisions/0008-introducing-typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Introducing TypeScript

## Status

Accepted

## Context

TypeScript is a strongly-typed superset of JavaScript that adds optional static type checking, class-based object-oriented programming, and other features to JavaScript.

As we start to expand the scope of the data that Learner Portal uses, the limitations of plain Javascript are coming more into focus. In order to support a changing landscape of course data, we would like to introduce TypeScript into the code base to facilitate the documentation and refactoring process.

Here are some of the advantages of TypeScript over JavaScript:

### Type safety
TypeScript helps catch errors at compile-time instead of runtime by adding type annotations to variables, functions, and classes. This can help prevent errors that might occur when dealing with large codebases.

### Better tooling support
TypeScript has better tooling support than JavaScript, with features like code navigation, auto-completion, and refactoring tools in popular code editors like Visual Studio Code.

### Improved code organization
TypeScript's class-based object-oriented programming model allows developers to organize code in a more structured and maintainable way.

### Easy adoption
TypeScript is a superset of JavaScript, which means that any valid JavaScript code is also valid TypeScript code. This makes it easy for developers to adopt TypeScript gradually, without needing to rewrite their entire codebase.

### Community support
TypeScript has a growing community of developers who contribute to its development, create libraries and tools, and provide support to other developers. This makes it easier for developers to learn and adopt TypeScript.

## Decision

We will prioritize using TypeScript in the following places:
* New code files
* Existing API endpoints (and their payloads)
* Components or Functions take a lot of parameters, or use parameters that are themselves complex objects

## Consequences

* Code that requires heavy contracts, whether that's functions/components with lots or parameters, or complex objects returned from backend API's, will become much more comprehensible and easier to work with in a modern programming IDE
* Because TypeScript is a superset of Javascript, the code does not need to be migrated all at once, but can be updated to TypeScript during the course of regular feature work.

## References

* https://www.typescriptlang.org/
27 changes: 27 additions & 0 deletions external.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// TODO: Add definition to @edx/frontend-platform/auth
export interface HttpClient {
get: (url: string) => any;
post: (url: string, options: any) => any;
};

// TODO: Add definition to @edx/frontend-platform/config
export type FrontendPlatformConfig = {
USE_API_CACHE: boolean;
ENTERPRISE_CATALOG_API_BASE_URL: string;
DISCOVERY_API_BASE_URL: string;
LMS_BASE_URL: string;
LICENSE_MANAGER_URL: string;
};

// TODO: Add definitions to @edx/frontend-platform/react
export type EnterpriseConfig = {
uuid: string;
name: string;
slug: string;
disableSearch: boolean;
adminUsers: any[]
};

export type ReactAppContext = {
enterpriseConfig: EnterpriseConfig;
};
4 changes: 4 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const content: string;
export default content;
}
Loading

0 comments on commit 85d3812

Please sign in to comment.