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>,
}
Expand description
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§
source§impl TsConfig
impl TsConfig
sourcepub fn parse_file<P: AsRef<Path>>(path: &P) -> Result<TsConfig>
pub fn parse_file<P: AsRef<Path>>(path: &P) -> Result<TsConfig>
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)
);
sourcepub fn parse_str(json: &str) -> Result<TsConfig>
pub fn parse_str(json: &str) -> Result<TsConfig>
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§
source§impl<'de> Deserialize<'de> for TsConfig
impl<'de> Deserialize<'de> for TsConfig
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl RefUnwindSafe for TsConfig
impl Send for TsConfig
impl Sync for TsConfig
impl Unpin for TsConfig
impl UnwindSafe for TsConfig
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more