Struct tsconfig::TsConfig[][src]

pub struct TsConfig {
    pub exclude: Option<Vec<String>>,
    pub extends: Option<String>,
    pub files: Option<Vec<String>>,
    pub include: Option<Vec<String>>,
    pub references: Option<References>,
    pub type_acquisition: Option<TypeAcquisition>,
    pub compiler_options: Option<CompilerOptions>,
}

The main struct representing a parsed .tsconfig file.

Fields

exclude: Option<Vec<String>>extends: Option<String>files: Option<Vec<String>>include: Option<Vec<String>>references: Option<References>type_acquisition: Option<TypeAcquisition>compiler_options: Option<CompilerOptions>

Implementations

impl TsConfig[src]

pub fn parse_file<P: AsRef<Path>>(path: &P) -> Result<TsConfig>[src]

Parses a .tsconfig file into a TsConfig.

The extends field will be respected, allowing for one .tsconfig file to inherit properties from another. Comments and trailing commas are both allowed, although they are not valid JSON.

Example

Assuming the following .tsconfig files:

tsconfig.base.json:

{
    "useDefineForClassFields": false,
    "traceResolution": true,
    "jsx": "preserve",
}

tsconfig.inherits.json:

{
    "extends": "./tsconfig.base.json",
    "compilerOptions": {
        "traceResolution": false,
        "declaration": true,
        "jsx": "react-jsxdev",
    }
}
use std::path::Path;
use tsconfig::TsConfig;
let path = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
    .join("test/tsconfig.inherits.json");
let config = TsConfig::parse_file(&path).unwrap();

assert_eq!(
    config
        .compiler_options
        .clone()
        .unwrap()
        .use_define_for_class_fields,
    Some(false)
);

assert_eq!(
    config.compiler_options.clone().unwrap().declaration,
    Some(true)
);

assert_eq!(
    config.compiler_options.unwrap().trace_resolution,
    Some(false)
);

pub fn parse_str(json: &str) -> Result<TsConfig>[src]

Parse a JSON string into a single TsConfig.

The ‘extends’ field will be ignored. Comments and trailing commas are both allowed, although they are not valid JSON.

Example

use tsconfig::{TsConfig, Jsx};
let json = r#"{"compilerOptions": {"jsx": /*here's a comment*/ "react-jsx"},}"#;

let config = TsConfig::parse_str(json).unwrap();
assert_eq!(config.compiler_options.unwrap().jsx, Some(Jsx::ReactJsx));     

Trait Implementations

impl Clone for TsConfig[src]

impl Debug for TsConfig[src]

impl<'de> Deserialize<'de> for TsConfig[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.